1+ name : Publish Review Event
2+
3+ on :
4+ workflow_run :
5+ workflows : ["Store_Review_Event"]
6+ types :
7+ - completed
8+ permissions : read-all
9+
10+ jobs :
11+ fetch_and_process :
12+ runs-on : ubuntu-latest
13+ steps :
14+ - name : ' Download artifact'
15+ uses : actions/github-script@v6
16+ with :
17+ script : |
18+ let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
19+ owner: context.repo.owner,
20+ repo: context.repo.repo,
21+ run_id: context.payload.workflow_run.id,
22+ });
23+ let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
24+ return artifact.name == "eventjson"
25+ })[0];
26+ let download = await github.rest.actions.downloadArtifact({
27+ owner: context.repo.owner,
28+ repo: context.repo.repo,
29+ artifact_id: matchArtifact.id,
30+ archive_format: 'zip',
31+ });
32+ let fs = require('fs');
33+ fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/eventjson.zip`, Buffer.from(download.data));
34+
35+ - name : ' Unzip artifact'
36+ run : |
37+ ls
38+ unzip eventjson.zip
39+
40+ - name : Get Token
41+ run : |
42+ retries=3
43+ while [ $retries -gt 0 ]; do
44+ if RESPONSE=$(curl --silent --location "${{ secrets.CLIENT_TOKEN_URL }}" \
45+ --header 'Content-Type: application/x-www-form-urlencoded' \
46+ --data-urlencode "client_id=${{ secrets.CLIENT_ID }}" \
47+ --data-urlencode "client_secret=${{ secrets.CLIENT_SECRET }}" \
48+ --data-urlencode 'grant_type=client_credentials'); then
49+ TOKEN=$(echo "$RESPONSE" | jq -r '.access_token')
50+ if [ -n "$TOKEN" ]; then
51+ echo "TOKEN=$TOKEN" >> $GITHUB_ENV
52+ break
53+ else
54+ echo "Error: Failed to parse access token from response"
55+ fi
56+ else
57+ echo "Error: Request to get token failed"
58+ fi
59+ retries=$((retries-1))
60+ sleep 1
61+ done
62+
63+ if [ $retries -eq 0 ]; then
64+ echo "Error: Failed to retrieve access token after multiple retries"
65+ exit 1
66+ fi
67+
68+
69+
70+ - name : Trigger Build with Event
71+ if : success()
72+ env :
73+ TOKEN : ${{ env.TOKEN }}
74+ run : |
75+
76+ EVENT_DATA=$(cat event.json)
77+
78+ retries=3
79+ while [ $retries -gt 0 ]; do
80+ if curl --silent --location --request POST "${{ secrets.CLIENT_PUBLISH_URL }}" \
81+ --header 'Content-Type: application/json' \
82+ --header 'x-github-event: github' \
83+ --header "Authorization: Bearer $TOKEN" \
84+ --data "$EVENT_DATA"; then
85+ break
86+ else
87+ echo "Error: Failed to trigger build"
88+ fi
89+ retries=$((retries-1))
90+ sleep 1
91+ done
92+
93+ if [ $retries -eq 0 ]; then
94+ echo "Error: Failed to trigger build after multiple retries"
95+ exit 1
96+ fi
0 commit comments