ci: add 'attestations: write' for the 'publish' job #1
This file contains 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: CI/CD Workflow | |
on: | |
push: | |
branches: [main, next] | |
paths: ["src/**/*", "package*.json"] | |
# This workflow can be manually triggered | |
workflow_dispatch: | |
permissions: | |
attestations: write # to generate artifact attestations for dist assets | |
contents: write # to checkout the code and create a release | |
id-token: write # to publish to npm using OIDC | |
pull-requests: write # to add coverage reports to a PR | |
statuses: write # to update commit status | |
jobs: | |
test: | |
name: Test | |
uses: ./.github/workflows/test.yaml | |
secrets: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
permissions: | |
contents: read # to checkout the code | |
pull-requests: write # to add coverage reports to the PR | |
statuses: write # to update commit status | |
release: | |
name: Release | |
needs: test # only release if tests passed | |
if: needs.test.outputs.success == 'true' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # to create a release | |
outputs: | |
new_release_published: ${{ steps.semantic-release.outputs.new_release_published }} | |
new_release_git_tag: ${{ steps.semantic-release.outputs.new_release_git_tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
fetch-depth: 0 | |
- name: Run Semantic-Release | |
id: semantic-release | |
uses: cycjimmy/semantic-release-action@v4 | |
with: | |
extra_plugins: | | |
@semantic-release/changelog@6.0.3 | |
@semantic-release/git@10.0.1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_TOKEN }} | |
publish: | |
name: Publish | |
needs: release # only publish if a release was created | |
if: needs.release.outputs.new_release_published == 'true' | |
runs-on: ubuntu-latest | |
permissions: | |
attestations: write # to generate artifact attestations for dist assets | |
contents: read # to checkout the code | |
id-token: write # to publish to npm using OIDC | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: ".nvmrc" | |
registry-url: "https://registry.npmjs.org" | |
- name: Publish to npm | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH_PUBLIC_ORG_SCOPE }} | |
run: | | |
npm ci --include=dev | |
npm run build | |
latest_or_next_tag=$( | |
[[ ${{ needs.release.outputs.new_release_git_tag }} =~ next ]] && | |
echo 'next' || | |
echo 'latest' | |
) | |
npm publish --provenance --access public \ | |
--tag ${{ github.ref }} \ | |
--tag $latest_or_next_tag |