Skip to content

Commit 6cc18d1

Browse files
feat(workflows): add cpm updater
1 parent 51f760c commit 6cc18d1

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
# This workflow looks for a CPM.cmake file in each repository in the organization, if the repo has the `cpm` label.
3+
# If found, it updates the CPM.cmake file to the latest version from the CPM.cmake repository, and
4+
# creates a pull request with the changes.
5+
6+
name: Update CPM.cmake
7+
permissions: {}
8+
9+
on:
10+
schedule:
11+
- cron: '0 9 * * *'
12+
workflow_dispatch:
13+
14+
jobs:
15+
setup-matrix:
16+
name: Setup Matrix
17+
runs-on: ubuntu-latest
18+
outputs:
19+
matrix: ${{ steps.set-matrix.outputs.result }}
20+
steps:
21+
- name: Get repos
22+
id: set-matrix
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
const opts = github.rest.repos.listForOrg.endpoint.merge({ org: context.repo.owner });
27+
const repos = await github.paginate(opts);
28+
29+
let matrix = { "include": [] };
30+
for (const repo of repos) {
31+
const topics = await github.rest.repos.getAllTopics({
32+
owner: context.repo.owner,
33+
repo: repo.name
34+
});
35+
if (topics.data.names.includes('cpm')) {
36+
matrix.include.push({ "repo": repo.name });
37+
}
38+
}
39+
return matrix;
40+
41+
test-matrix:
42+
name: Test Matrix - ${{ matrix.repo }}
43+
if: github.event_name == 'workflow_dispatch'
44+
needs: setup-matrix
45+
runs-on: ubuntu-latest
46+
strategy:
47+
fail-fast: false
48+
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
49+
steps:
50+
- name: Test Matrix
51+
run: echo ${{ matrix.repo }}
52+
53+
update-cpm-cmake:
54+
name: Update CPM.cmake - ${{ matrix.repo }}
55+
if: github.event_name == 'schedule'
56+
needs: setup-matrix
57+
runs-on: ubuntu-latest
58+
strategy:
59+
fail-fast: false
60+
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
61+
max-parallel: 1 # run one at a time to attempt to avoid GitHub api rate limits
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v4
65+
with:
66+
repository: ${{ matrix.repo }}
67+
token: ${{ secrets.GH_BOT_TOKEN }}
68+
path: repo
69+
70+
- name: Find CPM.cmake
71+
id: find-cpm
72+
working-directory: repo
73+
run: |
74+
CPM_FILE=$(find . -type f -name "CPM.cmake")
75+
if [ -z "${CPM_FILE}" ]; then
76+
echo "CPM.cmake not found in ${{ matrix.repo }}"
77+
exit 1
78+
fi
79+
echo "CPM.cmake found at ${CPM_FILE}"
80+
echo "cpm_file=${CPM_FILE}" >> "${GITHUB_OUTPUT}"
81+
82+
- name: Update CPM.cmake
83+
id: update-cpm
84+
working-directory: repo
85+
run: |
86+
curl \
87+
-fsSL \
88+
--retry 3 \
89+
-o "${{ steps.find-cpm.outputs.cpm_file }}" \
90+
https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/CPM.cmake
91+
92+
# get latest version tag from CPM.cmake repository
93+
RESPONSE=$(curl -fsSL https://api.github.com/repos/cpm-cmake/CPM.cmake/releases/latest)
94+
RELEASE_TAG=$(echo "$RESPONSE" | jq -r '.tag_name')
95+
RELEASE_BODY=$(echo "$RESPONSE" | jq -r '.body')
96+
echo "CPM.cmake updated to version ${RELEASE_TAG}"
97+
echo "Release notes:"
98+
echo "${RELEASE_BODY}"
99+
100+
{
101+
echo "cpm_version=${RELEASE_TAG}"
102+
echo "cpm_release_body<<EOF"
103+
echo "${RELEASE_BODY}"
104+
echo "EOF"
105+
} >> "${GITHUB_OUTPUT}"
106+
107+
- name: Create/Update Pull Request
108+
id: create-pr
109+
uses: peter-evans/create-pull-request@v7
110+
with:
111+
author: "${{ secrets.GH_BOT_NAME }} <${{ secrets.GH_BOT_EMAIL }}>"
112+
committer: "${{ secrets.GH_BOT_NAME }} <${{ secrets.GH_BOT_EMAIL }}>"
113+
path: "repo"
114+
token: ${{ secrets.GH_TOKEN }}
115+
commit-message: "chore(deps): Update CPM.cmake to ${{ steps.update-cpm.outputs.cpm_version }}"
116+
branch: bot/bump-cpm-cmake-${{ steps.update-cpm.outputs.cpm_version }}
117+
delete-branch: true
118+
title: "chore(deps): Update CPM.cmake to ${{ steps.update-cpm.outputs.cpm_version }}"
119+
body: ${{ steps.update-cpm.outputs.cpm_release_body }}
120+
labels: dependencies

0 commit comments

Comments
 (0)