chore: refine shared build targets and npm scripts across docs and academy repos #7
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 Docs Preview | |
| on: | |
| pull_request: | |
| branches: [master] | |
| types: [opened, synchronize, reopened, closed] | |
| paths: | |
| - 'content/**' | |
| - '**.md' | |
| - '**.go' | |
| - 'hugo.yaml' | |
| - '.github/workflows/build-docs-preview.yml' | |
| - '.github/workflows/deploy-docs-preview.yml' | |
| - '.github/workflows/docs-preview-cleanup.yml' | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: preview-${{ github.event.pull_request.number || github.run_id }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-docs-preview: | |
| runs-on: ubuntu-24.04 | |
| if: github.event.action != 'closed' | |
| # env: | |
| # HUGO_VERSION: 0.158.0 | |
| steps: | |
| # Hugo Module fetching hits proxy.golang.org and sum.golang.org. Harmless under egress-policy: audit, but if the harden-runner is promoted to block, | |
| # those two plus objects.githubusercontent.com must be in allowed-endpoints or the build dies at module resolution. | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout PR | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| persist-credentials: false | |
| # hugo-extended is one of the dependencies which gets added onto the node_modules whenever npm install is run, | |
| # so the commented out code below serves as a second installation of hugo within the runner. | |
| # the commented out code is to be removed if the pr preview builds successfully. | |
| # - name: Install Hugo CLI | |
| # run: | | |
| # wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ | |
| # && sudo dpkg -i ${{ runner.temp }}/hugo.deb | |
| # - name: Install Dart Sass | |
| # # Direct download from the dart-sass GitHub release rather than | |
| # # `sudo snap install dart-sass` (snap.io's storeserver was flaky | |
| # # in GitHub-hosted runners and broke this workflow on unrelated | |
| # # PRs, see #19574). Hugo Extended ships embedded Dart Sass as of | |
| # # v0.114+ but having the standalone binary on PATH is the most | |
| # # reliable path through `resources.toCSS` with transpiler "dartsass". | |
| # env: | |
| # DART_SASS_VERSION: 1.79.5 | |
| # run: | | |
| # set -eu | |
| # cd "${RUNNER_TEMP}" | |
| # curl -fsSL -o dart-sass.tar.gz "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" | |
| # sudo tar -xzf dart-sass.tar.gz -C /usr/local/lib | |
| # sudo ln -sf /usr/local/lib/dart-sass/sass /usr/local/bin/sass | |
| # sudo ln -sf /usr/local/lib/dart-sass/sass /usr/local/bin/dart-sass | |
| # dart-sass --version | |
| - name: Setup Go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 | |
| with: | |
| go-version-file: go.mod | |
| - name: Setup Node | |
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | |
| with: | |
| node-version: "22" | |
| - name: Install dependencies | |
| run: | | |
| if [ -f package-lock.json ]; then | |
| npm ci | |
| else | |
| npm install | |
| fi | |
| - name: Build PR preview | |
| env: | |
| HUGO_PREVIEW: "true" | |
| DEPLOY_PRIME_URL: "/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/" | |
| run: | | |
| npm run build:preview | |
| cat > public/robots.txt <<'ROBOTS' | |
| User-agent: * | |
| Disallow: / | |
| ROBOTS | |
| - name: Save PR Metadata | |
| run: | | |
| mkdir -p ./pr | |
| echo "${{ github.event.number }}" > ./pr/number | |
| echo "${{ github.event.pull_request.head.sha }}" > ./pr/sha | |
| echo "${{ github.event.action }}" > ./pr/action | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: docs-preview-build | |
| path: | | |
| ${{ github.event.action != 'closed' && 'public' || '' }} | |
| pr/ | |
| if-no-files-found: error |