Skip to content

Commit a47d75e

Browse files
authored
CI: fix review assignment GH action (prebid#14346)
* pr assignment split * add checkout * add output * pass PR number * fix prNo * add missing fs import * Add more missing imports * add ref: master * fix quoting * fix quoting, again * add condition on triggering workflow
1 parent e1796eb commit a47d75e

5 files changed

Lines changed: 115 additions & 50 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Unzip artifact
2+
description: Download and unzip artifact from a triggering workflow
3+
inputs:
4+
name:
5+
description: Artifact name
6+
outputs:
7+
exists:
8+
description: true if the artifact was found
9+
value: ${{ steps.download.outputs.result }}
10+
11+
runs:
12+
using: 'composite'
13+
steps:
14+
- name: 'Download artifact'
15+
id: download
16+
uses: actions/github-script@v8
17+
with:
18+
result-encoding: string
19+
script: |
20+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
run_id: context.payload.workflow_run.id,
24+
});
25+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
26+
return artifact.name == "${{ inputs.name }}"
27+
})[0];
28+
if (matchArtifact == null) {
29+
return "false"
30+
}
31+
let download = await github.rest.actions.downloadArtifact({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
artifact_id: matchArtifact.id,
35+
archive_format: 'zip',
36+
});
37+
const fs = require('fs');
38+
const path = require('path');
39+
const temp = '${{ runner.temp }}/artifacts';
40+
if (!fs.existsSync(temp)){
41+
fs.mkdirSync(temp);
42+
}
43+
fs.writeFileSync(path.join(temp, 'artifact.zip'), Buffer.from(download.data));
44+
return "true";
45+
46+
- name: 'Unzip artifact'
47+
shell: bash
48+
if: ${{ steps.download.outputs.result == 'true' }}
49+
run: unzip "${{ runner.temp }}/artifacts/artifact.zip" -d "${{ runner.temp }}/artifacts"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Compile dependencies.json for PR assignment checks
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
permissions:
6+
contents: read
7+
jobs:
8+
generate_deps:
9+
name: Generate dependencies.json
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v6
15+
with:
16+
ref: refs/pull/${{ github.event.pull_request.number }}/head
17+
- name: Install dependencies
18+
uses: ./.github/actions/npm-ci
19+
- name: Build
20+
run: |
21+
npx gulp build
22+
- name: Upload dependencies.json
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: dependencies.json
26+
path: ./build/dist/dependencies.json
27+
- name: Generate PR info
28+
run: |
29+
echo '{ "prNo": ${{ github.event.pull_request.number }} }' >> ${{ runner.temp}}/prInfo.json
30+
- name: Upload PR info
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: prInfo
34+
path: ${{ runner.temp}}/prInfo.json

.github/workflows/PR-assignment.yml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
name: Assign PR reviewers
22
on:
3-
pull_request_target:
4-
types: [opened, synchronize, reopened]
5-
3+
workflow_run:
4+
workflows:
5+
- Compile dependencies.json for PR assignment checks
6+
types:
7+
- completed
68
jobs:
79
assign_reviewers:
10+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
811
name: Assign reviewers
912
runs-on: ubuntu-latest
1013

