forked from google/neuroglancer
-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (65 loc) · 2.65 KB
/
deploy_docs_preview.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: Deploy docs preview
on:
workflow_run:
workflows: ["Build docs preview"]
types: [completed]
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: "Create commit status"
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commitId = "${{ github.event.workflow_run.head_commit.id }}";
await github.rest.repos.createCommitStatus({
context: "docs-preview",
owner: context.repo.owner,
repo: context.repo.repo,
sha: commitId,
state: "pending",
description: `Creating preview`,
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
});
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: docs
path: dist/docs
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
target: docs
- name: "Update commit status"
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.repos.createCommitStatus({
context: "docs-preview",
owner: context.repo.owner,
repo: context.repo.repo,
sha: commitId,
state: "success",
target_url: "${{ steps.deploy.outputs.details_url }}",
description: `Preview created, expires at: ${expires.toISOString()}`,
});