Skip to content

Commit 1ba2986

Browse files
authored
add Breakage (#14)
1 parent 0298d66 commit 1ba2986

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed

.github/workflows/Breakage.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Ref: https://securitylab.github.com/research/github-actions-preventing-pwn-requests
2+
name: Breakage
3+
4+
# read-only repo token
5+
# no access to secrets
6+
on:
7+
pull_request:
8+
9+
jobs:
10+
break:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
pkg: [
16+
"cscherrer/MeasureTheory.jl",
17+
"cscherrer/Soss.jl",
18+
"mschauer/Mitosis.jl"
19+
]
20+
pkgversion: [latest, stable]
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
# Install Julia
26+
- uses: julia-actions/setup-julia@v1
27+
with:
28+
version: 1
29+
arch: x64
30+
- uses: actions/cache@v1
31+
env:
32+
cache-name: cache-artifacts
33+
with:
34+
path: ~/.julia/artifacts
35+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
36+
restore-keys: |
37+
${{ runner.os }}-test-${{ env.cache-name }}-
38+
${{ runner.os }}-test-
39+
${{ runner.os }}-
40+
- uses: julia-actions/julia-buildpkg@v1
41+
42+
# Breakage test
43+
- name: 'Breakage of ${{ matrix.pkg }}, ${{ matrix.pkgversion }} version'
44+
env:
45+
URL: ${{ matrix.pkg }}
46+
VERSION: ${{ matrix.pkgversion }}
47+
run: |
48+
set -v
49+
mkdir -p ./pr
50+
echo "${{ github.event.number }}" > ./pr/NR
51+
git clone https://github.com/$URL
52+
export PKG=$(echo $URL | cut -f2 -d/)
53+
cd $PKG
54+
if [ $VERSION == "stable" ]; then
55+
TAG=$(git tag -l "v*" --sort=-creatordate | head -n1)
56+
if [ -z "$TAG" ]; then
57+
TAG="no_tag"
58+
else
59+
git checkout $TAG
60+
fi
61+
else
62+
TAG=$VERSION
63+
fi
64+
export TAG
65+
julia -e 'using Pkg;
66+
PKG, TAG, VERSION = ENV["PKG"], ENV["TAG"], ENV["VERSION"]
67+
joburl = joinpath(ENV["GITHUB_SERVER_URL"], ENV["GITHUB_REPOSITORY"], "actions/runs", ENV["GITHUB_RUN_ID"])
68+
open("../pr/$PKG-$VERSION", "w") do io
69+
try
70+
TAG == "no_tag" && error("Not tag for $VERSION")
71+
pkg"activate .";
72+
pkg"instantiate";
73+
pkg"dev ../";
74+
pkg"build";
75+
pkg"test";
76+
77+
print(io, "[![](https://img.shields.io/badge/$TAG-Pass-green)]($joburl)");
78+
catch e
79+
@error e;
80+
print(io, "[![](https://img.shields.io/badge/$TAG-Fail-red)]($joburl)");
81+
end;
82+
end'
83+
84+
- uses: actions/upload-artifact@v2
85+
with:
86+
name: pr
87+
path: pr/
88+
89+
upload:
90+
needs: break
91+
runs-on: ubuntu-latest
92+
steps:
93+
- uses: actions/checkout@v2
94+
95+
- uses: actions/download-artifact@v2
96+
with:
97+
name: pr
98+
path: pr/
99+
100+
- run: ls
101+
- run: |
102+
cd pr
103+
echo "| Package name | latest | stable |" > MSG
104+
echo "|--|--|--|" >> MSG
105+
count=0
106+
for file in *
107+
do
108+
[ "$file" == "NR" ] && continue
109+
[ "$file" == "MSG" ] && continue
110+
if [ $count == "0" ]; then
111+
name=$(echo $file | cut -f1 -d-)
112+
echo -n "| $name | "
113+
else
114+
echo -n "| "
115+
fi
116+
cat $file
117+
if [ $count == "0" ]; then
118+
echo -n " "
119+
count=1
120+
else
121+
echo " |"
122+
count=0
123+
fi
124+
done >> MSG
125+
126+
- uses: actions/upload-artifact@v2
127+
with:
128+
name: pr
129+
path: pr/

.github/workflows/CommentPR.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Ref: https://securitylab.github.com/research/github-actions-preventing-pwn-requests
2+
name: Comment on the pull request
3+
4+
# read-write repo token
5+
# access to secrets
6+
on:
7+
workflow_run:
8+
workflows: ["Breakage"]
9+
types:
10+
- completed
11+
12+
jobs:
13+
upload:
14+
runs-on: ubuntu-latest
15+
if: >
16+
${{ github.event.workflow_run.event == 'pull_request' &&
17+
github.event.workflow_run.conclusion == 'success' }}
18+
steps:
19+
- name: 'Download artifact'
20+
uses: actions/[email protected]
21+
with:
22+
script: |
23+
var artifacts = await github.actions.listWorkflowRunArtifacts({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
run_id: ${{github.event.workflow_run.id }},
27+
});
28+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
29+
return artifact.name == "pr"
30+
})[0];
31+
var download = await github.actions.downloadArtifact({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
artifact_id: matchArtifact.id,
35+
archive_format: 'zip',
36+
});
37+
var fs = require('fs');
38+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
39+
- run: unzip pr.zip
40+
41+
- name: 'Comment on PR'
42+
uses: actions/github-script@v3
43+
with:
44+
github-token: ${{ secrets.GITHUB_TOKEN }}
45+
script: |
46+
var fs = require('fs');
47+
var issue_number = Number(fs.readFileSync('./NR'));
48+
var msg = fs.readFileSync('./MSG', 'utf8');
49+
await github.issues.createComment({
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
issue_number: issue_number,
53+
body: msg
54+
});

0 commit comments

Comments
 (0)