Skip to content

Commit 94f9a25

Browse files
authored
Update nginx.org-make-aws.yml
1 parent f33e372 commit 94f9a25

File tree

1 file changed

+60
-51
lines changed

1 file changed

+60
-51
lines changed

.github/workflows/nginx.org-make-aws.yml

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,53 @@ defaults:
4040
shell: 'bash -Eeo pipefail -x {0}'
4141

4242
jobs:
43+
check-if-allowed:
44+
if: ${{ ( github.repository_owner == 'nginx' || github.repository_owner == 'nginxinc' ) }}
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: Check if we're in the allowed environment
49+
run: |
50+
org_found=0
51+
event_found=0
52+
ref_found=0
53+
user_found=0
54+
ALLOWED_ORGS="nginx nginxinc"
55+
ALLOWED_EVENTS="push workflow_dispatch"
56+
ALLOWED_REFS="refs/heads/main"
57+
ALLOWED_USERS="${{ secrets.ALLOWED_USERS }}"
58+
for org in $ALLOWED_ORGS; do
59+
if [ "$org" == "$GITHUB_REPOSITORY_OWNER" ]; then org_found=1; fi
60+
done
61+
for event in $ALLOWED_EVENTS; do
62+
if [ "$event" == "$GITHUB_EVENT_NAME" ]; then event_found=1; fi
63+
done
64+
for ref in $ALLOWED_REFS; do
65+
if [ ${{ inputs.deployment_env } == 'prod' ]; then
66+
if [ "$ref" == "$GITHUB_REF" ]; then ref_found=1; fi
67+
else
68+
ref_found=1
69+
fi
70+
done
71+
for user in ALLOWED_USERS; do
72+
if [ ${{ inputs.deployment_env } == 'prod' ]; then
73+
if [ "$user" == "$GITHUB_ACTOR" ]; then user_found=1; fi
74+
else
75+
user_found=1
76+
fi
77+
done
78+
if [ $org_found$event_found$ref_found -ne 1111 ]; then
79+
echo "Repository owner, event, ref or actor are not explicitely allowed to use this workflow: $GITHUB_REPOSITORY_OWNER, $GITHUB_EVENT_NAME, $GITHUB_REF, $GITHUB_ACTOR"
80+
exit 1
81+
fi
82+
exit 0
83+
4384
build-staging:
4485
name: build-staging
4586
runs-on: ubuntu-latest
4687
if: ${{ inputs.deployment_env == 'staging' }}
4788

48-
steps:
49-
50-
- name: Decode OIDC sub
51-
uses: actions/github-script@v7
52-
id: oidc
53-
with:
54-
script: |
55-
const idToken = await core.getIDToken();
56-
const payload = idToken.split('.')[1];
57-
const decoded = Buffer.from(payload, 'base64').toString('utf8');
58-
core.info(decoded);
59-
60-
- name: Debug context
61-
run: |
62-
echo "Repository: $GITHUB_REPOSITORY"
63-
echo "Ref: $GITHUB_REF"
64-
echo "Actor: $GITHUB_ACTOR"
65-
echo "${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_NAME }}"
66-
89+
steps:
6790
- name: Install dependencies
6891
run: |
6992
sudo apt-get update
@@ -119,8 +142,15 @@ jobs:
119142
- name: Deployment summary
120143
run: |
121144
{
122-
echo "### Deployment staging to https://${{ inputs.url_staging }}/${GITHUB_SHA}"
123-
echo "### It should be accessible in 5 minutes"
145+
echo "### Deployment Summary"
146+
echo ""
147+
echo "| Key | Value |"
148+
echo "|------------------|-------|"
149+
echo "| deployment_env | ${{ inputs.deployment_env }} |"
150+
echo "| repository | $GITHUB_REPOSITORY |"
151+
echo "| actor | $GITHUB_ACTOR |"
152+
echo "| commit | $GITHUB_SHA |"
153+
echo "| Public URL | https://${{ inputs.url_staging }}/${GITHUB_SHA} |"
124154
} >> $GITHUB_STEP_SUMMARY
125155
126156
build-prod:
@@ -129,35 +159,6 @@ jobs:
129159
if: ${{ inputs.deployment_env == 'prod' }}
130160

131161
steps:
132-
133-
- name: Check prod access
134-
if: ${{ inputs.deployment_env == 'prod' }}
135-
run: |
136-
if [ "$GITHUB_REF" != "refs/heads/main" ]; then
137-
echo "Error: Production deployments are only allowed from the main branch."
138-
exit 1
139-
fi
140-
141-
if [ "$GITHUB_REPOSITORY_OWNER" != "nginx" ] && [ "$GITHUB_REPOSITORY_OWNER" != "nginxinc" ]; then
142-
echo "Error: This workflow is only allowed in repositories owned by 'nginx' or 'nginxinc'."
143-
exit 1
144-
fi
145-
146-
allowed=false
147-
USER_LIST="${{ secrets.ALLOWED_USERS }}"
148-
for user in $USER_LIST; do
149-
if [ "$GITHUB_ACTOR" == "$user" ]; then
150-
echo "User $GITHUB_ACTOR is allowed to deploy to prod"
151-
allowed=true
152-
break
153-
fi
154-
done
155-
156-
if [ "$allowed" != true ]; then
157-
echo "User $GITHUB_ACTOR is NOT allowed to deploy to prod"
158-
exit 1
159-
fi
160-
161162
- name: Configure AWS credentials
162163
uses: aws-actions/configure-aws-credentials@v4
163164
with:
@@ -194,5 +195,13 @@ jobs:
194195
- name: Deployment summary
195196
run: |
196197
{
197-
echo "### prod is deployed by $GITHUB_ACTOR from $GITHUB_REPOSITORY/$GITHUB_SHA"
198+
echo "### Deployment Summary"
199+
echo ""
200+
echo "| Key | Value |"
201+
echo "|------------------|-------|"
202+
echo "| deployment_env | ${{ inputs.deployment_env }} |"
203+
echo "| repository | $GITHUB_REPOSITORY |"
204+
echo "| actor | $GITHUB_ACTOR |"
205+
echo "| commit | $GITHUB_SHA |"
206+
echo "| Public URL | https://${{ inputs.url_staging }}/preview |"
198207
} >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)