Skip to content

Commit 1a655c4

Browse files
author
celadon
committed
Added github workflows to capture events for CI
Signed-off-by: Shweta Joshi <shweta.joshi@intel.com>
1 parent 296cc77 commit 1a655c4

File tree

3 files changed

+182
-0
lines changed

3 files changed

+182
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CI Workflow
2+
3+
on:
4+
pull_request_target:
5+
types: "*"
6+
branches: "**"
7+
permissions: read-all
8+
9+
jobs:
10+
Trigger_Workflows:
11+
runs-on: ubuntu-latest
12+
name: CI Workflow
13+
steps:
14+
- name: Get Token
15+
run: |
16+
retries=3
17+
while [ $retries -gt 0 ]; do
18+
if RESPONSE=$(curl --silent --location "${{ secrets.CLIENT_TOKEN_URL }}" \
19+
--header 'Content-Type: application/x-www-form-urlencoded' \
20+
--data-urlencode "client_id=${{ secrets.CLIENT_ID }}" \
21+
--data-urlencode "client_secret=${{ secrets.CLIENT_SECRET }}" \
22+
--data-urlencode 'grant_type=client_credentials'); then
23+
TOKEN=$(echo "$RESPONSE" | jq -r '.access_token')
24+
if [ -n "$TOKEN" ]; then
25+
echo "TOKEN=$TOKEN" >> $GITHUB_ENV
26+
break
27+
else
28+
echo "Error: Failed to parse access token from response"
29+
fi
30+
else
31+
echo "Error: Request to get token failed"
32+
fi
33+
retries=$((retries-1))
34+
sleep 1
35+
done
36+
37+
if [ $retries -eq 0 ]; then
38+
echo "Error: Failed to retrieve access token after multiple retries"
39+
exit 1
40+
fi
41+
42+
43+
44+
- name: Trigger Build with Event
45+
if: success()
46+
env:
47+
TOKEN: ${{ env.TOKEN }}
48+
run: |
49+
EVENT_DATA='${{ toJSON(github.event_path) }}'
50+
retries=3
51+
while [ $retries -gt 0 ]; do
52+
if curl --silent --location --request POST "${{ secrets.CLIENT_PUBLISH_URL }}" \
53+
--header 'Content-Type: application/json' \
54+
--header 'x-github-event: github' \
55+
--header "Authorization: Bearer $TOKEN" \
56+
--data "@${{ github.event_path }}"; then
57+
break
58+
else
59+
echo "Error: Failed to trigger build"
60+
fi
61+
retries=$((retries-1))
62+
sleep 1
63+
done
64+
65+
if [ $retries -eq 0 ]; then
66+
echo "Error: Failed to trigger build after multiple retries"
67+
exit 1
68+
fi
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Store_Review_Event
2+
3+
on:
4+
pull_request_review:
5+
types: "**"
6+
permissions: read-all
7+
8+
jobs:
9+
Store_Review_Event:
10+
runs-on: ubuntu-latest
11+
name: Store Review Event
12+
steps:
13+
- name: Upload event JSON as artifact
14+
uses: actions/upload-artifact@v4
15+
with:
16+
name: eventjson
17+
path: "${{ github.event_path }}"
18+
retention-days: 7

0 commit comments

Comments
 (0)