implement deploy previews #9
Workflow file for this run
This file contains 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 | |
permissions: | |
contents: read | |
pull-requests: write | |
env: | |
SPIN_OPERATOR_RELEASE: "v0.2.0" | |
HUGO_VERSION: "0.123.0" | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- 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 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: 'npm' | |
- name: Install Node.js dependencies | |
run: npm ci | |
- name: Setup Go environment | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.22.x' | |
cache: true | |
- name: Generate CRD reference docs | |
run: ./generate.sh | |
working-directory: ./crd-reference | |
env: | |
SPIN_OPERATOR_RELEASE: ${{ env.SPIN_OPERATOR_RELEASE }} | |
- name: Build | |
run: hugo --gc --minify | |
- name: Upload pages | |
id: deploy-preview | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./public | |
- name: Make a comment | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
// Get the existing comments. | |
const {data: comments} = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.number, | |
}) | |
// Find any comment already made by the bot. | |
const botComment = comments.find(comment => comment.user.id === 41898282) | |
const commentBody = `Your deploy preview is ready at https://${context.serverUrl}}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/artifacts/${{ steps.deploy-preview.outputs.artifact_id }}` | |
if (botComment) { | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: botComment.id, | |
body: commentBody | |
}) | |
} else { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.number, | |
body: commentBody | |
}) | |
} |