1
1
name : Azure - Deploy Preview Environment
2
2
3
- # **What it does**: Build and deploy to an Azure preview environment
4
- # **Why we have it**: It's our preview environment deploy mechanism, only applicable to docs-internal
3
+ # **What it does**: Build and deploy an Azure preview environment for this PR
4
+ # **Why we have it**: It's our preview environment deploy mechanism, to docs-internal and docs public repo
5
5
# **Who does it impact**: All contributors.
6
6
7
- # This whole workflow is only guaranteed to be secure in the *private
8
- # repo* and because we repo-sync these files over the to the public one,
9
- # IT'S IMPORTANT THAT THIS WORKFLOW IS ONLY ENABLED IN docs-internal!
7
+ # !!!
8
+ # ! This worflow has access to secrets, runs in the public repository, and clones untrusted user code.
9
+ # ! Modify with extreme caution
10
+ # !!!
10
11
11
12
on :
12
13
# The advantage of 'pull_request' over 'pull_request_target' is that we
15
16
# From a security point of view, its arguably safer this way because
16
17
# unlike 'pull_request_target', these only have secrets if the pull
17
18
# request creator has permission to access secrets.
18
- pull_request :
19
+ pull_request_target :
19
20
workflow_dispatch :
20
21
inputs :
21
22
PR_NUMBER :
22
23
description : ' PR Number'
23
24
type : string
24
25
required : true
26
+ COMMIT_REF :
27
+ description : ' The commit SHA to build'
28
+ type : string
29
+ required : true
25
30
26
31
permissions :
27
32
contents : read
@@ -34,7 +39,6 @@ concurrency:
34
39
35
40
jobs :
36
41
build-and-deploy-azure-preview :
37
- if : ${{ github.repository == 'github/docs-internal' }}
38
42
name : Build and deploy Azure preview environment
39
43
runs-on : ubuntu-latest
40
44
timeout-minutes : 15
47
51
url : ${{ env.APP_URL }}
48
52
env :
49
53
PR_NUMBER : ${{ github.event.number || github.event.inputs.PR_NUMBER }}
50
- ENABLE_EARLY_ACCESS : ${{ github.repository == 'github/docs-internal' }}
54
+ COMMIT_REF : ${{ github.event.pull_request.head.sha || github.event.inputs.COMMIT_REF }}
55
+ BRANCH_NAME : ${{ github.head_ref || github.ref_name }}
56
+ IS_INTERNAL_BUILD : ${{ github.repository == 'github/docs-internal' }}
57
+ # This may also run in forked repositories, not just 'github/docs'
58
+ IS_PUBLIC_BUILD : ${{ github.repository != 'github/docs-internal' }}
51
59
52
60
steps :
53
61
- name : ' Az CLI login'
@@ -65,10 +73,19 @@ jobs:
65
73
- name : Set up Docker Buildx
66
74
uses : docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25
67
75
68
- - name : Check out repo
76
+ - if : ${{ env.IS_PUBLIC_BUILD }}
77
+ name : Check out main branch
78
+ uses : actions/checkout@1e204e9a9253d643386038d443f96446fa156a97
79
+ with :
80
+ ref : ' main'
81
+ persist-credentials : ' false'
82
+ lfs : ' true'
83
+
84
+ - if : ${{ env.IS_INTERNAL_BUILD }}
85
+ name : Check out PR code
69
86
uses : actions/checkout@1e204e9a9253d643386038d443f96446fa156a97
70
87
with :
71
- ref : ${{ github.event.pull_request.head.sha }}
88
+ ref : ${{ env.COMMIT_REF }}
72
89
# To prevent issues with cloning early access content later
73
90
persist-credentials : ' false'
74
91
lfs : ' true'
@@ -84,14 +101,14 @@ jobs:
84
101
- name : ' Set env vars'
85
102
run : |
86
103
# Image tag is unique to each workflow run so that it always triggers a new deployment
87
- echo "DOCKER_IMAGE=${{ secrets.NONPROD_REGISTRY_SERVER }}/${IMAGE_REPO}:${{ github.event.pull_request.head.sha }}-${{ github.run_number }}-${{ github.run_attempt }}" >> $GITHUB_ENV
104
+ echo "DOCKER_IMAGE=${{ secrets.NONPROD_REGISTRY_SERVER }}/${IMAGE_REPO}:${{ env.COMMIT_REF }}-${{ github.run_number }}-${{ github.run_attempt }}" >> $GITHUB_ENV
88
105
89
- - if : ${{ env.ENABLE_EARLY_ACCESS }}
106
+ - if : ${{ env.IS_INTERNAL_BUILD }}
90
107
name : Determine which docs-early-access branch to clone
91
108
id : ' check-early-access'
92
109
uses : actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
93
110
env :
94
- BRANCH_NAME : ${{ github.head_ref || github.ref_name }}
111
+ BRANCH_NAME : ${{ env.BRANCH_NAME }}
95
112
with :
96
113
github-token : ${{ secrets.DOCUBOT_REPO_PAT }}
97
114
result-encoding : string
@@ -116,7 +133,7 @@ jobs:
116
133
return 'main'
117
134
}
118
135
119
- - if : ${{ env.ENABLE_EARLY_ACCESS }}
136
+ - if : ${{ env.IS_INTERNAL_BUILD }}
120
137
name : Clone docs-early-access
121
138
uses : actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
122
139
with :
@@ -125,10 +142,25 @@ jobs:
125
142
path : docs-early-access
126
143
ref : ${{ steps.check-early-access.outputs.result }}
127
144
128
- - if : ${{ env.ENABLE_EARLY_ACCESS }}
145
+ - if : ${{ env.IS_INTERNAL_BUILD }}
129
146
name : Merge docs-early-access repo's folders
130
147
run : .github/actions-scripts/merge-early-access.sh
131
148
149
+ - if : ${{ env.IS_PUBLIC_BUILD }}
150
+ name : Check out user code to temp directory
151
+ uses : actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
152
+ with :
153
+ path : ./user-code
154
+ ref : ${{ env.COMMIT_REF }}
155
+
156
+ # Move acceptable user changes into our main branch checkout
157
+ - if : ${{ env.IS_PUBLIC_BUILD }}
158
+ name : Move acceptable user changes
159
+ run : |
160
+ rsync -rptovR ./user-code/content/./**/*.md ./content
161
+ rsync -rptovR ./user-code/assets/./**/*.png ./assets
162
+ rsync -rptovR ./user-code/data/./**/*.{yml,md} ./data
163
+
132
164
# In addition to making the final image smaller, we also save time by not sending unnecessary files to the docker build context
133
165
- name : ' Prune for preview env'
134
166
run : .github/actions-scripts/prune-for-preview-env.sh
0 commit comments