|
| 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: Set up Python |
| 83 | + uses: actions/setup-python@v5 |
| 84 | + with: |
| 85 | + python-version: '3.12' |
| 86 | + |
| 87 | + - name: Install Python dependencies |
| 88 | + run: python -m pip install --upgrade clang-format |
| 89 | + |
| 90 | + - name: Update CPM.cmake |
| 91 | + id: update-cpm |
| 92 | + working-directory: repo |
| 93 | + run: | |
| 94 | + curl \ |
| 95 | + -fsSL \ |
| 96 | + --retry 3 \ |
| 97 | + -o "${{ steps.find-cpm.outputs.cpm_file }}" \ |
| 98 | + https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/CPM.cmake |
| 99 | +
|
| 100 | + # get latest version tag from CPM.cmake repository |
| 101 | + RESPONSE=$(curl -fsSL https://api.github.com/repos/cpm-cmake/CPM.cmake/releases/latest) |
| 102 | + RELEASE_TAG=$(echo "$RESPONSE" | jq -r '.tag_name') |
| 103 | + RELEASE_BODY=$(echo "$RESPONSE" | jq -r '.body') |
| 104 | + echo "CPM.cmake updated to version ${RELEASE_TAG}" |
| 105 | + echo "Release notes:" |
| 106 | + echo "${RELEASE_BODY}" |
| 107 | +
|
| 108 | + { |
| 109 | + echo "cpm_version=${RELEASE_TAG}" |
| 110 | + echo "cpm_release_body<<EOF" |
| 111 | + echo "${RELEASE_BODY}" |
| 112 | + echo "EOF" |
| 113 | + } >> "${GITHUB_OUTPUT}" |
| 114 | +
|
| 115 | + - name: cmake-format |
| 116 | + working-directory: repo |
| 117 | + run: cmake-format --line-width 120 --tab-size 4 --in-place "${{ steps.find-cpm.outputs.cpm_file }}" |
| 118 | + |
| 119 | + - name: Create/Update Pull Request |
| 120 | + id: create-pr |
| 121 | + uses: peter-evans/create-pull-request@v7 |
| 122 | + with: |
| 123 | + author: "${{ secrets.GH_BOT_NAME }} <${{ secrets.GH_BOT_EMAIL }}>" |
| 124 | + committer: "${{ secrets.GH_BOT_NAME }} <${{ secrets.GH_BOT_EMAIL }}>" |
| 125 | + path: "repo" |
| 126 | + token: ${{ secrets.GH_TOKEN }} |
| 127 | + commit-message: "chore(deps): Update CPM.cmake to ${{ steps.update-cpm.outputs.cpm_version }}" |
| 128 | + branch: bot/bump-cpm-cmake-${{ steps.update-cpm.outputs.cpm_version }} |
| 129 | + delete-branch: true |
| 130 | + title: "chore(deps): Update CPM.cmake to ${{ steps.update-cpm.outputs.cpm_version }}" |
| 131 | + body: ${{ steps.update-cpm.outputs.cpm_release_body }} |
| 132 | + labels: dependencies |
0 commit comments