Skip to content

Commit 3f2ab60

Browse files
authored
[CI] Update comment trigger tests with improved workflow design (#1103)
* Improved workflow runs on the PR commit instead of the main commit, and reports results to the PR with comments and status updates. * Based on: https://dev.to/zirkelc/trigger-github-workflow-for-comment-on-pull-request-45l2
1 parent d45126c commit 3f2ab60

5 files changed

+206
-82
lines changed
Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
name: Run ITensorGaussianMPS tests from comment trigger
22

33
on:
4-
pull_request:
5-
types: [opened]
64
issue_comment:
75
types: [created]
86

97
jobs:
108
test:
119
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ matrix.threads }} thread(s)
10+
if: github.event.issue.pull_request && contains(github.event.comment.body, '[test ITensorGaussianMPS]')
1211
runs-on: ${{ matrix.os }}
1312
env:
1413
JULIA_NUM_THREADS: ${{ matrix.threads }}
@@ -20,32 +19,59 @@ jobs:
2019
os:
2120
- ubuntu-latest
2221
threads:
23-
- '1'
22+
- '2'
2423
arch:
2524
- x64
2625
steps:
27-
- name: Pull Request Comment Trigger
28-
uses: Khan/[email protected]
29-
id: check
26+
- name: Get PR branch
27+
uses: xt0rted/pull-request-comment-branch@v1
28+
id: comment-branch
29+
- name: Set latest commit status as pending
30+
uses: myrotvorets/set-commit-status-action@master
31+
with:
32+
sha: ${{ steps.comment-branch.outputs.head_sha }}
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
status: pending
35+
- name: Checkout PR branch
36+
uses: actions/checkout@v3
3037
with:
31-
trigger: '[gaussianmps]'
32-
reaction: rocket
33-
env:
34-
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
35-
- uses: actions/checkout@v2
36-
if: steps.check.outputs.triggered == 'true'
38+
ref: ${{ steps.comment-branch.outputs.head_ref }}
39+
- name: Setup Node.js 16
40+
uses: actions/setup-node@v3
41+
with:
42+
node-version: 16
3743
- uses: julia-actions/setup-julia@latest
3844
with:
3945
version: ${{ matrix.version }}
4046
arch: ${{ matrix.arch }}
41-
if: steps.check.outputs.triggered == 'true'
4247
- name: Install Julia dependencies
4348
shell: julia --project=monorepo {0}
4449
run: |
4550
using Pkg;
4651
pkg"dev ./NDTensors . ./ITensorGaussianMPS"
47-
if: steps.check.outputs.triggered == 'true'
4852
- name: Run the tests
49-
run: >
53+
run: |
5054
julia --project=monorepo --depwarn=yes -e 'using Pkg; Pkg.test("ITensorGaussianMPS")'
51-
if: steps.check.outputs.triggered == 'true'
55+
- name: Set latest commit status as ${{ job.status }}
56+
uses: myrotvorets/set-commit-status-action@master
57+
if: always()
58+
with:
59+
sha: ${{ steps.comment-branch.outputs.head_sha }}
60+
token: ${{ secrets.GITHUB_TOKEN }}
61+
status: ${{ job.status }}
62+
- name: Add comment to PR
63+
uses: actions/github-script@v6
64+
if: always()
65+
with:
66+
script: |
67+
const name = '${{ github.workflow }}';
68+
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
69+
const success = '${{ job.status }}' === 'success';
70+
const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`;
71+
72+
await github.rest.issues.createComment({
73+
issue_number: context.issue.number,
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
body: body
77+
})
Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
name: Run ITensorGLMakie tests from comment trigger
22

33
on:
4-
pull_request:
5-
types: [opened]
64
issue_comment:
75
types: [created]
86

97
jobs:
108
test:
119
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ matrix.threads }} thread(s)
10+
if: github.event.issue.pull_request && contains(github.event.comment.body, '[test ITensorGLMakie]')
1211
runs-on: ${{ matrix.os }}
1312
env:
1413
JULIA_NUM_THREADS: ${{ matrix.threads }}
@@ -20,25 +19,31 @@ jobs:
2019
os:
2120
- ubuntu-20.04 # Needed for proper CI installation?
2221
threads:
23-
- '1'
22+
- '2'
2423
arch:
2524
- x64
2625
steps:
27-
- name: Pull Request Comment Trigger
28-
uses: Khan/[email protected]
29-
id: check
26+
- name: Get PR branch
27+
uses: xt0rted/pull-request-comment-branch@v1
28+
id: comment-branch
29+
- name: Set latest commit status as pending
30+
uses: myrotvorets/set-commit-status-action@master
3031
with:
31-
trigger: '[glmakie]'
32-
reaction: rocket
33-
env:
34-
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
35-
- uses: actions/checkout@v2
36-
if: steps.check.outputs.triggered == 'true'
32+
sha: ${{ steps.comment-branch.outputs.head_sha }}
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
status: pending
35+
- name: Checkout PR branch
36+
uses: actions/checkout@v3
37+
with:
38+
ref: ${{ steps.comment-branch.outputs.head_ref }}
39+
- name: Setup Node.js 16
40+
uses: actions/setup-node@v3
41+
with:
42+
node-version: 16
3743
- uses: julia-actions/setup-julia@latest
3844
with:
3945
version: ${{ matrix.version }}
4046
arch: ${{ matrix.arch }}
41-
if: steps.check.outputs.triggered == 'true'
4247
- uses: actions/cache@v1
4348
env:
4449
cache-name: cache-artifacts
@@ -49,16 +54,35 @@ jobs:
4954
${{ runner.os }}-test-${{ env.cache-name }}-
5055
${{ runner.os }}-test-
5156
${{ runner.os }}-
52-
if: steps.check.outputs.triggered == 'true'
5357
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev
54-
if: steps.check.outputs.triggered == 'true'
5558
- name: Install Julia dependencies
5659
shell: julia --project=monorepo {0}
5760
run: |
5861
using Pkg;
5962
pkg"dev ./NDTensors . ./ITensorVisualizationBase ./ITensorMakie ./ITensorGLMakie"
60-
if: steps.check.outputs.triggered == 'true'
6163
- name: Run the tests
6264
run: |
6365
DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=monorepo --depwarn=yes -e 'using Pkg; Pkg.test("ITensorGLMakie")'
64-
if: steps.check.outputs.triggered == 'true'
66+
- name: Set latest commit status as ${{ job.status }}
67+
uses: myrotvorets/set-commit-status-action@master
68+
if: always()
69+
with:
70+
sha: ${{ steps.comment-branch.outputs.head_sha }}
71+
token: ${{ secrets.GITHUB_TOKEN }}
72+
status: ${{ job.status }}
73+
- name: Add comment to PR
74+
uses: actions/github-script@v6
75+
if: always()
76+
with:
77+
script: |
78+
const name = '${{ github.workflow }}';
79+
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
80+
const success = '${{ job.status }}' === 'success';
81+
const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`;
82+
83+
await github.rest.issues.createComment({
84+
issue_number: context.issue.number,
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
body: body
88+
})
Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
name: Run ITensors mps tests from comment trigger
22