1114
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v6
17+
with:
18+
ref: master
1219
- name: Generate app token
1320
id: token
1421
uses: actions/create-github-app-token@v2
1522
with:
1623
app-id: ${{ vars.PR_BOT_ID }}
1724
private-key: ${{ secrets.PR_BOT_PEM }}
18-
19-
- name: Checkout
20-
uses: actions/checkout@v6
25+
- name: Download dependencies.json
26+
uses: ./.github/actions/unzip-artifact
2127
with:
22-
ref: refs/pull/${{ github.event.pull_request.number }}/head
23-
24-
- name: Install dependencies
25-
uses: ./.github/actions/npm-ci
26-
- name: Build
27-
run: |
28-
npx gulp build
28+
name: dependencies.json
29+
- name: Download PR info
30+
uses: ./.github/actions/unzip-artifact
31+
with:
32+
name: prInfo
2933
- name: Install s3 client
3034
run: |
3135
npm install @aws-sdk/client-s3
@@ -35,14 +39,17 @@ jobs:
3539
env:
3640
AWS_ACCESS_KEY_ID: ${{ vars.PR_BOT_AWS_AK }}
3741
AWS_SECRET_ACCESS_KEY: ${{ secrets.PR_BOT_AWS_SAK }}
42+
DEPENDENCIES_JSON: ${{ runner.temp }}/artifacts/dependencies.json
3843
with:
3944
github-token: ${{ steps.token.outputs.token }}
4045
script: |
46+
const fs = require('fs');
4147
const getProps = require('./.github/workflows/scripts/getPRProperties.js')
48+
const { prNo } = JSON.parse(fs.readFileSync('${{runner.temp}}/artifacts/prInfo.json').toString());
4249
const props = await getProps({
4350
github,
4451
context,
45-
prNo: ${{ github.event.pull_request.number }},
52+
prNo,
4653
reviewerTeam: '${{ vars.REVIEWER_TEAM }}',
4754
engTeam: '${{ vars.ENG_TEAM }}',
4855
authReviewTeam: '${{ vars.AUTH_REVIEWER_TEAM }}'

.github/workflows/comment.yml

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,18 @@ jobs:
1616
comment:
1717
runs-on: ubuntu-latest
1818
steps:
19-
- name: 'Download artifact'
20-
id: download
21-
uses: actions/github-script@v8
19+
- name: Checkout
20+
uses: actions/checkout@v6
2221
with:
23-
result-encoding: string
24-
script: |
25-
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
26-
owner: context.repo.owner,
27-
repo: context.repo.repo,
28-
run_id: context.payload.workflow_run.id,
29-
});
30-
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
31-
return artifact.name == "comment"
32-
})[0];
33-
if (matchArtifact == null) {
34-
return "false"
35-
}
36-
let download = await github.rest.actions.downloadArtifact({
37-
owner: context.repo.owner,
38-
repo: context.repo.repo,
39-
artifact_id: matchArtifact.id,
40-
archive_format: 'zip',
41-
});
42-
const fs = require('fs');
43-
const path = require('path');
44-
const temp = '${{ runner.temp }}/artifacts';
45-
if (!fs.existsSync(temp)){
46-
fs.mkdirSync(temp);
47-
}
48-
fs.writeFileSync(path.join(temp, 'comment.zip'), Buffer.from(download.data));
49-
return "true";
50-
51-
- name: 'Unzip artifact'
52-
if: ${{ steps.download.outputs.result == 'true' }}
53-
run: unzip "${{ runner.temp }}/artifacts/comment.zip" -d "${{ runner.temp }}/artifacts"
22+
ref: master
23+
- name: Retrieve comment data
24+
id: get-comment
25+
uses: ./.github/actions/unzip-artifact
26+
with:
27+
name: comment
5428

5529
- name: 'Comment on PR'
56-
if: ${{ steps.download.outputs.result == 'true' }}
30+
if: ${{ steps.get-comment.outputs.exists == 'true' }}
5731
uses: actions/github-script@v8
5832
with:
5933
script: |

.github/workflows/scripts/getPRProperties.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const ghRequester = require('./ghRequest.js');
22
const AWS = require("@aws-sdk/client-s3");
3+
const fs = require('fs');
34

45
const MODULE_PATTERNS = [
56
/^modules\/([^\/]+)BidAdapter(\.(\w+)|\/)/,
@@ -25,7 +26,7 @@ function extractVendor(chunkName) {
2526
}
2627

2728
const getLibraryRefs = (() => {
28-
const deps = require('../../../build/dist/dependencies.json');
29+
const deps = JSON.parse(fs.readFileSync(process.env.DEPENDENCIES_JSON).toString());
2930
const refs = {};
3031
return function (libraryName) {
3132
if (!refs.hasOwnProperty(libraryName)) {

0 commit comments

Comments
 (0)