Skip to content

Commit 10da570

Browse files
authored
fix: prevent PR deployment without manual trigger (#8882)
* fix: do not deploy without a manual trigger This will fix automatic first deployment * fix typo * Update pr-deploy.yaml * Update pr-deploy.yaml * Update pr-deploy.yaml * Update pr-deploy.yaml * Update pr-deploy.yaml * Update pr-deploy.yaml * Update pr-deploy.yaml * build at least once * wait for certificate * Update pr-deploy.yaml
1 parent b47bd7c commit 10da570

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

.github/workflows/pr-cleanup.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ jobs:
7070
if: ${{ github.event.pull_request.merged == true }}
7171
run: |
7272
set -euxo pipefail
73-
kuebctl delete certificate "pr${{ steps.pr_number.outputs.PR_NUMBER }}-tls" -n pr-deployment-certs || echo "certificate not found"
73+
kubectl delete certificate "pr${{ steps.pr_number.outputs.PR_NUMBER }}-tls" -n pr-deployment-certs || echo "certificate not found"

.github/workflows/pr-deploy.yaml

+17-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
CODER_BASE_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }}
4747
CODER_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }}
4848
NEW: ${{ steps.check_deployment.outputs.new }}
49-
BUILD: ${{ steps.filter.outputs.all_count > steps.filter.outputs.ignored_count }}
49+
BUILD: ${{ steps.filter.outputs.all_count > steps.filter.outputs.ignored_count || steps.check_deployment.outputs.new }}
5050

5151
runs-on: "ubuntu-latest"
5252
steps:
@@ -87,13 +87,14 @@ jobs:
8787
echo "Deployment already exists. Skipping deployment."
8888
new=false
8989
else
90-
echo "Deployment doesn't exist. Creating a new one."
90+
echo "Deployment doesn't exist."
9191
new=true
9292
fi
9393
echo "new=$new" >> $GITHUB_OUTPUT
9494
9595
- name: Find Comment
9696
uses: peter-evans/find-comment@v2
97+
if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false'
9798
id: fc
9899
with:
99100
issue-number: ${{ steps.pr_info.outputs.PR_NUMBER }}
@@ -103,6 +104,7 @@ jobs:
103104

104105
- name: Comment on PR
105106
id: comment_id
107+
if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false'
106108
uses: peter-evans/create-or-update-comment@v3
107109
with:
108110
comment-id: ${{ steps.fc.outputs.comment-id }}
@@ -116,12 +118,14 @@ jobs:
116118
reactions-edit-mode: replace
117119

118120
- name: Checkout
121+
if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false'
119122
uses: actions/checkout@v3
120123
with:
121124
ref: ${{ steps.pr_info.outputs.PR_BRANCH }}
122125
fetch-depth: 0
123126

124127
- name: Check changed files
128+
if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false'
125129
uses: dorny/paths-filter@v2
126130
id: filter
127131
with:
@@ -145,6 +149,7 @@ jobs:
145149
- "scripts/**/*[^D][^o][^c][^k][^e][^r][^f][^i][^l][^e][.][b][^a][^s][^e]*"
146150
147151
- name: Print number of changed files
152+
if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false'
148153
run: |
149154
set -euxo pipefail
150155
echo "Total number of changed files: ${{ steps.filter.outputs.all_count }}"
@@ -154,10 +159,10 @@ jobs:
154159
needs: get_info
155160
# Skips the build job if the workflow was triggered by a workflow_dispatch event and the skip_build input is set to true
156161
# or if the workflow was triggered by an issue_comment event and the comment body contains --skip-build
157-
# alwyas run the build job if the workflow was triggered by a pull_request event
162+
# always run the build job if a pull_request event triggered the workflow
158163
if: |
159164
(github.event_name == 'workflow_dispatch' && github.event.inputs.skip_build == 'false') ||
160-
(github.event_name == 'pull_request' && needs.get_info.outputs.NEW == 'false')
165+
(github.event_name == 'pull_request' && needs.get_info.result == 'success' && needs.get_info.outputs.NEW == 'false')
161166
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
162167
env:
163168
DOCKER_CLI_EXPERIMENTAL: "enabled"
@@ -211,7 +216,9 @@ jobs:
211216
deploy:
212217
needs: [build, get_info]
213218
# Run deploy job only if build job was successful or skipped
214-
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && needs.get_info.result == 'success'
219+
if: |
220+
always() && (needs.build.result == 'success' || needs.build.result == 'skipped') &&
221+
(github.event_name == 'workflow_dispatch' || needs.get_info.outputs.NEW == 'false')
215222
runs-on: "ubuntu-latest"
216223
env:
217224
CODER_IMAGE_TAG: ${{ needs.get_info.outputs.CODER_IMAGE_TAG }}
@@ -287,6 +294,11 @@ jobs:
287294
echo "Certificate exists. Skipping certificate creation."
288295
fi
289296
echo "Copy certificate from pr-deployment-certs to pr${{ env.PR_NUMBER }} namespace"
297+
until kubectl get secret pr${{ env.PR_NUMBER }}-tls -n pr-deployment-certs &> /dev/null
298+
do
299+
echo "Waiting for secret pr${{ env.PR_NUMBER }}-tls to be created..."
300+
sleep 5
301+
done
290302
(
291303
kubectl get secret pr${{ env.PR_NUMBER }}-tls -n pr-deployment-certs -o json |
292304
jq 'del(.metadata.namespace,.metadata.creationTimestamp,.metadata.resourceVersion,.metadata.selfLink,.metadata.uid,.metadata.managedFields)' |

0 commit comments

Comments
 (0)