| name: Release package | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "RELEASE_NOTES.md" | |
| release: | |
| types: | |
| - published | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
| permissions: | |
| contents: write | |
| id-token: write # OIDC for npm Trusted Publishing | |
| issues: write | |
| jobs: | |
| create-release: | |
| if: github.repository == 'mdn/browser-compat-data' && github.event_name == 'push' && startsWith(github.event.head_commit.message, 'Release v') | |
| name: Create release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout (BCD) | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: Create release | |
| run: | | |
| VERSION=v$(jq -r '.version' package.json) | |
| awk '/^## /{if (p) exit; p=1; next} p' RELEASE_NOTES.md | tail -n +4 >> CURRENT_RELEASE_NOTES.md | |
| gh release create $VERSION --title=$VERSION --target $GITHUB_SHA --notes-file CURRENT_RELEASE_NOTES.md --latest | |
| publish-release: | |
| if: github.event_name == 'release' | |
| name: Publish release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | |
| with: | |
| node-version-file: ".nvmrc" | |
| package-manager-cache: false | |
| registry-url: "https://registry.npmjs.org/" | |
| - run: npm ci | |
| - run: npm test | |
| env: | |
| FORCE_COLOR: 3 | |
| - run: npm run build | |
| - run: npm publish build/ --access public --provenance | |
| - name: Add JSON as a release asset | |
| run: gh release upload ${GITHUB_REF#refs/*/} build/data.json | |
| # - name: Publish stats for all data (#3555) | |
| # run: npm run --silent stats | gh issue comment https://github.com/mdn/browser-compat-data/issues/3555 --body-file - | |
| - name: Trigger BCD deployment | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | |
| with: | |
| github-token: ${{ secrets.DISPATCH_PAT }} | |
| script: | | |
| const result = await github.rest.repos.createDispatchEvent({ | |
| owner: 'mdn', | |
| repo: 'bcd-utils', | |
| event_type: 'bcd_release', | |
| client_payload: {} | |
| }) | |
| console.log(result); | |
| - name: Comment in release PR | |
| if: always() | |
| env: | |
| JOB_STATUS: ${{ job.status }} | |
| RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| run: | | |
| if [ "$JOB_STATUS" = "success" ]; then | |
| BODY="Release was successfully published by [this run]($RUN_URL)." | |
| else | |
| BODY="@mdn/bcd-releasers Failed to publish release (see [this run]($RUN_URL)." | |
| fi | |
| PR_NUMBER=$(gh pr list --repo "$GITHUB_REPOSITORY" --state merged --search "$GITHUB_SHA" --json number --jq '.[0].number') | |
| gh pr comment --repo "$GITHUB_REPOSITORY" "$PR_NUMBER" --body "$BODY" |