Deploy preview #11
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: | |
workflow_run: | |
workflows: ["Build preview"] | |
types: [completed] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: client | |
path: dist/min | |
github-token: "${{ secrets.GITHUB_TOKEN }}" | |
run-id: "${{ github.event.workflow_run.id }}" | |
- name: Get PR ID | |
# https://github.com/orgs/community/discussions/25220#discussioncomment-7532132 | |
id: pr-id | |
run: | | |
PR_ID=$(gh run view -R ${{ github.repository }} ${{ github.event.workflow_run.id }} | grep -oP '#[0-9]+ . ${{ github.event.workflow_run.id }}' | grep -oP '#[0-9]+' | cut -c 2-) | |
echo "pr-id=${PR_ID}" >> $GITHUB_OUTPUT | |
env: | |
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
- uses: FirebaseExtended/action-hosting-deploy@v0 | |
id: deploy | |
with: | |
repoToken: "${{ secrets.GITHUB_TOKEN }}" | |
firebaseServiceAccount: "${{ secrets.FIREBASE_HOSTING_SERVICE_ACCOUNT_KEY }}" | |
expires: 30d | |
channelId: "pr${{ steps.pr-id.outputs.pr-id }}" | |
projectId: neuroglancer-demo | |
- name: "Comment on PR" | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const expires = new Date("${{ steps.deploy.outputs.expire_time }}"); | |
const commitId = "${{ github.event.workflow_run.head_commit.id }}"; | |
await github.rest.checks.create({ | |
name: "client-preview", | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
head_sha: commitId, | |
status: "completed", | |
details_url: "${{ steps.deploy.outputs.details_url }}", | |
conclusion: "success", | |
title: `🔥 Preview created, expires at: ${expires.toISOString()}`, | |
}); |