Skip to content

Commit 8cf3360

Browse files
committed
Automatically update all Manifest files
1 parent 5fd9f61 commit 8cf3360

File tree

12 files changed

+340
-19
lines changed

12 files changed

+340
-19
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
*.jl.cov
33
*.jl.mem
44
.DS_Store
5-
/Manifest.toml
5+
Manifest.toml
66
/dev/

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,38 @@ CompatHelper is now installed as a GitHub Action on your repository.
2828

2929

3030
## Actions Setup
31-
* Sign up for the beta of GitHub Actions from https://github.com/features/actions
31+
* Sign up for the beta of GitHub Actions from https://github.com/features/actions
3232
* Open the specific repository, navigate to the Settings tab, click Actions option, check if the Actions is enabled for this repository.
3333

3434

35-
## Updating `Manifest.toml` files after updating compat information
35+
## Custom pre-commit hooks
3636

37-
If you check in `Manifest.toml` file(s), the PR created by default CompatHelper setup does not run CI with the latest versions of the dependencies. In this case, it may be a good idea to run `Pkg.update()` via CompatHelper. This can be done simply using the following snippet instead `run: julia -e 'using CompatHelper; CompatHelper.main()'`:
37+
CompatHelper supports running a custom function just before commiting changes.
38+
By default, this function updates any `Manifest.toml` files in your repository to reflect new compatibility bounds.
39+
If you want to extend this behaviour, you can pass your own zero-argument function to `CompatHelper.main`, like so:
3840

3941
```yaml
40-
run: >-
41-
julia -e '
42+
run: julia -e '
4243
using CompatHelper;
4344
CompatHelper.main() do;
44-
run(`julia --project=test -e "import Pkg; Pkg.instantiate(); Pkg.update()"`);
45-
run(`julia --project=docs -e "import Pkg; Pkg.instantiate(); Pkg.update()"`);
46-
end
47-
'
45+
CompatHelper.update_manifests();
46+
println("I did it!");
47+
end;'
4848
```
4949
50-
This setup updates `test/Manifest.toml` and `docs/Manifest.toml` before CompatHelper creates a commit for the pull request.
51-
52-
This snippet uses `>-` to specify a long one-liner command using multi-line code (i.e., the shell does not see the newline characters after `;`). Note that every line must ends with `;` when using `>-`. Do not use `'` inside (outer) Julia code since it is used to quote the command line option `-e '...'`.
50+
This snippet uses `;` to specify the ends of lines, because according to YAML, the entire block of Julia code is a single line.
51+
Also to note is that you cannot use `'` inside of your Julia command, since it's used to quote the Julia code.
5352

5453
A full example is available here: https://github.com/tkf/Kaleido.jl/blob/master/.github/workflows/CompatHelper.yml
5554

55+
If you want to disable the default behavior, simply pass a dummy function that does nothing:
56+
57+
```yaml
58+
run: julia -e '
59+
using CompatHelper;
60+
CompatHelper.main( () -> () );'
61+
```
62+
5663
## Acknowledgements
5764

5865
- This work was supported in part by National Institutes of Health grants U54GM115677, R01LM011963, and R25MH116440. The content is solely the responsibility of the authors and does not necessarily represent the official views of the National Institutes of Health.

src/CompatHelper.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ include("new_versions.jl")
1313
include("pull_requests.jl")
1414
include("stdlib.jl")
1515
include("timestamps.jl")
16+
include("update_manifests.jl")
1617
include("utils.jl")
1718
include("version_numbers.jl")
1819

src/main.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ const default_registries = Pkg.Types.RegistrySpec[Pkg.RegistrySpec(name = "Gener
44
uuid = "23338594-aafe-5451-b93e-139f81909106",
55
url = "https://github.com/JuliaRegistries/General.git")]
66

