sync-labels #8
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-labels | |
| on: | |
| pull_request: | |
| paths: | |
| - labels.yml | |
| - .github/scripts/sync-labels.rb | |
| - .github/workflows/sync-labels.yml | |
| - test/sync_labels_test.rb | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - labels.yml | |
| - .github/scripts/sync-labels.rb | |
| - .github/workflows/sync-labels.yml | |
| schedule: | |
| - cron: "41 9 * * 1" | |
| workflow_dispatch: | |
| inputs: | |
| target_repos: | |
| description: "Comma-separated repos, defaults to all active evalops repos" | |
| required: false | |
| default: "" | |
| apply: | |
| description: "Apply changes instead of dry-run" | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| env: | |
| GH_TOKEN: ${{ secrets.EVALOPS_LABEL_SYNC_TOKEN || secrets.EVALOPS_ORG_WRITE_TOKEN || github.token }} | |
| ORG_WRITE_TOKEN_PRESENT: ${{ secrets.EVALOPS_LABEL_SYNC_TOKEN != '' || secrets.EVALOPS_ORG_WRITE_TOKEN != '' }} | |
| TARGET_REPOS: ${{ inputs.target_repos || '' }} | |
| REQUESTED_APPLY: ${{ inputs.apply || false }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Validate canonical labels | |
| run: ruby .github/scripts/sync-labels.rb --validate-only --labels labels.yml | |
| - name: Plan or apply label sync | |
| env: | |
| IS_PULL_REQUEST: ${{ github.event_name == 'pull_request' }} | |
| run: | | |
| set -euo pipefail | |
| apply=false | |
| if [ "${IS_PULL_REQUEST}" != "true" ]; then | |
| apply=true | |
| fi | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${REQUESTED_APPLY}" != "true" ]; then | |
| apply=false | |
| fi | |
| if [ "${apply}" = "true" ] && [ "${ORG_WRITE_TOKEN_PRESENT}" != "true" ]; then | |
| echo "::error::Set EVALOPS_LABEL_SYNC_TOKEN or EVALOPS_ORG_WRITE_TOKEN with org-wide issues:write access before applying labels." | |
| exit 2 | |
| fi | |
| args=(--owner evalops --json-output label-sync-report.json --markdown-output label-sync-report.md) | |
| if [ -n "${TARGET_REPOS}" ]; then | |
| args+=(--repos "${TARGET_REPOS}") | |
| fi | |
| if [ "${apply}" = "true" ]; then | |
| args+=(--apply) | |
| else | |
| args+=(--dry-run) | |
| fi | |
| ruby .github/scripts/sync-labels.rb "${args[@]}" | |
| cat label-sync-report.md >> "${GITHUB_STEP_SUMMARY}" | |
| - name: Comment dry-run summary | |
| if: ${{ github.event_name == 'pull_request' }} | |
| run: gh pr comment "${{ github.event.pull_request.number }}" --repo evalops/.github --body-file label-sync-report.md | |
| - name: Upload label sync report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: label-sync-report | |
| path: | | |
| label-sync-report.json | |
| label-sync-report.md | |
| if-no-files-found: error | |
| retention-days: 30 |