chore: grant additional permissions to publish tests #63
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: CI | |
| on: | |
| workflow_dispatch: # Allows you to run this workflow manually from the Actions tab | |
| push: # Runs whenever a commit is pushed to the repository | |
| branches: [experience-cs] | |
| permissions: | |
| packages: write # deploy to GitHub Packages | |
| contents: read # The following 4 permissions are needed to publish test results | |
| issues: read | |
| checks: write | |
| pull-requests: write | |
| concurrency: | |
| group: "${{ github.workflow }} @ ${{ github.event.compare || github.head_ref || github.ref }}" | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| outputs: | |
| any-workspace: ${{ steps.filter.outputs.any-workspace }} | |
| packages: ${{ steps.filter.outputs.changes }} | |
| steps: | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 | |
| - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6 | |
| with: | |
| cache: "npm" | |
| node-version-file: ".nvmrc" | |
| registry-url: "https://npm.pkg.github.com" | |
| - uses: wagoid/commitlint-github-action@9763196e10f27aef304c9b8b660d31d97fce0f99 # v5 | |
| - name: Debug info | |
| # https://docs.github.com/en/actions/reference/security/secure-use#use-an-intermediate-environment-variable | |
| env: | |
| # `env:` values are printed to the log even without using them in `run:` | |
| GH_CONTEXT: ${{ toJson(github) }} | |
| run: | | |
| cat <<EOF | |
| Working directory: $(pwd) | |
| Node version: $(node --version) | |
| NPM version: $(npm --version) | |
| Scratch environment: ${{ vars.SCRATCH_ENV || '<none>' }} | |
| EOF | |
| - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3 | |
| id: filter | |
| with: | |
| filters: ./.github/path-filters.yml | |
| - if: ${{ steps.filter.outputs.any-workspace == 'true' }} | |
| env: | |
| NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| uses: ./.github/actions/install-dependencies | |
| - name: Explicitly install Rolldown linux binaries | |
| if: ${{ steps.filter.outputs.any-workspace == 'true' }} | |
| run: npm install @rolldown/binding-linux-x64-gnu --no-save --ignore-scripts | |
| - name: Build packages | |
| if: ${{ steps.filter.outputs.any-workspace == 'true' }} | |
| run: npm run build | |
| - name: Store build artifacts | |
| if: ${{ steps.filter.outputs.any-workspace == 'true' }} | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5 | |
| with: | |
| name: build | |
| path: | | |
| packages/**/build | |
| packages/**/dist | |
| packages/**/playground | |
| - name: Publish scratch-gui to GitHub Packages | |
| working-directory: ./packages/scratch-gui | |
| env: | |
| NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| RELEASE_VERSION="0.1.0-experience-cs.$(date +'%Y%m%d%H%M%S')" | |
| npm version --no-git-tag-version $RELEASE_VERSION | |
| npm publish --access public --tag latest | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: ${{ needs.build.outputs.any-workspace == 'true' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package: ${{ fromJSON(needs.build.outputs.packages) }} | |
| exclude: | |
| - package: global | |
| - package: any-workspace | |
| name: Test ${{ matrix.package }} | |
| steps: | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 | |
| - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6 | |
| with: | |
| cache: "npm" | |
| node-version-file: ".nvmrc" | |
| - uses: ./.github/actions/install-dependencies | |
| - uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6 | |
| with: | |
| name: build | |
| path: packages | |
| - uses: ./.github/actions/test-package | |
| with: | |
| package_name: ${{ matrix.package }} | |
| results: | |
| name: Test Results | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: ${{ !cancelled() }} | |
| steps: | |
| - run: | | |
| case "${{ needs.test.result }}" in | |
| success) | |
| echo "Tests passed successfully." | |
| exit 0 | |
| ;; | |
| skipped) | |
| echo "Tests were unnecessary for these changes, so they were skipped." | |
| echo "If this is unexpected, check the path filters." | |
| exit 0 | |
| ;; | |
| *) | |
| echo "Tests failed." | |
| exit 1 | |
| ;; | |
| esac |