7-
const default_value_for_keep_existing_compat = true
8-
const default_value_for_drop_existing_compat = false
9-
10-
function main(precommit_hook::Function = () -> (),
7+
function main(precommit_hook::Function = update_manifests,
118
env::AbstractDict = ENV,
129
ci_cfg::CIService = auto_detect_ci_service(; env = env);
1310
registries::Vector{Pkg.Types.RegistrySpec} = default_registries,
14-
keep_existing_compat::Bool = default_value_for_keep_existing_compat,
15-
drop_existing_compat::Bool = default_value_for_drop_existing_compat,
11+
keep_existing_compat::Bool = true,
12+
drop_existing_compat::Bool = false,
1613
master_branch::Union{DefaultBranch, AbstractString} = DefaultBranch(),
1714
pr_title_prefix::String = "")
1815
if !keep_existing_compat && !drop_existing_compat

src/update_manifests.jl

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
function update_manifests(path::AbstractString = pwd();
2+
registries::Vector{Pkg.Types.RegistrySpec} = default_registries,
3+
delete_old_manifest::Bool = true)
4+
environments_to_update = Vector{String}(undef, 0)
5+
for (root, dirs, files) in walkdir(path)
6+
for file in files
7+
if (file == "Manifest.toml") | (file == "JuliaManifest.toml")
8+
environment = joinpath(path, root)
9+
push!(environments_to_update, environment)
10+
end
11+
end
12+
end
13+
unique!(environments_to_update)
14+
_update_manifests(environments_to_update;
15+
registries = registries,
16+
delete_old_manifest = delete_old_manifest)
17+
return nothing
18+
end
19+
20+
function _update_manifests(environments::AbstractVector{<:AbstractString};
21+
registries::Vector{Pkg.Types.RegistrySpec},
22+
delete_old_manifest::Bool)
23+
for environment in environments
24+
_update_manifest(environment;
25+
registries = registries,
26+
delete_old_manifest = delete_old_manifest)
27+
end
28+
return nothing
29+
end
30+
31+
function _has_project(environment::AbstractString)
32+
return (ispath(joinpath(environment, "Project.toml"))) |
33+
(ispath(joinpath(environment, "JuliaProject.toml")))
34+
end
35+
36+
function _update_manifest(environment::AbstractString;
37+
registries::Vector{Pkg.Types.RegistrySpec},
38+
delete_old_manifest::Bool)
39+
@info("Updating environment: $(environment)")
40+
if _has_project(environment) && delete_old_manifest
41+
@debug("Removing Manifest.toml if it exists")
42+
rm(joinpath(environment, "Manifest.toml");
43+
force = true, recursive = true)
44+
@debug("Removing JuliaManifest.toml if it exists")
45+
rm(joinpath(environment, "JuliaManifest.toml");
46+
force = true, recursive = true)
47+
end
48+
with_tmp_dir() do tmp_dir
49+
code = """
50+
using Pkg;
51+
using UUIDs;
52+
Pkg.Types.RegistrySpec(name::Union{Nothing, String},
53+
uuid::Union{Nothing, UUID},
54+
url::Union{Nothing, String},
55+
path::Union{Nothing, String}) = Pkg.Types.RegistrySpec(;
56+
name = name,
57+
uuid = uuid,
58+
url = url,
59+
path = path)
60+
registries = $(registries);
61+
for registry in registries;
62+
Pkg.Registry.add(registry);
63+
end;
64+
Pkg.activate("$(environment)"; shared = false);
65+
Pkg.instantiate();
66+
Pkg.update();
67+
"""
68+
cmd = Cmd(`$(Base.julia_cmd()) -e $(code)`;
69+
env = Dict("PATH" => ENV["PATH"],
70+
"JULIA_DEPOT_PATH" => tmp_dir))
71+
run(pipeline(cmd, stdout=stdout, stderr=stderr))
72+
return nothing
73+
end
74+
return nothing
75+
end

src/utils.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ function generate_pr_title_parenthetical(keep_or_drop::Symbol,
1616
return ""
1717
end
1818
end
19+
20+
function with_tmp_dir(f::Function)
21+
tmp_dir = mktempdir()
22+
atexit(() -> rm(tmp_dir; force = true, recursive = true))
23+
result = f(tmp_dir)
24+
rm(tmp_dir; force = true, recursive = true)
25+
return result
26+
end

test/integration-tests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ with_master_branch(templates("master_4"), "master"; repo_url = repo_url_with_aut
8181
end
8282
end
8383

84+
with_master_branch(templates("master_5"), "master"; repo_url = repo_url_with_auth) do master_5
85+
withenv("GITHUB_REPOSITORY" => COMPATHELPER_INTEGRATION_TEST_REPO,
86+
"GITHUB_TOKEN" => TEST_USER_GITHUB_TOKEN) do
87+
precommit_hook = CompatHelper.update_manifests
88+
env = ENV
89+
ci_cfg = CompatHelper.GitHubActions(whoami)
90+
CompatHelper.main(precommit_hook, env, ci_cfg;
91+
pr_title_prefix = "[test-5a] ",
92+
master_branch = master_5,
93+
keep_existing_compat = false,
94+
drop_existing_compat = true)
95+
end
96+
end
97+
8498
all_prs = CompatHelper.get_all_pull_requests(repo, "open";
8599
auth = auth,
86100
per_page = 3,

test/templates/master_5/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!Manifest.toml
2+
!/Manifest.toml

test/templates/master_5/Manifest.toml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
[[ArgCheck]]
4+
deps = ["Random"]
5+
git-tree-sha1 = "dab25d711a1dedb707a55dbc1eb9fd578f76ff32"
6+
uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197"
7+
version = "1.0.1"
8+
9+
[[Base64]]
10+
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
11+
12+
[[CSTParser]]
13+
deps = ["Tokenize"]
14+
git-tree-sha1 = "99dda94f5af21a4565dc2b97edf6a95485f116c3"
15+
uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
16+
version = "1.0.0"
17+
18+
[[Compat]]
19+
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
20+
git-tree-sha1 = "ed2c4abadf84c53d9e58510b5fc48912c2336fbb"
21+
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
22+
version = "2.2.0"
23+
24+
[[Crayons]]
25+
deps = ["Test"]
26+
git-tree-sha1 = "f621b8ef51fd2004c7cf157ea47f027fdeac5523"
27+
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
28+
version = "4.0.0"
29+
30+
[[DataAPI]]
31+
git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252"
32+
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
33+
version = "1.1.0"
34+
35+
[[DataStructures]]
36+
deps = ["InteractiveUtils", "OrderedCollections"]
37+
git-tree-sha1 = "1fe8fad5fc84686dcbc674aa255bc867a64f8132"
38+
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
39+
version = "0.17.5"
40+
41+
[[Dates]]
42+
deps = ["Printf"]
43+
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
44+
45+
[[DefaultApplication]]
46+
deps = ["Test"]
47+
git-tree-sha1 = "a51d16b075dc52e22cde13b4a6e0ba4ba86649ee"
48+
uuid = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85"
49+
version = "0.1.3"
50+
51+
[[DelimitedFiles]]
52+
deps = ["Mmap"]
53+
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
54+
55+
[[Distributed]]
56+
deps = ["Random", "Serialization", "Sockets"]
57+
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
58+
59+
[[DocStringExtensions]]
60+
deps = ["LibGit2", "Markdown", "Pkg", "Test"]
61+
git-tree-sha1 = "88bb0edb352b16608036faadcc071adda068582a"
62+
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
63+
version = "0.8.1"
64+
65+
[[InteractiveUtils]]
66+
deps = ["Markdown"]
67+
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
68+
69+
[[LibGit2]]
70+
deps = ["Printf"]
71+
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
72+
73+
[[Libdl]]
74+
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
75+
76+
[[LinearAlgebra]]
77+
deps = ["Libdl"]
78+
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
79+
80+
[[Logging]]
81+
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
82+
83+
[[MacroTools]]
84+
deps = ["CSTParser", "Compat", "DataStructures", "Test", "Tokenize"]
85+
git-tree-sha1 = "d6e9dedb8c92c3465575442da456aec15a89ff76"
86+
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
87+
version = "0.5.1"
88+
89+
[[Markdown]]
90+
deps = ["Base64"]
91+
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
92+
93+
[[Missings]]
94+
deps = ["DataAPI"]
95+
git-tree-sha1 = "de0a5ce9e5289f27df672ffabef4d1e5861247d5"
96+
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
97+
version = "0.4.3"
98+
99+
[[Mmap]]
100+
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
101+
102+
[[OrderedCollections]]
103+
deps = ["Random", "Serialization", "Test"]
104+
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
105+
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
106+
version = "1.1.0"
107+
108+
[[PGFPlotsX]]
109+
deps = ["ArgCheck", "Crayons", "DataStructures", "Dates", "DefaultApplication", "DocStringExtensions", "MacroTools", "Missings", "Parameters", "Requires", "StatsBase", "Unicode"]
110+
git-tree-sha1 = "b75f57b00e24934ad94594a71bb10e8c3c523064"
111+
uuid = "8314cec4-20b6-5062-9cdb-752b83310925"
112+
version = "1.0.0"
113+
114+
[[Parameters]]
115+
deps = ["OrderedCollections"]
116+
git-tree-sha1 = "b62b2558efb1eef1fa44e4be5ff58a515c287e38"
117+
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a"
118+
version = "0.12.0"
119+
120+
[[Pkg]]
121+
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
122+
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
123+
124+
[[Printf]]
125+
deps = ["Unicode"]
126+
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
127+
128+
[[REPL]]
129+
deps = ["InteractiveUtils", "Markdown", "Sockets"]
130+
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
131+
132+
[[Random]]
133+
deps = ["Serialization"]
134+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
135+
136+
[[Requires]]
137+
deps = ["Test"]
138+
git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1"
139+
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
140+
version = "0.5.2"
141+
142+
[[SHA]]
143+
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
144+
145+
[[Serialization]]
146+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
147+
148+
[[SharedArrays]]
149+
deps = ["Distributed", "Mmap", "Random", "Serialization"]
150+
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
151+
152+
[[Sockets]]
153+
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
154+
155+
[[SortingAlgorithms]]
156+
deps = ["DataStructures", "Random", "Test"]
157+
git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd"
158+
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
159+
version = "0.3.1"
160+
161+
[[SparseArrays]]
162+
deps = ["LinearAlgebra", "Random"]
163+
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
164+
165+
[[Statistics]]
166+
deps = ["LinearAlgebra", "SparseArrays"]
167+
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
168+
169+
[[StatsBase]]
170+
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics"]
171+
git-tree-sha1 = "c53e809e63fe5cf5de13632090bc3520649c9950"
172+
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
173+
version = "0.32.0"
174+
175+
[[Test]]
176+
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
177+
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
178+
179+
[[Tokenize]]
180+
git-tree-sha1 = "dfcdbbfb2d0370716c815cbd6f8a364efb6f42cf"
181+
uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
182+
version = "0.5.6"
183+
184+
[[UUIDs]]
185+
deps = ["Random", "SHA"]
186+
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
187+
188+
[[Unicode]]
189+
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

0 commit comments

Comments
 (0)