Skip to content

Commit b62e91d

Browse files
authored
Dbp-1067-optional-rollout-prevention (#92)
* Test getting PR labels * remove pr event condition * test env var * rename env var * add github authentication * use github_token * prevent failing without existing PR * edit env var * has pr condition * remove dot * test clearance * correct var name * test push * debug output * test output * test output * new name * test output * correct variable for output * remove debugging steps * correct condition * test new condition * test * test * new condition * remove quotation marks * test condition * test output * new condition * rename to deployment * remove test output * update default for database_recreation
1 parent d00824b commit b62e91d

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

.github/workflows/image-and-helm-publish-check-deploy-on-push-scheduled.yml

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,45 @@ concurrency:
1616
cancel-in-progress: true
1717

1818
jobs:
19+
check_deployment_clearance:
20+
name: "Check deployment clearance"
21+
runs-on: ubuntu-latest
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
outputs:
25+
deployment_clearance: ${{ steps.determine_deployment_clearance.outputs.deployment_clearance }}
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v2
29+
30+
- name: Get PR number
31+
id: get_pr_number
32+
run: |
33+
PR_NUMBER=$(gh pr list --state open --head ${{ github.ref_name }} --json number --jq '.[0].number')
34+
if [ -z "$PR_NUMBER" ]; then
35+
echo "No existing PR found for ${{ github.ref_name }} "
36+
else
37+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
38+
fi
39+
40+
- name: Get PR labels
41+
id: get_pr_labels
42+
if: ${{ env.PR_NUMBER != '' }}
43+
run: |
44+
PR_LABELS=$(gh pr view ${{ env.PR_NUMBER }} --json labels --jq '.labels | map(.name) | join(",")')
45+
echo "PR_LABELS=$PR_LABELS" >> $GITHUB_ENV
46+
47+
- name: Determine deployment clearance
48+
id: determine_deployment_clearance
49+
run: |
50+
if [ -z "$env.PR_NUMBER" ] || [[ ${{ ! contains(env.PR_LABELS, 'prevent_auto_deployment') }} == true ]]; then
51+
echo "Deployment clearance: true"
52+
echo "deployment_clearance=true" >> "$GITHUB_OUTPUT"
53+
else
54+
echo "deployment_clearance=false" >> "$GITHUB_OUTPUT"
55+
echo "Deployment clearance: false"
56+
fi
57+
1958
codeql_analyze:
2059
name: "CodeQL"
2160
if: ${{ github.event_name == 'push' }}
@@ -26,10 +65,11 @@ jobs:
2665
security-events: write
2766

2867
build_image_on_push:
29-
needs:
68+
needs:
69+
- check_deployment_clearance
3070
- create_branch_identifier
3171
name: "Publish image and scan with trivy"
32-
if: ${{ github.event_name == 'push' }}
72+
if: ${{ github.event_name == 'push' && needs.check_deployment_clearance.outputs.deployment_clearance == 'true' }}
3373
permissions:
3474
packages: write
3575
security-events: write
@@ -53,7 +93,9 @@ jobs:
5393
contents: read
5494

5595
select_helm_version_generation_and_image_tag_generation:
56-
if: ${{ github.event_name == 'push'}}
96+
needs:
97+
- check_deployment_clearance
98+
if: ${{ github.event_name == 'push' && needs.check_deployment_clearance.outputs.deployment_clearance == 'true' }}
5799
runs-on: ubuntu-latest
58100
outputs:
59101
SELECT_HELM_VERSION_GENERATION: ${{ steps.select_generation.outputs.SELECT_HELM_VERSION_GENERATION }}
@@ -118,8 +160,7 @@ jobs:
118160
dbildungs_iam_keycloak_branch: ${{ needs.branch_meta.outputs.ticket }}
119161
dbildungs_iam_ldap_branch: ${{ needs.branch_meta.outputs.ticket }}
120162
namespace: ${{ needs.create_branch_identifier.outputs.namespace_from_branch }}
121-
database_recreation: ${{ github.ref_name == 'main' && 'true' || 'false' }}
122-
# database_recreation: "true" # to force database recreation this has be set to true
163+
database_recreation: "true" # to prevent database recreation this has to be set to false
123164
secrets: inherit
124165

125166
# On Delete

0 commit comments

Comments
 (0)