Skip to content

Commit 0eb698d

Browse files
authored
Started on recording who did an approval of a release (#13)
1 parent fdd677c commit 0eb698d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

.github/workflows/build-deploy-backend.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,43 @@ jobs:
124124
secrets: inherit
125125

126126

127+
get-approver-for-stage:
128+
runs-on: ubuntu-latest
129+
steps:
130+
- name: Get workflow run ID
131+
id: get-run-id
132+
run: echo "workflow_run_id=${{ github.run_id }}" >> $GITHUB_ENV
133+
134+
- name: Get approval actor from audit log
135+
id: get-approver
136+
env:
137+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
138+
OWNER: kosli-dev
139+
REPO: github-release-example
140+
WORKFLOW_RUN_ID: ${{ github.run_id }}
141+
run: |
142+
API_URL="https://api.github.com/orgs/${OWNER}/audit-log"
143+
TIMESTAMP_24H_AGO=$(date -u -d '1 day ago' +"%Y-%m-%dT%H:%M:%SZ")
144+
145+
curl -s -H "Authorization: Bearer ${GH_TOKEN}" \
146+
-H "Accept: application/vnd.github+json" \
147+
--get \
148+
--data-urlencode "phrase=repo:${OWNER}/${REPO}" \
149+
--data-urlencode "phrase=action:workflows.approve_workflow_job" \
150+
--data-urlencode "created_after=${TIMESTAMP_24H_AGO}" \
151+
"$API_URL" > audit.json
152+
153+
APPROVER=$(jq -r --arg run_id "$WORKFLOW_RUN_ID" '
154+
map(select(.workflow_run_id | tostring == $run_id))
155+
| sort_by(.created_at)
156+
| reverse
157+
| .[0].actor // "unknown"
158+
' audit.json)
159+
160+
echo "Approver: $APPROVER"
161+
echo "approver=$APPROVER" >> $GITHUB_OUTPUT
162+
163+
127164
semver-tag:
128165
needs: [build,deploy-stage]
129166
name: Check for semver tag

0 commit comments

Comments
 (0)