-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add automated action version sync to templates #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
52e77ec
feat: add automated action version sync to templates
stranske a35ae60
Merge branch 'main' into fix/sync-action-versions-to-templates
stranske bffeddd
chore(codex-autofix): apply updates (PR #444)
github-actions[bot] da4e40e
chore(codex-autofix): apply updates (PR #444)
github-actions[bot] 1c75bd0
fix: correct action versions and comparison logic
stranske 87cac14
chore(codex-autofix): apply updates (PR #444)
github-actions[bot] 260aa8b
fix: address shellcheck warnings SC2129 and SC2044
stranske File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| name: Maint Sync Action Versions | ||
|
|
||
| # Sync GitHub Action versions from .github/workflows to templates | ||
| # after Dependabot merges action version updates. | ||
| # | ||
| # This ensures templates stay in sync with the latest action versions | ||
| # that Dependabot updates in the main workflows. | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - '.github/workflows/*.yml' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| sync-versions: | ||
| name: Sync action versions to templates | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Extract action versions from workflows | ||
| id: extract | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| # Extract unique action versions from .github/workflows/ | ||
| declare -A versions | ||
|
|
||
| for file in .github/workflows/*.yml; do | ||
| while IFS= read -r line; do | ||
| # Match 'uses: owner/action@version' | ||
| if [[ "$line" =~ uses:[[:space:]]*([^[:space:]]+)@(v[0-9]+) ]]; then | ||
| action="${BASH_REMATCH[1]}" | ||
| version="${BASH_REMATCH[2]}" | ||
| # Store highest version for each action | ||
| if [[ -z "${versions[$action]:-}" ]] || [[ "$version" > "${versions[$action]}" ]]; then | ||
| versions["$action"]="$version" | ||
| fi | ||
| fi | ||
| done < "$file" | ||
| done | ||
|
|
||
| # Output versions for key actions | ||
| echo "checkout=${versions[actions/checkout]:-v4}" >> "$GITHUB_OUTPUT" | ||
| echo "github_script=${versions[actions/github-script]:-v7}" >> "$GITHUB_OUTPUT" | ||
| echo "upload_artifact=${versions[actions/upload-artifact]:-v4}" >> "$GITHUB_OUTPUT" | ||
| echo "download_artifact=${versions[actions/download-artifact]:-v4}" >> "$GITHUB_OUTPUT" | ||
| echo "cache=${versions[actions/cache]:-v4}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| echo "Detected versions:" | ||
| for action in "${!versions[@]}"; do | ||
| echo " $action: ${versions[$action]}" | ||
| done | ||
|
|
||
| - name: Update templates with synced versions | ||
| id: update | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| checkout="${{ steps.extract.outputs.checkout }}" | ||
| github_script="${{ steps.extract.outputs.github_script }}" | ||
| upload_artifact="${{ steps.extract.outputs.upload_artifact }}" | ||
| download_artifact="${{ steps.extract.outputs.download_artifact }}" | ||
| cache="${{ steps.extract.outputs.cache }}" | ||
|
|
||
| changed=0 | ||
|
|
||
| # Update all YAML files in templates/ | ||
| find templates/ -name "*.yml" -type f | while read -r file; do | ||
| orig_hash=$(md5sum "$file" | cut -d' ' -f1) | ||
|
|
||
| sed -i \ | ||
| -e "s|actions/checkout@v[0-9]\+|actions/checkout@${checkout}|g" \ | ||
| -e "s|actions/github-script@v[0-9]\+|actions/github-script@${github_script}|g" \ | ||
| -e "s|actions/upload-artifact@v[0-9]\+|actions/upload-artifact@${upload_artifact}|g" \ | ||
| -e "s|actions/download-artifact@v[0-9]\+|actions/download-artifact@${download_artifact}|g" \ | ||
| -e "s|actions/cache@v[0-9]\+|actions/cache@${cache}|g" \ | ||
| "$file" | ||
|
|
||
| new_hash=$(md5sum "$file" | cut -d' ' -f1) | ||
| if [[ "$orig_hash" != "$new_hash" ]]; then | ||
| echo "Updated: $file" | ||
| changed=1 | ||
| fi | ||
| done | ||
|
|
||
| echo "changed=$changed" >> "$GITHUB_OUTPUT" | ||
|
stranske marked this conversation as resolved.
Outdated
|
||
|
|
||
| - name: Check for changes | ||
| id: check | ||
| run: | | ||
| if git diff --quiet templates/; then | ||
| echo "has_changes=false" >> "$GITHUB_OUTPUT" | ||
| echo "No changes to templates" | ||
| else | ||
| echo "has_changes=true" >> "$GITHUB_OUTPUT" | ||
| echo "Changes detected:" | ||
| git diff --stat templates/ | ||
| fi | ||
|
|
||
| - name: Create PR if changes exist | ||
| if: steps.check.outputs.has_changes == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| branch="auto/sync-action-versions-$(date +%Y%m%d%H%M%S)" | ||
|
|
||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git checkout -b "$branch" | ||
| git add templates/ | ||
| git commit -m "ci(deps): sync action versions to templates | ||
|
|
||
| Automated sync from .github/workflows/ to templates/ | ||
|
|
||
| Updated versions: | ||
| - actions/checkout: ${{ steps.extract.outputs.checkout }} | ||
| - actions/github-script: ${{ steps.extract.outputs.github_script }} | ||
| - actions/upload-artifact: ${{ steps.extract.outputs.upload_artifact }} | ||
| - actions/download-artifact: ${{ steps.extract.outputs.download_artifact }} | ||
| - actions/cache: ${{ steps.extract.outputs.cache }}" | ||
|
|
||
| git push origin "$branch" | ||
|
|
||
| gh pr create \ | ||
| --title "ci(deps): sync action versions to templates" \ | ||
| --body "Automated PR to sync GitHub Action versions from \`.github/workflows/\` to \`templates/\`. | ||
|
|
||
| This ensures templates stay in sync with Dependabot updates. | ||
|
|
||
| **Updated versions:** | ||
| - actions/checkout: \`${{ steps.extract.outputs.checkout }}\` | ||
| - actions/github-script: \`${{ steps.extract.outputs.github_script }}\` | ||
| - actions/upload-artifact: \`${{ steps.extract.outputs.upload_artifact }}\` | ||
| - actions/download-artifact: \`${{ steps.extract.outputs.download_artifact }}\` | ||
| - actions/cache: \`${{ steps.extract.outputs.cache }}\`" \ | ||
| --label "dependencies" \ | ||
| --label "github-actions" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env bash | ||
| # Sync GitHub Action versions from .github/workflows/ to templates/ | ||
| # Run this after Dependabot updates are merged to keep templates in sync. | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| REPO_ROOT="$(dirname "$SCRIPT_DIR")" | ||
|
|
||
| cd "$REPO_ROOT" | ||
|
|
||
| # Extract versions from .github/workflows/ | ||
| declare -A versions | ||
|
|
||
| echo "Extracting versions from .github/workflows/..." | ||
| for file in .github/workflows/*.yml; do | ||
| while IFS= read -r line; do | ||
| if [[ "$line" =~ uses:[[:space:]]*([^[:space:]]+)@(v[0-9]+) ]]; then | ||
| action="${BASH_REMATCH[1]}" | ||
| version="${BASH_REMATCH[2]}" | ||
| if [[ -z "${versions[$action]:-}" ]] || [[ "$version" > "${versions[$action]}" ]]; then | ||
| versions["$action"]="$version" | ||
|
stranske marked this conversation as resolved.
Outdated
|
||
| fi | ||
| fi | ||
| done < "$file" | ||
| done | ||
|
|
||
| echo "" | ||
| echo "Detected versions:" | ||
| for action in "${!versions[@]}"; do | ||
| echo " $action: ${versions[$action]}" | ||
| done | ||
|
|
||
| checkout="${versions[actions/checkout]:-v4}" | ||
| github_script="${versions[actions/github-script]:-v7}" | ||
| upload_artifact="${versions[actions/upload-artifact]:-v4}" | ||
| download_artifact="${versions[actions/download-artifact]:-v4}" | ||
| cache="${versions[actions/cache]:-v4}" | ||
|
|
||
| echo "" | ||
| echo "Updating templates/..." | ||
|
|
||
| # Update templates | ||
| find templates/ -name "*.yml" -type f | while read -r file; do | ||
| orig=$(cat "$file") | ||
|
|
||
| sed -i \ | ||
| -e "s|actions/checkout@v[0-9]\+|actions/checkout@${checkout}|g" \ | ||
| -e "s|actions/github-script@v[0-9]\+|actions/github-script@${github_script}|g" \ | ||
| -e "s|actions/upload-artifact@v[0-9]\+|actions/upload-artifact@${upload_artifact}|g" \ | ||
| -e "s|actions/download-artifact@v[0-9]\+|actions/download-artifact@${download_artifact}|g" \ | ||
| -e "s|actions/cache@v[0-9]\+|actions/cache@${cache}|g" \ | ||
| "$file" | ||
|
|
||
| if [[ "$(cat "$file")" != "$orig" ]]; then | ||
| echo " Updated: $file" | ||
| fi | ||
| done | ||
|
|
||
| echo "" | ||
| echo "Done. Run 'git diff templates/' to see changes." | ||
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.