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 and Preview Site | |
| on: | |
| pull_request_target: | |
| branches: [master] | |
| types: [opened, synchronize, reopened, closed] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout 🛎️ | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Install and Build 🔧 | |
| env: | |
| PATH_PREFIX: /recognition/pr-preview/pr-${{ github.event.pull_request.number }} | |
| run: | | |
| npm install | |
| node -v | |
| npm run build -- --prefix-paths | |
| - name: Broken Link Check 🔗 | |
| uses: technote-space/broken-link-checker-action@v2 | |
| with: | |
| target: ./public/**/*.html | |
| - name: Zip Site | |
| run: | | |
| bash .github/workflows/script.sh | |
| - name: Upload files | |
| uses: actions/upload-artifact@master | |
| with: | |
| name: public-dir | |
| path: public-dir.zip | |
| retention-days: 1 | |
| preview: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request_target' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout 🛎️ | |
| uses: actions/checkout@v6 | |
| - name: Download pre-built site | |
| if: github.event_name == 'pull_request_target' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: public-dir | |
| path: . | |
| - name: Extract site | |
| if: github.event_name == 'pull_request_target' | |
| run: | | |
| unzip -q public-dir.zip | |
| # Ensure the extracted folder has the static files in a 'public' dir for the action | |
| if [ -d "public-dir" ] && [ ! -d "public" ]; then | |
| mv public-dir public | |
| elif [ ! -d "public" ]; then | |
| echo "Warning: Neither public nor public-dir found after extraction" | |
| fi | |
| - name: Remove CNAME from preview build | |
| if: github.event_name == 'pull_request_target' | |
| run: | | |
| # Remove CNAME from the built site to prevent DNS redirect to badges.layer5.io | |
| # This ensures PR previews use the default GitHub Pages domain | |
| if [ -f public/CNAME ]; then | |
| rm public/CNAME | |
| echo "CNAME removed from preview build to prevent DNS redirect" | |
| else | |
| echo "No CNAME file found in public directory" | |
| fi | |
| - name: Deploy Preview | |
| if: github.event_name == 'pull_request_target' && github.event.action != 'closed' | |
| uses: rossjrw/pr-preview-action@v1.6.3 | |
| with: | |
| source-dir: public | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Remove Preview on Close | |
| if: github.event_name == 'pull_request_target' && github.event.action == 'closed' | |
| uses: rossjrw/pr-preview-action@v1.6.3 | |
| with: | |
| source-dir: public | |
| remove: true | |
| token: ${{ secrets.GITHUB_TOKEN }} |