Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 56 additions & 37 deletions .github/workflows/__update-cpm-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,51 @@ jobs:
- name: Test Matrix
run: echo ${{ matrix.repo }}

update-cpm-cmake:
name: Update CPM.cmake - ${{ matrix.full_name }}
download-cpm-cmake:
name: Download CPM.cmake
if: github.event_name == 'schedule' && needs.setup-matrix.outputs.has-repositories == 'true'
needs: setup-matrix
permissions:
contents: read
runs-on: ubuntu-latest
outputs:
release-tag: ${{ steps.release.outputs.tag }}
release-body: ${{ steps.release.outputs.body }}
steps:
- name: Get latest CPM.cmake release
id: release
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const {data: release} = await github.rest.repos.getLatestRelease({
owner: 'cpm-cmake',
repo: 'CPM.cmake',
});
core.setOutput('id', release.id);
core.setOutput('tag', release.tag_name);
core.setOutput('body', release.body ?? '');

- name: Download release asset
uses: robinraju/release-downloader@28fc21f50d76778e7023361aa1f863e717d3d56f # v1.13
with:
repository: cpm-cmake/CPM.cmake
releaseId: ${{ steps.release.outputs.id }}
fileName: CPM.cmake
out-file-path: cpm-release

- name: Upload CPM.cmake artifact
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: cpm-release
path: cpm-release/CPM.cmake
if-no-files-found: error
overwrite: true

update-cpm-cmake:
name: Update CPM.cmake - ${{ matrix.full_name }}
needs:
- setup-matrix
- download-cpm-cmake
permissions: {}
runs-on: ubuntu-latest
strategy:
Expand All @@ -68,43 +109,21 @@ jobs:
token: ${{ secrets.GH_BOT_TOKEN }}
path: repo

- name: Find CPM.cmake
id: find-cpm
- name: Download CPM.cmake artifact
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: cpm-release
path: ${{ runner.temp }}/cpm-release

- name: Update CPM.cmake
working-directory: repo
run: |
CPM_FILE=$(find . -type f -name "CPM.cmake")
if [ -z "${CPM_FILE}" ]; then
echo "CPM.cmake not found in ${{ matrix.repo }}"
echo "CPM.cmake not found"
exit 1
fi
echo "CPM.cmake found at ${CPM_FILE}"
echo "cpm_file=${CPM_FILE}" >> "${GITHUB_OUTPUT}"

- name: Update CPM.cmake
id: update-cpm
working-directory: repo
run: |
curl \
--proto "=https" \
-fsSL \
--retry 3 \
-o "${{ steps.find-cpm.outputs.cpm_file }}" \
https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/CPM.cmake

# get latest version tag from CPM.cmake repository
RESPONSE=$(curl -fsS https://api.github.com/repos/cpm-cmake/CPM.cmake/releases/latest)
RELEASE_TAG=$(echo "$RESPONSE" | jq -r '.tag_name')
RELEASE_BODY=$(echo "$RESPONSE" | jq -r '.body')
echo "CPM.cmake updated to version ${RELEASE_TAG}"
echo "Release notes:"
echo "${RELEASE_BODY}"

{
echo "cpm_version=${RELEASE_TAG}"
echo "cpm_release_body<<EOF"
echo "${RELEASE_BODY}"
echo "EOF"
} >> "${GITHUB_OUTPUT}"
cp -- "${RUNNER_TEMP}/cpm-release/CPM.cmake" "${CPM_FILE}"

- name: Create/Update Pull Request
id: create-pr
Expand All @@ -114,9 +133,9 @@ jobs:
committer: "${{ vars.GH_BOT_NAME }} <${{ secrets.GH_BOT_EMAIL }}>"
path: "repo"
token: ${{ secrets.GH_BOT_TOKEN }}
commit-message: "chore(deps): Update CPM.cmake to ${{ steps.update-cpm.outputs.cpm_version }}"
branch: bot/bump-cpm-cmake-${{ steps.update-cpm.outputs.cpm_version }}
commit-message: "chore(deps): Update CPM.cmake to ${{ needs.download-cpm-cmake.outputs.release-tag }}"
branch: bot/bump-cpm-cmake-${{ needs.download-cpm-cmake.outputs.release-tag }}
delete-branch: true
title: "chore(deps): Update CPM.cmake to ${{ steps.update-cpm.outputs.cpm_version }}"
body: ${{ steps.update-cpm.outputs.cpm_release_body }}
title: "chore(deps): Update CPM.cmake to ${{ needs.download-cpm-cmake.outputs.release-tag }}"
body: ${{ needs.download-cpm-cmake.outputs.release-body }}
labels: dependencies
13 changes: 13 additions & 0 deletions tests/workflow-profile-selection.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ test('CPM maintenance delegates profile and organization selection to the shared
assert.equal(source.match(/if:.*needs.setup-matrix.outputs.has-repositories == 'true'/g).length, 2);
});

test('CPM maintenance fetches the upstream release asset once and shares it across repository jobs', () => {
const source = readFileSync('.github/workflows/__update-cpm-cmake.yml', 'utf8').replaceAll('\r\n', '\n');
const [, downloadAndUpdate] = source.split('\n download-cpm-cmake:\n');
assert.ok(downloadAndUpdate, 'A dedicated job must fetch the upstream release');
const [download, update] = downloadAndUpdate.split('\n update-cpm-cmake:\n');
assert.match(download, /uses: robinraju\/release-downloader@/);
assert.match(download, /releaseId: \$\{\{ steps\.release\.outputs\.id \}\}/);
assert.match(download, /uses: actions\/upload-artifact@.*\n\s+with:\n\s+name: cpm-release/);
assert.match(update, /needs:\n\s+- setup-matrix\n\s+- download-cpm-cmake/);
assert.match(update, /uses: actions\/download-artifact@.*\n\s+with:\n\s+name: cpm-release/);
assert.doesNotMatch(update, /release-downloader|\bcurl\b/);
});

test('workflow automation contains no repository-topic API calls or legacy profile guidance', () => {
for (const file of readdirSync('.github/workflows').filter(file => file.endsWith('.yml'))) {
const source = readFileSync(`.github/workflows/${file}`, 'utf8');
Expand Down
Loading