-
Notifications
You must be signed in to change notification settings - Fork 63
131 lines (122 loc) · 6.47 KB
/
Copy pathpr-deploy.yml
File metadata and controls
131 lines (122 loc) · 6.47 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: "Deploy PR for review"
on:
workflow_run: # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
workflows: [Build and check HTML]
types: [completed]
permissions:
pull-requests: write
jobs:
deploy:
if:
github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event ==
'pull_request' && github.repository == 'leanprover/reference-manual'
runs-on: ubuntu-latest
steps:
- name: Retrieve information about the original workflow
uses: potiuk/get-workflow-origin@v1_1 # https://github.com/marketplace/actions/get-workflow-origin
# This action is deprecated and archived, but it seems hard to find a
# better solution for getting the PR number
# see https://github.com/orgs/community/discussions/25220 for some discussion
id: workflow-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
- name: Download artifact
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
id: download-artifact
uses: dawidd6/action-download-artifact@v7
with:
run_id: ${{ github.event.workflow_run.id }}
name: "html"
path: _out
allow_forks: true
# Detect whether we have the new combined site structure or the old single-site structure
- name: Detect deployment structure
id: detect-structure
run: |
# Individual redirects are more readable than grouped output for simple variable assignments
# shellcheck disable=SC2129
if [ -d "_out/site" ]; then
echo "structure=new" >> "$GITHUB_OUTPUT"
echo "site_dir=_out/site" >> "$GITHUB_OUTPUT"
echo "draft_dir=_out/draft-site" >> "$GITHUB_OUTPUT"
else
echo "structure=old" >> "$GITHUB_OUTPUT"
echo "site_dir=_out/html-multi" >> "$GITHUB_OUTPUT"
echo "draft_dir=_out/draft/html-multi" >> "$GITHUB_OUTPUT"
fi
# deploy-alias computes a URL component for the PR preview. This
# is so we can have a stable name to use for feedback on draft
# material.
- id: deploy-alias
uses: actions/github-script@v7
name: Compute Alias
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
with:
result-encoding: string
script: |
if (process.env.PR) {
return `pr-${process.env.PR}`
} else {
return 'deploy-preview-main';
}
env:
PR: ${{ steps.workflow-info.outputs.pullRequestNumber }}
- name: Deploy current draft
id: deploy-draft
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
uses: nwtgck/actions-netlify@v2.0
with:
publish-dir: ${{ steps.detect-structure.outputs.site_dir }}
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: |
${{ format('pr#{0}', steps.workflow-info.outputs.pullRequestNumber) }}
alias: ${{ steps.deploy-alias.outputs.result }}
enable-commit-comment: false
enable-pull-request-comment: false
github-deployment-environment: |
${{ format('lean-ref-pr-#{0}', steps.workflow-info.outputs.pullRequestNumber) || 'lean-ref' }}
github-deployment-description: |
Draft without proofreading info
fails-without-credentials: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: "32e0f63e-7a18-4bf9-87f4-713650c7db70"
# When pushing to `main` or a PR branch, deploy it with proofreading info as well
- name: Deploy with proofreading info (draft mode, for PRs)
id: deploy-draft-proofreading
uses: nwtgck/actions-netlify@v2.0
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
with:
publish-dir: ${{ steps.detect-structure.outputs.draft_dir }}
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: |
${{ format('pr#{0} proofreading', steps.workflow-info.outputs.pullRequestNumber) }}
alias: draft-${{ steps.deploy-alias.outputs.result }}
enable-commit-comment: false
enable-pull-request-comment: false
github-deployment-environment: |
${{ format('lean-ref-pr-draft-#{0}', steps.workflow-info.outputs.pullRequestNumber) }}
github-deployment-description: |
Draft with proofreading info
fails-without-credentials: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: "32e0f63e-7a18-4bf9-87f4-713650c7db70"
# actions-netlify cannot add deploy links to a PR because it assumes a
# pull_request context, not a workflow_run context, see
# https://github.com/nwtgck/actions-netlify/issues/545
# We work around by using a comment to post the latest link
- name: "Comment on PR with preview links"
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ env.PR_NUMBER }}
header: preview-comment
recreate: true
message: |
[Preview for this PR](${{ steps.deploy-draft.outputs.deploy-url }}) is ready! :tada: [(also as a proofreading version)](${{ steps.deploy-draft-proofreading.outputs.deploy-url }}). built with commit ${{ env.PR_HEADSHA }}.
env:
PR_NUMBER: ${{ steps.workflow-info.outputs.pullRequestNumber }}
PR_HEADSHA: ${{ steps.workflow-info.outputs.sourceHeadSha }}