Sync skills from upstream #66
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: Sync skills from upstream | |
| on: | |
| schedule: | |
| - cron: '17 6 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| actions: write | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: sync-from-upstream | |
| cancel-in-progress: false | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout aggregator | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | |
| - name: Run sync script | |
| run: bash scripts/sync-from-upstream.sh | |
| - name: Build PR body | |
| run: | | |
| { | |
| echo "Automated sync of skill content from upstream source repositories." | |
| echo | |
| echo "## Upstream sources" | |
| echo | |
| cat "$RUNNER_TEMP/sync-summary.md" | |
| echo | |
| echo "Review the diff against the listed upstream commits before merging." | |
| } > "$RUNNER_TEMP/pr-body.md" | |
| - name: Create or update pull request | |
| id: sync-pr | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_BRANCH: autosync/upstream-skills | |
| PR_TITLE: 'chore: sync skills from upstream' | |
| run: | | |
| set -euo pipefail | |
| if [ -z "$(git status --porcelain)" ]; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| existing_pr="$( | |
| gh pr list \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --head "$PR_BRANCH" \ | |
| --base main \ | |
| --state open \ | |
| --json number \ | |
| --jq '.[0].number // empty' | |
| )" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git switch -c "$PR_BRANCH" | |
| git add -A | |
| git commit -m "chore: sync skills from upstream" | |
| remote_sha="$(git ls-remote --heads origin "$PR_BRANCH" | awk '{print $1}')" | |
| if [ -n "$remote_sha" ]; then | |
| git push --force-with-lease="refs/heads/$PR_BRANCH:$remote_sha" origin "HEAD:$PR_BRANCH" | |
| else | |
| git push origin "HEAD:$PR_BRANCH" | |
| fi | |
| if [ -n "$existing_pr" ]; then | |
| gh pr edit "$existing_pr" \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --title "$PR_TITLE" \ | |
| --body-file "$RUNNER_TEMP/pr-body.md" | |
| else | |
| gh pr create \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --base main \ | |
| --head "$PR_BRANCH" \ | |
| --title "$PR_TITLE" \ | |
| --body-file "$RUNNER_TEMP/pr-body.md" | |
| fi | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| # PRs opened by GITHUB_TOKEN don't trigger pull_request workflows | |
| # (GitHub anti-recursion). workflow_dispatch is the documented exception, | |
| # so we dispatch CI explicitly against the autosync branch's HEAD SHA; | |
| # the resulting check_run attaches to the PR via SHA. | |
| - name: Trigger CI on autosync PR | |
| if: steps.sync-pr.outputs.changed == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: gh workflow run ci.yml --ref autosync/upstream-skills --repo "$GITHUB_REPOSITORY" |