Add deploy preview workflow #4
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: Deploy Preview | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| types: [opened, synchronize, reopened] | |
| concurrency: | |
| group: deploy-preview-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| pull-requests: write | |
| deployments: write | |
| jobs: | |
| build-preview: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install Antora | |
| run: npm install antora | |
| - name: Generate Site | |
| run: npx antora antora-playbook.yml | |
| - name: Post-process paths for VC context/schema docs | |
| run: | | |
| if [ -d "build/site/identity/1.1/_attachments/ica" ]; then | |
| mv build/site/identity/1.1/_attachments/ica build/site/identity/1.1/ica | |
| fi | |
| - name: Disable Jekyll | |
| run: touch build/site/.nojekyll | |
| - name: Upload Preview Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: preview-site-${{ github.event.pull_request.number }} | |
| path: ./build/site | |
| retention-days: 30 | |
| deploy-preview: | |
| needs: build-preview | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: preview-pr-${{ github.event.pull_request.number }} | |
| url: ${{ steps.deploy.outputs.page_url }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download Preview Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: preview-site-${{ github.event.pull_request.number }} | |
| path: ./site | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Upload Pages Artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./site | |
| - name: Deploy to GitHub Pages | |
| id: deploy | |
| uses: actions/deploy-pages@v4 | |
| - name: Comment on PR | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| // Read and execute the external script | |
| const scriptPath = path.join(process.cwd(), '.github/scripts/comment-preview.js'); | |
| const scriptContent = fs.readFileSync(scriptPath, 'utf8'); | |
| const commentScript = eval(`(${scriptContent})`); | |
| const deploymentUrl = '${{ steps.deploy.outputs.page_url }}'; | |
| await commentScript({ github, context, deploymentUrl }); | |
| cleanup-on-close: | |
| runs-on: ubuntu-latest | |
| if: github.event.action == 'closed' | |
| steps: | |
| - name: Delete deployment environment | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| // Read and execute the external script | |
| const scriptPath = path.join(process.cwd(), '.github/scripts/delete-environment.js'); | |
| const scriptContent = fs.readFileSync(scriptPath, 'utf8'); | |
| const deleteScript = eval(`(${scriptContent})`); | |
| await deleteScript({ github, context }); |