Repository navigation
fix(security): Remove unsafe PR head checkout in pull_request_target workflow #2645
Workflow file for this run
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: 'Build & Test' | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - release/** | |
| pull_request: | |
| workflow_call: | |
| concurrency: | |
| group: ${{ github.ref_name || github.sha }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| strategy: | |
| matrix: | |
| node: ['20', '22'] | |
| name: Node ${{ matrix.node }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: '${{ matrix.node }}' | |
| - name: Get pnpm version from Volta config | |
| id: pnpm-version | |
| run: echo "version=$(jq -r '.volta.pnpm' package.json)" >> $GITHUB_OUTPUT | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: ${{ steps.pnpm-version.outputs.version }} | |
| - uses: actions/cache@v5 | |
| id: cache | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-${{ hashFiles('package.json', 'pnpm-lock.yaml') }} | |
| - name: Install Dependencies | |
| if: steps.cache.outputs.cache-hit != 'true' | |
| run: pnpm install --frozen-lockfile | |
| - name: Test | |
| run: pnpm test | |
| build: | |
| name: Build | |
| needs: test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| environment: ${{ github.ref == 'refs/heads/master' && 'production' }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: package.json | |
| - name: Get pnpm version from Volta config | |
| id: pnpm-version | |
| run: echo "version=$(jq -r '.volta.pnpm' package.json)" >> $GITHUB_OUTPUT | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: ${{ steps.pnpm-version.outputs.version }} | |
| - uses: actions/cache@v5 | |
| id: cache | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-${{ hashFiles('package.json', 'pnpm-lock.yaml') }} | |
| - name: Install Dependencies | |
| if: steps.cache.outputs.cache-hit != 'true' | |
| run: pnpm install --frozen-lockfile | |
| - name: Build | |
| env: | |
| CRAFT_BUILD_SHA: ${{ github.sha }} | |
| SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
| run: pnpm build | |
| - name: Smoke Test | |
| run: ./dist/craft --help | |
| - name: NPM Pack | |
| run: npm pack | |
| - name: Upload Build Artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: craft-binary | |
| path: | | |
| ${{ github.workspace }}/*.tgz | |
| ${{ github.workspace }}/dist/craft | |
| docs: | |
| name: Build Docs | |
| needs: test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: package.json | |
| - name: Get pnpm version from Volta config | |
| id: pnpm-version | |
| run: echo "version=$(jq -r '.volta.pnpm' package.json)" >> $GITHUB_OUTPUT | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: ${{ steps.pnpm-version.outputs.version }} | |
| - name: Build Docs | |
| working-directory: docs | |
| run: | | |
| pnpm install --frozen-lockfile | |
| pnpm build | |
| - name: Package Docs | |
| run: | | |
| cp .nojekyll docs/dist/ | |
| cd docs/dist && zip -r ../../gh-pages.zip . | |
| - name: Upload Docs Artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: craft-docs | |
| path: ${{ github.workspace }}/gh-pages.zip |