Auto-update Snap Revisions #2282
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto-update Snap Revisions | |
| on: | |
| schedule: | |
| - cron: "0 */4 * * *" # every 4 hours | |
| pull_request: | |
| paths: | |
| - .github/workflows/auto-update-snap-revision.yaml | |
| jobs: | |
| stable-branches: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| branches: ${{ steps.release-branches.outputs.data }} | |
| steps: | |
| - uses: octokit/[email protected] | |
| id: list-branches | |
| with: | |
| route: GET /repos/${{ github.repository }}/branches | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - id: release-branches | |
| run: |- | |
| DATA='${{ steps.list-branches.outputs.data }}' | |
| NAMES=$(jq -r '.[] | .name' <<< $DATA) | |
| RELEASES=() | |
| for BRANCH in ${NAMES}; do | |
| if [[ "${BRANCH}" =~ ^release-[0-9]+\.[0-9]+$ ]]; then | |
| RELEASES+=($BRANCH) | |
| fi | |
| done | |
| echo data=$(printf '%s\n' "${RELEASES[@]}" | jq -R . | jq -s .) >> ${GITHUB_OUTPUT} | |
| update-branches: | |
| runs-on: ubuntu-latest | |
| needs: [stable-branches] | |
| strategy: | |
| matrix: | |
| branch: ${{ fromJSON(needs.stable-branches.outputs.branches) }} | |
| steps: | |
| - name: Prepare Track | |
| run: |- | |
| BRANCH="${{matrix.branch}}" | |
| echo "TRACK=${BRANCH:8}" | tee -a "$GITHUB_ENV" | |
| - name: Checkout ${{ matrix.branch }} | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ matrix.branch }} | |
| token: ${{ secrets.REPO_ACCESS_TOKEN }} | |
| - name: Fetch update-snap-revision.py into a separate path | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: ${{ github.repository }} | |
| path: update-scripts | |
| sparse-checkout: | | |
| .github/workflows/update-snap-revision.py | |
| sparse-checkout-cone-mode: false | |
| - name: Place update-snap-revision.py into working directory | |
| run: | | |
| mkdir -p .github/workflows | |
| cp update-scripts/.github/workflows/update-snap-revision.py .github/workflows/update-snap-revision.py | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.14' | |
| - run: "pip install pyyaml" | |
| - name: Update amd64 Revision | |
| id: update-amd64-revision | |
| run: | | |
| python3 .github/workflows/update-snap-revision.py locate amd64 | |
| - name: Update arm64 Revision | |
| id: update-arm64-revision | |
| run: | | |
| python3 .github/workflows/update-snap-revision.py locate arm64 | |
| - name: Assemble Revisions | |
| id: assemble-revisions | |
| run: | | |
| AMD64_REVISION=${{ steps.update-amd64-revision.outputs.revision }} | |
| ARM64_REVISION=${{ steps.update-arm64-revision.outputs.revision }} | |
| AMD64_COMMIT=${{ steps.update-amd64-revision.outputs.commit_sha }} | |
| ARM64_COMMIT=${{ steps.update-arm64-revision.outputs.commit_sha }} | |
| # Only proceed if both architectures have new revisions | |
| if [[ -z $AMD64_REVISION || -z $ARM64_REVISION ]]; then | |
| echo "Not both architectures have new revisions (amd64=${AMD64_REVISION:-none}, arm64=${ARM64_REVISION:-none})" | |
| echo 'revisions=[]' >> ${GITHUB_OUTPUT} | |
| exit 0 | |
| fi | |
| # Only proceed if both commit digests match | |
| if [[ $AMD64_COMMIT != $ARM64_COMMIT ]]; then | |
| echo "Commit digests do not match (amd64=${AMD64_COMMIT}, arm64=${ARM64_COMMIT})" | |
| echo 'revisions=[]' >> ${GITHUB_OUTPUT} | |
| exit 0 | |
| fi | |
| REVISIONS=("amd64-${AMD64_REVISION}" "arm64-${ARM64_REVISION}") | |
| echo "revisions=$(printf '%s\n' "${REVISIONS[@]}" | jq -R . | jq -s -c .)" >> ${GITHUB_OUTPUT} | |
| - name: Report Pull Request | |
| if: ${{ github.event_name != 'schedule' && steps.assemble-revisions.outputs.revisions != '[]' }} | |
| run: | | |
| echo "Would have created pull-request" | |
| echo "Title: chore(release-${{ env.TRACK }}): update k8s snap revisions" | |
| echo "Revisions: amd64=${{ steps.update-amd64-revision.outputs.revision }}, arm64=${{ steps.update-arm64-revision.outputs.revision }}" | |
| echo "Source commit: ${{ steps.update-amd64-revision.outputs.commit_sha }}" | |
| - name: Create pull request | |
| uses: peter-evans/create-pull-request@v8 | |
| if: ${{ github.event_name == 'schedule' && (steps.assemble-revisions.outputs.revisions != '[]') }} | |
| with: | |
| commit-message: 'chore(release-${{ env.TRACK }}): update k8s snap revisions' | |
| title: "chore(release-${{ env.TRACK }}): update k8s snap revisions" | |
| body: |- | |
| ## Overview | |
| Updates the K8s snap revisions for the `${{ env.TRACK }}` track. | |
| ## Revisions | |
| | Architecture | Revision | | |
| |--------------|----------| | |
| | amd64 | ${{ steps.update-amd64-revision.outputs.revision }} | | |
| | arm64 | ${{ steps.update-arm64-revision.outputs.revision }} | | |
| ## Source Commits | |
| Both architectures are built from the same commit: | |
| - https://github.com/canonical/k8s-snap/commit/${{ steps.update-amd64-revision.outputs.commit_sha }} | |
| labels: | | |
| automerge | |
| branch: revision-update-job/${{ env.TRACK }}/${{ join(fromJson(steps.assemble-revisions.outputs.revisions), '-') }} | |
| base: ${{ matrix.branch }} | |
| author: Canonical Github Bot <[email protected]> | |
| token: ${{ secrets.REPO_ACCESS_TOKEN }} | |
| add-paths: | | |
| charms/worker/k8s/templates/*.yaml |