Skip to content

Commit 60c9eee

Browse files
authored
Improve test worker check creation (#22063)
1 parent 5844ac3 commit 60c9eee

File tree

1 file changed

+36
-53
lines changed

1 file changed

+36
-53
lines changed

.github/workflows/zz-test-worker-poc.yaml

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,14 @@ on:
1313
type: string
1414

1515
jobs:
16-
create-check-run:
16+
setup:
1717
runs-on: ubuntu-latest
1818
permissions:
1919
id-token: write
2020
contents: read
21-
outputs:
22-
check_run_id: ${{ steps.create_check.outputs.result }}
23-
steps:
24-
- name: Get GitHub token via dd-octo-sts
25-
uses: DataDog/dd-octo-sts-action@08f2144903ced3254a3dafec2592563409ba2aa0
26-
id: octo-sts
27-
with:
28-
scope: DataDog/integrations-core
29-
policy: self.test-worker-poc
30-
31-
- name: Create Check Run
32-
id: create_check
33-
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
34-
with:
35-
github-token: ${{ steps.octo-sts.outputs.token }}
36-
script: |
37-
const response = await github.rest.checks.create({
38-
owner: context.repo.owner,
39-
repo: context.repo.repo,
40-
name: 'Test Worker POC',
41-
head_sha: '${{ inputs.ref }}',
42-
status: 'in_progress',
43-
details_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
44-
output: {
45-
title: 'Test Worker POC Running',
46-
summary: 'The test worker POC workflow is currently running.'
47-
}
48-
});
49-
return response.data.id;
50-
51-
setup:
52-
needs: create-check-run
53-
runs-on: ubuntu-latest
5421
outputs:
5522
work_matrix: ${{ steps.set_matrix.outputs.work_matrix }}
23+
token: ${{ steps.octo-sts.outputs.token }}
5624

5725
steps:
5826
- name: Check out repository
@@ -65,6 +33,13 @@ jobs:
6533
with:
6634
python-version: '3.13'
6735

36+
- name: Get GitHub token via dd-octo-sts
37+
uses: DataDog/dd-octo-sts-action@08f2144903ced3254a3dafec2592563409ba2aa0
38+
id: octo-sts
39+
with:
40+
scope: DataDog/integrations-core
41+
policy: self.test-worker-poc
42+
6843
- name: Parse matrix and set matrix output
6944
id: set_matrix
7045
run: |
@@ -94,36 +69,43 @@ jobs:
9469
with:
9570
ref: ${{ inputs.ref }}
9671

72+
- name: Create Check Run
73+
id: create_check
74+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
75+
with:
76+
github-token: ${{ needs.setup.outputs.token }}
77+
script: |
78+
const response = await github.rest.checks.create({
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
name: 'Test Worker POC Test - ${{ matrix.name }}',
82+
head_sha: '${{ inputs.ref }}',
83+
status: 'in_progress',
84+
details_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
85+
output: {
86+
title: 'Test Worker POC Test - ${{ matrix.name }}',
87+
summary: 'Test Worker POC Test - ${{ matrix.name }} is currently running.'
88+
}
89+
});
90+
return response.data.id;
91+
9792
- name: Run Generic Task
93+
id: run_task
9894
run: |
9995
echo "Running generic logic for job: ${{ matrix.name }}"
10096
echo "Platform: ${{ matrix.platform }}"
10197
echo "Runner: ${{ matrix.runner }}"
10298
echo "Target: ${{ matrix.target }}"
10399
echo "Git SHA: $(git rev-parse HEAD)"
104100
105-
complete-check-run:
106-
runs-on: ubuntu-latest
107-
if: always()
108-
needs: [create-check-run, run_work]
109-
permissions:
110-
id-token: write
111-
contents: read
112-
steps:
113-
- name: Get GitHub token via dd-octo-sts
114-
uses: DataDog/dd-octo-sts-action@08f2144903ced3254a3dafec2592563409ba2aa0
115-
id: octo-sts
116-
with:
117-
scope: DataDog/integrations-core
118-
policy: self.test-worker-poc
119-
120101
- name: Complete Check Run
102+
if: always()
121103
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
122104
with:
123-
github-token: ${{ steps.octo-sts.outputs.token }}
105+
github-token: ${{ needs.setup.outputs.token }}
124106
script: |
125-
const check_run_id = ${{ needs.create-check-run.outputs.check_run_id }};
126-
const conclusion = '${{ needs.run_work.result }}';
107+
const check_run_id = ${{ steps.create_check.outputs.result }};
108+
const conclusion = '${{ steps.run_task.outcome }}'; // Outcome of the specific task
127109
128110
// Map actions conclusion to check run conclusion
129111
// https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#update-a-check-run
@@ -144,8 +126,9 @@ jobs:
144126
check_run_id: check_run_id,
145127
status: 'completed',
146128
conclusion: checkConclusion,
129+
details_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
147130
output: {
148-
title: 'Test Worker POC Completed',
131+
title: 'Test Worker POC Test - ${{ matrix.name }} Completed',
149132
summary: `The workflow completed with status: ${conclusion}`
150133
}
151134
});

0 commit comments

Comments
 (0)