3333 name : Branch Check
3434 runs-on : ubuntu-latest
3535 steps :
36+ - name : Checkout code
37+ uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
38+
3639 - name : Validate branch
3740 env :
3841 TARGET_ENV : ${{ github.event.inputs.target_env }}
@@ -41,11 +44,19 @@ jobs:
4144 echo 'This workflow can only be run on branches staging and master.'
4245 exit 1
4346 fi
44- if [ "$TARGET_ENV" == 'luxadmosam' ] || [ "$TARGET_ENV" == 'euros' ]; then
45- if [ "$GITHUB_REF_NAME" != 'master' ]; then
46- echo 'Only the master branch can be deployed to external parties.'
47- exit 1
48- fi
47+ # Check branch restriction from deploy_targets.yml
48+ BRANCH_RESTRICTION=$(python3 << 'PYTHON_EOF'
49+ import yaml
50+ with open('config/deploy_targets.yml', 'r') as f:
51+ config = yaml.safe_load(f)
52+ target = config['targets']['${{ github.event.inputs.target_env }}']
53+ restriction = target.get('branch_restriction')
54+ print(restriction if restriction else '')
55+ PYTHON_EOF
56+ )
57+ if [ -n "$BRANCH_RESTRICTION" ] && [ "$GITHUB_REF_NAME" != "$BRANCH_RESTRICTION" ]; then
58+ echo "Target $TARGET_ENV can only be deployed from branch $BRANCH_RESTRICTION, but current branch is $GITHUB_REF_NAME."
59+ exit 1
4960 fi
5061
5162 metadata :
@@ -74,18 +85,25 @@ jobs:
7485 echo 'has_diff=false' >> "$GITHUB_OUTPUT"
7586 fi
7687 fi
77-
78- if [ "$TARGET_ENV" == 'luxadmosam' ]; then
79- echo 'stage=luxproduction' >> "$GITHUB_OUTPUT"
80- elif [ "$TARGET_ENV" == 'euros' ]; then
81- echo 'stage=euros' >> "$GITHUB_OUTPUT"
82- else
83- echo 'stage=production' >> "$GITHUB_OUTPUT"
84- fi
85- else
86- echo 'stage=staging' >> "$GITHUB_OUTPUT"
8788 fi
8889
90+ # Get stage from deploy_targets.yml
91+ STAGE=$(python3 << 'PYTHON_EOF'
92+ import yaml
93+ with open('config/deploy_targets.yml', 'r') as f:
94+ config = yaml.safe_load(f)
95+ target_env = '${{ github.event.inputs.target_env }}'
96+ current_branch = '${{ github.ref_name }}'
97+ # If on staging branch, always use staging stage unless targeting external party
98+ if current_branch == 'staging':
99+ print('staging')
100+ else:
101+ # On master: use the stage from the target environment
102+ print(config['targets'][target_env]['stage'])
103+ PYTHON_EOF
104+ )
105+ echo "stage=$STAGE" >> "$GITHUB_OUTPUT"
106+
89107 merge :
90108 name : Merge
91109 runs-on : ubuntu-latest
@@ -157,25 +175,31 @@ jobs:
157175 inputs.merge && fromJSON(needs.metadata.outputs.has_diff) || github.event.inputs.ignore_metadata_diff && success()) ||
158176 ((!inputs.merge|| !fromJSON(needs.metadata.outputs.has_diff)) || github.event.inputs.ignore_metadata_diff && !cancelled()))
159177 steps :
178+ - name : Checkout code
179+ uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
180+ with :
181+ ref : ${{ needs.merge.outputs.sha }}
182+
160183 - name : Get environment URL
161184 id : get_url
162185 env :
163186 TARGET_ENV : ${{ github.event.inputs.target_env }}
164187 run : |
165- if [ "$TARGET_ENV" == 'luxadmosam' ] && [ "$GITHUB_REF_NAME" = 'master' ]; then
166- echo 'environment_url=https://luxstreep.csvalpha.nl' >> "$GITHUB_OUTPUT"
167- elif [ "$TARGET_ENV" == 'euros' ] && [ "$GITHUB_REF_NAME" = 'master' ]; then
168- echo 'environment_url=https://euros.csvalpha.nl' >> "$GITHUB_OUTPUT"
169- elif [ "$GITHUB_REF_NAME" = 'master' ]; then
170- echo 'environment_url=https://streep.csvalpha.nl' >> "$GITHUB_OUTPUT"
171- else
172- echo 'environment_url=https://stagingstreep.csvalpha.nl' >> "$GITHUB_OUTPUT"
173- fi
174-
175- - name : Checkout code
176- uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
177- with :
178- ref : ${{ needs.merge.outputs.sha }}
188+ # Get URL from deploy_targets.yml based on current branch and target
189+ URL=$(python3 << 'PYTHON_EOF'
190+ import yaml
191+ with open('config/deploy_targets.yml', 'r') as f:
192+ config = yaml.safe_load(f)
193+ current_branch = '${{ github.ref_name }}'
194+ target_env = '${{ github.event.inputs.target_env }}'
195+ # If on staging, use stagingstreep URL; otherwise use the target's URL
196+ if current_branch == 'staging':
197+ print(config['targets']['stagingstreep']['url'])
198+ else:
199+ print(config['targets'][target_env]['url'])
200+ PYTHON_EOF
201+ )
202+ echo "environment_url=$URL" >> "$GITHUB_OUTPUT"
179203
180204 - name : Start deployment
181205 uses : bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0
0 commit comments