Skip to content

Deploy Preview

Deploy Preview #389

name: Deploy Preview
on:
workflow_run:
workflows:
- Start Preview Deployment
types:
- completed
permissions:
contents: read
id-token: write
deployments: write
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
concurrency:
group: staging-web
steps:
- name: Harden the runner
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: block
allowed-endpoints: >
9236a389bd48b984df91adc1bc924620.r2.cloudflarestorage.com:443
api.github.com:443
apk.cgr.dev:443
artifactregistry.googleapis.com:443
cgr.dev:443
dl.google.com:443
europe-west1-docker.pkg.dev:443
europe-west1-run.googleapis.com:443
github.com:443
iamcredentials.googleapis.com:443
nodejs.org:443
raw.githubusercontent.com:443
run.googleapis.com:443
serviceusage.googleapis.com:443
sts.googleapis.com:443
- name: Checkout the repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Download server from prepare step
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: preview-server
repository: ${{ github.repository_owner }}/${{ github.event.repository.name }}
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.PREVIEW_ARTIFACT_PAT }}
- name: Extract archive to restore symlinks
run: tar -xf server.tar
- name: Extract PR number
run: |
PR_NUMBER=$(cat ./preview-id)
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Notify about new deployment
uses: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0
id: status
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.workflow_run.head_commit.id }}
env: preview-${{ env.PR_NUMBER }}
- name: Deploy to Google Cloud
id: deploy
uses: ./.github/actions/deploy
with:
projectId: slowreader-453400
region: europe-west1
folder: ./server/
registry: staging/server
service: staging-server
tag: preview-${{ env.PR_NUMBER }}
env: ASSETS=1,DATABASE_URL=memory://,PROXY_ORIGIN=^https:\/\/preview-\d+---staging-server-300174498438\.europe-west1\.run\.app$
# flags: |
# --update-secrets DATABASE_URL=preview-db-url:latest
- name: Update deployment status
uses: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env: ${{ steps.status.outputs.env }}
env_url: ${{ steps.deploy.outputs.url }}/ui/
deployment_id: ${{ steps.status.outputs.deployment_id }}