33
on:
4-
pull_request:
5-
types: [opened]
64
issue_comment:
75
types: [created]
86

97
jobs:
108
test:
119
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ matrix.threads }} thread(s)
10+
if: github.event.issue.pull_request && contains(github.event.comment.body, '[test ITensors mps]')
1211
runs-on: ${{ matrix.os }}
1312
env:
1413
JULIA_NUM_THREADS: ${{ matrix.threads }}
@@ -23,39 +22,62 @@ jobs:
2322
- '2'
2423
arch:
2524
- x64
26-
exclude:
27-
# MacOS not available on x86
28-
- {os: 'macOS-latest', arch: 'x86'}
2925
steps:
30-
- name: Pull Request Comment Trigger
31-
uses: Khan/[email protected]
32-
id: check
26+
- name: Get PR branch
27+
uses: xt0rted/pull-request-comment-branch@v1
28+
id: comment-branch
29+
- name: Set latest commit status as pending
30+
uses: myrotvorets/set-commit-status-action@master
3331
with:
34-
trigger: '[mps]'
35-
reaction: rocket
36-
env:
37-
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
38-
- uses: actions/checkout@v2
39-
if: steps.check.outputs.triggered == 'true'
32+
sha: ${{ steps.comment-branch.outputs.head_sha }}
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
status: pending
35+
- name: Checkout PR branch
36+
uses: actions/checkout@v3
37+
with:
38+
ref: ${{ steps.comment-branch.outputs.head_ref }}
39+
- name: Setup Node.js 16
40+
uses: actions/setup-node@v3
41+
with:
42+
node-version: 16
4043
- uses: julia-actions/setup-julia@latest
4144
with:
4245
version: ${{ matrix.version }}
4346
arch: ${{ matrix.arch }}
44-
if: steps.check.outputs.triggered == 'true'
4547
- name: Install Julia dependencies
4648
shell: julia --project=monorepo {0}
4749
run: |
4850
using Pkg;
4951
pkg"dev ./NDTensors ."
50-
if: steps.check.outputs.triggered == 'true'
5152
- name: Run the tests
5253
shell: julia --project=monorepo {0}
5354
run: |
5455
using Pkg;
5556
# https://github.com/JuliaLang/Pkg.jl/pull/1226
5657
Pkg.test("ITensors"; coverage=true, test_args=["mps"])
57-
if: steps.check.outputs.triggered == 'true'
5858
- uses: julia-actions/julia-uploadcodecov@latest
5959
env:
6060
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
61-
if: steps.check.outputs.triggered == 'true'
61+
- name: Set latest commit status as ${{ job.status }}
62+
uses: myrotvorets/set-commit-status-action@master
63+
if: always()
64+
with:
65+
sha: ${{ steps.comment-branch.outputs.head_sha }}
66+
token: ${{ secrets.GITHUB_TOKEN }}
67+
status: ${{ job.status }}
68+
- name: Add comment to PR
69+
uses: actions/github-script@v6
70+
if: always()
71+
with:
72+
script: |
73+
const name = '${{ github.workflow }}';
74+
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
75+
const success = '${{ job.status }}' === 'success';
76+
const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`;
77+
78+
await github.rest.issues.createComment({
79+
issue_number: context.issue.number,
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
body: body
83+
})
Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
name: Run ITensorUnicodePlots tests from comment trigger
22

33
on:
4-
pull_request:
5-
types: [opened]
64
issue_comment:
75
types: [created]
86

97
jobs:
108
test:
119
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ matrix.threads }} thread(s)
10+
if: github.event.issue.pull_request && contains(github.event.comment.body, '[test ITensorUnicodePlots]')
1211
runs-on: ${{ matrix.os }}
1312
env:
1413
JULIA_NUM_THREADS: ${{ matrix.threads }}
@@ -20,32 +19,59 @@ jobs:
2019
os:
2120
- ubuntu-latest
2221
threads:
23-
- '1'
22+
- '2'
2423
arch:
2524
- x64
2625
steps:
27-
- name: Pull Request Comment Trigger
28-
uses: Khan/[email protected]
29-
id: check
26+
- name: Get PR branch
27+
uses: xt0rted/pull-request-comment-branch@v1
28+
id: comment-branch
29+
- name: Set latest commit status as pending
30+
uses: myrotvorets/set-commit-status-action@master
31+
with:
32+
sha: ${{ steps.comment-branch.outputs.head_sha }}
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
status: pending
35+
- name: Checkout PR branch
36+
uses: actions/checkout@v3
3037
with:
31-
trigger: '[unicodeplots]'
32-
reaction: rocket
33-
env:
34-
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
35-
- uses: actions/checkout@v2
36-
if: steps.check.outputs.triggered == 'true'
38+
ref: ${{ steps.comment-branch.outputs.head_ref }}
39+
- name: Setup Node.js 16
40+
uses: actions/setup-node@v3
41+
with:
42+
node-version: 16
3743
- uses: julia-actions/setup-julia@latest
3844
with:
3945
version: ${{ matrix.version }}
4046
arch: ${{ matrix.arch }}
41-
if: steps.check.outputs.triggered == 'true'
4247
- name: Install Julia dependencies
4348
shell: julia --project=monorepo {0}
4449
run: |
4550
using Pkg;
4651
pkg"dev ./NDTensors . ./ITensorVisualizationBase ./ITensorUnicodePlots"
47-
if: steps.check.outputs.triggered == 'true'
4852
- name: Run the tests
49-
run: >
53+
run: |
5054
julia --project=monorepo --depwarn=yes -e 'using Pkg; Pkg.test("ITensorUnicodePlots")'
51-
if: steps.check.outputs.triggered == 'true'
55+
- name: Set latest commit status as ${{ job.status }}
56+
uses: myrotvorets/set-commit-status-action@master
57+
if: always()
58+
with:
59+
sha: ${{ steps.comment-branch.outputs.head_sha }}
60+
token: ${{ secrets.GITHUB_TOKEN }}
61+
status: ${{ job.status }}
62+
- name: Add comment to PR
63+
uses: actions/github-script@v6
64+
if: always()
65+
with:
66+
script: |
67+
const name = '${{ github.workflow }}';
68+
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
69+
const success = '${{ job.status }}' === 'success';
70+
const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`;
71+
72+
await github.rest.issues.createComment({
73+
issue_number: context.issue.number,
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
body: body
77+
})

0 commit comments

Comments
 (0)