Skip to content

Commit dd99ed5

Browse files
[gha] Automatically add job link to PR description (#3453)
### Changes Add action `add_job_link` to add job link in the end of PR description Update workflow that can be run manually for PR ### Reason for changes Laziness
1 parent 6d0aacd commit dd99ed5

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: 'Add job link to PR description'
2+
inputs:
3+
pull_request_number:
4+
description: 'Pull Request number'
5+
required: true
6+
link_name:
7+
description: 'Name of link, should contain only alphanumeric characters, dashes, and underscores'
8+
required: true
9+
runs:
10+
using: "composite"
11+
steps:
12+
- name: Update PR description with preview link
13+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
14+
with:
15+
script: |
16+
const prNumber = parseInt(${{ inputs.pull_request_number }});
17+
const newLink = `https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}`;
18+
const newLine = `[${{ inputs.link_name }}](${newLink})`;
19+
20+
const { data: pr } = await github.rest.pulls.get({
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
pull_number: prNumber
24+
});
25+
26+
let body = pr.body || '';
27+
const regex = /\[${{ inputs.link_name }}\]\([^)]+\)/;
28+
29+
if (regex.test(body)) {
30+
body = body.replace(regex, newLine);
31+
} else {
32+
body = body.trim() + `\n\n${newLine}`;
33+
}
34+
35+
await github.rest.pulls.update({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
pull_number: prNumber,
39+
body
40+
});

.github/workflows/conformance_weight_compression.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,23 @@ jobs:
7171
run: |
7272
pip install defusedxml==0.7.1
7373
python .github/scripts/pytest_md_summary.py pytest-results.xml >> $GITHUB_STEP_SUMMARY
74+
75+
update-pr-description:
76+
name: Update PR description
77+
runs-on: ubuntu-22.04
78+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pull_request_number != '' }}
79+
permissions:
80+
contents: write
81+
pull-requests: write
82+
issues: write
83+
steps:
84+
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
85+
with:
86+
sparse-checkout: .github/actions/add_job_link
87+
- name: Update PR preview link
88+
uses: ./.github/actions/add_job_link
89+
with:
90+
pull_request_number: ${{ inputs.pull_request_number }}
91+
link_name: "Test_Weight_Compression"
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/examples.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,23 @@ jobs:
203203
run: |
204204
pip install defusedxml==0.7.1
205205
python .github/scripts/pytest_md_summary.py pytest-results.xml >> $GITHUB_STEP_SUMMARY
206+
207+
update-pr-description:
208+
name: Update PR description
209+
runs-on: ubuntu-22.04
210+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pull_request_number != '' }}
211+
permissions:
212+
contents: write
213+
pull-requests: write
214+
issues: write
215+
steps:
216+
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
217+
with:
218+
sparse-checkout: .github/actions/add_job_link
219+
- name: Update PR preview link
220+
uses: ./.github/actions/add_job_link
221+
with:
222+
pull_request_number: ${{ inputs.pull_request_number }}
223+
link_name: "Test_Examples"
224+
env:
225+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/install.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,23 @@ jobs:
9090
export PATH=/usr/local/cuda-12.4/bin${PATH:+:${PATH}}
9191
export LD_LIBRARY_PATH=/usr/local/cuda-12.4/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
9292
pytest tests/cross_fw/install -rA -s --host-configuration gpu --backend torch
93+
94+
update-pr-description:
95+
name: Update PR description
96+
runs-on: ubuntu-22.04
97+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pull_request_number != '' }}
98+
permissions:
99+
contents: write
100+
pull-requests: write
101+
issues: write
102+
steps:
103+
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
104+
with:
105+
sparse-checkout: .github/actions/add_job_link
106+
- name: Update PR preview link
107+
uses: ./.github/actions/add_job_link
108+
with:
109+
pull_request_number: ${{ inputs.pull_request_number }}
110+
link_name: "Test_Install"
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/macos.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,23 @@ jobs:
5959
run: pytest -ra tests/openvino
6060
env:
6161
ONEDNN_MAX_CPU_ISA: AVX2
62+
63+
update-pr-description:
64+
name: Update PR description
65+
runs-on: ubuntu-22.04
66+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pull_request_number != '' }}
67+
permissions:
68+
contents: write
69+
pull-requests: write
70+
issues: write
71+
steps:
72+
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
73+
with:
74+
sparse-checkout: .github/actions/add_job_link
75+
- name: Update PR preview link
76+
uses: ./.github/actions/add_job_link
77+
with:
78+
pull_request_number: ${{ inputs.pull_request_number }}
79+
link_name: "Test_MacOS"
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)