Update Known Good Block Numbers #3943
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: Update Known Good Block Numbers | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| retry: | |
| description: 'If this is a retry run' | |
| required: false | |
| type: boolean | |
| failed_tests: | |
| description: 'Failed tests to retry (JSON array)' | |
| required: false | |
| type: string | |
| schedule: | |
| - cron: '0 */6 * * *' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| actions: write | |
| issues: write | |
| jobs: | |
| define-matrix: | |
| timeout-minutes: 20 | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tests: ${{ steps.tests.outputs.tests }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: setup node env | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22.x | |
| cache: 'yarn' | |
| - run: yarn --immutable | |
| - name: Define Tests | |
| id: tests | |
| run: | | |
| if [ "${{ github.event.inputs.retry }}" == "true" ]; then | |
| echo "tests=$(echo '${{ github.event.inputs.failed_tests }}' | sed 's/^"\(.*\)"$/\1/')" >> "$GITHUB_OUTPUT" | |
| else | |
| echo tests=$(cd packages && ls */src/*.test.ts | jq -R -s -c 'split("\n")[:-1]') >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Update Known Good Block Numbers | |
| run: | | |
| yarn update-known-good | |
| - name: Upload Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: KNOWN_GOOD_BLOCK_NUMBERS | |
| path: | | |
| KNOWN_GOOD_BLOCK_NUMBERS_POLKADOT.env | |
| KNOWN_GOOD_BLOCK_NUMBERS_KUSAMA.env | |
| retention-days: 1 | |
| tests: | |
| needs: define-matrix | |
| timeout-minutes: 60 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| tests: ${{ fromJSON(needs.define-matrix.outputs.tests) }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: setup node env | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22.x | |
| cache: 'yarn' | |
| - run: yarn --immutable | |
| - name: Download a single artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: KNOWN_GOOD_BLOCK_NUMBERS | |
| - run: yarn test packages/${{ matrix.tests }} | |
| save: | |
| needs: tests | |
| runs-on: ubuntu-latest | |
| if: success() && github.event.inputs.retry != 'true' | |
| steps: | |
| - uses: actions/create-github-app-token@v1 | |
| id: app-token | |
| with: | |
| app-id: ${{ secrets.GH_APP_ID }} | |
| private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| - name: Download a single artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: KNOWN_GOOD_BLOCK_NUMBERS | |
| - name: Commit and push changes | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| git add -A 'KNOWN_GOOD_BLOCK_NUMBERS_*.env' | |
| if ! git diff --cached --quiet; then | |
| git commit -m "[ci skip] Update known good block numbers" | |
| git push | |
| else | |
| echo "No changes to commit" | |
| fi | |
| schedule-retry: | |
| needs: tests | |
| if: failure() && github.event.inputs.retry != 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Get failed jobs | |
| id: get-failed | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const response = await github.paginate( | |
| github.rest.actions.listJobsForWorkflowRun, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.runId | |
| } | |
| ); | |
| const failedTests = response | |
| .filter(job => job.name.startsWith('tests (') && job.conclusion === 'failure') | |
| .map(job => { | |
| const match = job.name.match(/tests \((.*)\)/); | |
| return match ? match[1] : null; | |
| }) | |
| .filter(Boolean); | |
| return JSON.stringify(failedTests); | |
| - name: sleep | |
| run: sleep 300 | |
| - name: Dispatch retry workflow | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| await github.rest.actions.createWorkflowDispatch({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| workflow_id: 'update-known-good.yml', | |
| ref: 'master', | |
| inputs: { | |
| retry: 'true', | |
| failed_tests: '${{ steps.get-failed.outputs.result }}' | |
| } | |
| }) | |
| notify: | |
| needs: tests | |
| if: failure() && github.event.inputs.retry == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Create Comment | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const response = await github.paginate( | |
| github.rest.actions.listJobsForWorkflowRun, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.runId | |
| }, | |
| ); | |
| const failedTests = response | |
| .filter(job => job.name.startsWith('tests (') && job.conclusion === 'failure') | |
| .map(job => { | |
| const match = job.name.match(/tests \((.*)\)/); | |
| return match ? match[1] : null; | |
| }) | |
| .filter(Boolean); | |
| const { data: config } = await github.rest.repos.getContent({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| path: '.github/workflows/notifications.json', | |
| ref: 'master' | |
| }) | |
| const notifications = JSON.parse(Buffer.from(config.content, 'base64').toString('utf8')) | |
| const impactedNetworks = new Set() | |
| for (const test of failedTests) { | |
| const filename = test.split('/').pop() | |
| const segments = filename.replace(/\.test\.ts$/, '').split('.') | |
| const chains = segments.filter(s => notifications[s] !== undefined) | |
| if (chains.length === 0) { | |
| impactedNetworks.add("unknown") | |
| } else { | |
| for (const chain of chains) { | |
| impactedNetworks.add(chain) | |
| } | |
| } | |
| } | |
| const issuesToNotify = new Set() | |
| for (const network of impactedNetworks) { | |
| issuesToNotify.add(notifications[network] ?? notifications['unknown']) | |
| } | |
| for (const issueNumber of issuesToNotify) { | |
| // add a comment to the issue | |
| await github.rest.issues.createComment({ | |
| issue_number: issueNumber, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `Workflow failed: https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` | |
| }) | |
| } |