File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments