Skip to content

Commit 7133ea7

Browse files
committed
Automatic PR
- update.yml file invokes update.jl on workflow_dispatch or on Sat 6 am utc - Peek in each dir in benchmarks - If there are any changes push it to "dir" branch - Create a PR (or update if one already exists)
1 parent 1ae8995 commit 7133ea7

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

.github/workflows/update.jl

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
using Pkg
2-
import Git
2+
Pkg.add(["Git", "GitHub", "Dates"])
3+
using Git, GitHub, Dates
34

4-
const git = Git.git()
5+
gh_token = ARGS[1]
6+
auth = GitHub.authenticate(gh_token)
57

8+
const git = Git.git()
9+
date = Dates.format(now(), "yyyy-mm-dd")
610
benchpath = joinpath(@__DIR__, "..", "..", "benchmarks")
711

12+
# Get all the open PRs and their number
13+
gh_prs = GitHub.pull_requests("SciML/SciMLBenchmarks"; auth=auth)
14+
prs = Dict{String, Int64}()
15+
for i in 1:length(gh_prs[1])
16+
prs[gh_prs[1][i].head.ref] = gh_prs[1][i].number
17+
end
18+
19+
# Get all the branches from the repo
20+
gh_branches = GitHub.branches("SciML/SciMLBenchmarks"; auth=auth)
21+
branches = [gh_branches[1][i].name for i in 1:length(gh_branches[1])]
22+
823
for dir in readdir(benchpath)
924
model_dir = joinpath(benchpath, dir)
1025
isdir(model_dir) || continue
@@ -15,9 +30,28 @@ for dir in readdir(benchpath)
1530
end
1631
manpath = (joinpath(benchpath, "Manifest.toml"))
1732
if length(readlines(`git status . --porcelain`)) > 1
18-
run(`git checkout -B $dir`)
19-
run(`$git add -A . :!$(manpath)`)
20-
run(`$git commit -m "Updated $(dir)"`)
21-
run(`$git push --set-upstream origin $(dir)`)
33+
if dir branches
34+
run(`git checkout -b $(dir) master`)
35+
run(`$git add -A . :!$(manpath)`)
36+
run(`$git commit -m "Updated $(dir) on $(date)"`)
37+
run(`$git push --set-upstream origin $(dir)`)
38+
else
39+
run(`$git fetch origin`)
40+
run(`$git checkout $(dir)`)
41+
run(`$git pull -Xours`)
42+
run(`$git add -A . :!$(manpath)`)
43+
run(`$git commit -m "Updated $(dir) on $(date)"`)
44+
run(`$git push`)
45+
end
46+
if dir keys(prs)
47+
params = Dict(
48+
"title" => "Updated $(dir) for benchmarks",
49+
"head" => "$(dir)",
50+
"base" => "master"
51+
)
52+
GitHub.create_pull_request("SciML/SciMLBenchmarks"; params=params, auth=auth)
53+
else
54+
GitHub.update_pull_request("SciML/SciMLBenchmarks", prs[dir]; auth=auth)
55+
end
2256
end
2357
end

.github/workflows/update.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: Weekly Update
22

33
on:
44
schedule:
5-
- cron: '0 */1 * * *'
5+
- cron: 0 6 * * 6
6+
workflow_dispatch:
67

78
jobs:
89
update_weekly:
@@ -14,8 +15,9 @@ jobs:
1415
uses: julia-actions/setup-julia@v1
1516
with:
1617
version: 1.6.0
17-
- run: |
18+
- name: Check for updates and create a PR
19+
run: |
1820
git config --local user.email "$(git log --format='%ae' HEAD^!)"
1921
git config --local user.name "$(git log --format='%an' HEAD^!)"
2022
21-
julia -e 'include("update.jl")'
23+
julia -e 'include("update.jl")' ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)