From 1fc09dcf44e258c2117f338e56fac1be5fcf9570 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sun, 30 Jan 2022 13:55:41 +0100 Subject: [PATCH 01/10] Use same ApproximateGPs version for docs and examples --- docs/make.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 0c981b70..d0445127 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,13 +1,18 @@ +using ApproximateGPs + ### Process examples # Always rerun examples const EXAMPLES_OUT = joinpath(@__DIR__, "src", "examples") ispath(EXAMPLES_OUT) && rm(EXAMPLES_OUT; recursive=true) mkpath(EXAMPLES_OUT) +# Obtain path of ApproximateGPs so we can run examples with the same version +const PATH_ApproximateGPs = dirname(dirname(pathof(ApproximateGPs))) + # Install and precompile all packages # Workaround for https://github.com/JuliaLang/Pkg.jl/issues/2219 examples = filter!(isdir, readdir(joinpath(@__DIR__, "..", "examples"); join=true)) -let script = "using Pkg; Pkg.activate(ARGS[1]); Pkg.instantiate()" +let script = "using Pkg; Pkg.activate(ARGS[1]); Pkg.develop(PackageSpec(; path=$PATH_ApproximateGPs)); Pkg.instantiate()" for example in examples if !success(`$(Base.julia_cmd()) -e $script $example`) error( @@ -39,8 +44,6 @@ isempty(processes) || success(processes) || error("some examples were not run su ### Build documentation using Documenter -using ApproximateGPs - # Doctest setup DocMeta.setdocmeta!( ApproximateGPs, From bccc37ba509219f2c2860141d91452971b8fde3e Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sun, 30 Jan 2022 14:04:31 +0100 Subject: [PATCH 02/10] Add quotes? --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index d0445127..8a1fa8bd 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -12,7 +12,7 @@ const PATH_ApproximateGPs = dirname(dirname(pathof(ApproximateGPs))) # Install and precompile all packages # Workaround for https://github.com/JuliaLang/Pkg.jl/issues/2219 examples = filter!(isdir, readdir(joinpath(@__DIR__, "..", "examples"); join=true)) -let script = "using Pkg; Pkg.activate(ARGS[1]); Pkg.develop(PackageSpec(; path=$PATH_ApproximateGPs)); Pkg.instantiate()" +let script = "using Pkg; Pkg.activate(ARGS[1]); Pkg.develop(PackageSpec(; path=\"$PATH_ApproximateGPs\")); Pkg.instantiate()" for example in examples if !success(`$(Base.julia_cmd()) -e $script $example`) error( From 7049863f684f97b8219f18912a97243b06c9c67a Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sun, 30 Jan 2022 14:44:26 +0100 Subject: [PATCH 03/10] Use `relpath` to make it easier to reuse Manifest files --- docs/make.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 8a1fa8bd..61ed3f88 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -12,7 +12,12 @@ const PATH_ApproximateGPs = dirname(dirname(pathof(ApproximateGPs))) # Install and precompile all packages # Workaround for https://github.com/JuliaLang/Pkg.jl/issues/2219 examples = filter!(isdir, readdir(joinpath(@__DIR__, "..", "examples"); join=true)) -let script = "using Pkg; Pkg.activate(ARGS[1]); Pkg.develop(PackageSpec(; path=\"$PATH_ApproximateGPs\")); Pkg.instantiate()" +let script = """ +using Pkg +Pkg.activate(ARGS[1]) +Pkg.develop(PackageSpec(; path=relpath("$PATH_ApproximateGPs", ARGS[1]))) +Pkg.instantiate() +""" for example in examples if !success(`$(Base.julia_cmd()) -e $script $example`) error( From e880d4c0c1ee0d89661e533e9b095fb3b382426c Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sun, 30 Jan 2022 14:47:26 +0100 Subject: [PATCH 04/10] Add back quotes --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 61ed3f88..65b91030 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -15,7 +15,7 @@ examples = filter!(isdir, readdir(joinpath(@__DIR__, "..", "examples"); join=tru let script = """ using Pkg Pkg.activate(ARGS[1]) -Pkg.develop(PackageSpec(; path=relpath("$PATH_ApproximateGPs", ARGS[1]))) +Pkg.develop(PackageSpec(; path=relpath(\"$PATH_ApproximateGPs\", ARGS[1]))) Pkg.instantiate() """ for example in examples From d0b799715d3849205125ab5679c3438a0f931980 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sun, 30 Jan 2022 14:54:23 +0100 Subject: [PATCH 05/10] Use regular string --- docs/make.jl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 65b91030..13527cd3 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -12,12 +12,7 @@ const PATH_ApproximateGPs = dirname(dirname(pathof(ApproximateGPs))) # Install and precompile all packages # Workaround for https://github.com/JuliaLang/Pkg.jl/issues/2219 examples = filter!(isdir, readdir(joinpath(@__DIR__, "..", "examples"); join=true)) -let script = """ -using Pkg -Pkg.activate(ARGS[1]) -Pkg.develop(PackageSpec(; path=relpath(\"$PATH_ApproximateGPs\", ARGS[1]))) -Pkg.instantiate() -""" +let script = "using Pkg; Pkg.activate(ARGS[1]); Pkg.develop(PackageSpec(; path=relpath(\"$PATH_ApproximateGPs\", ARGS[1]))); Pkg.instantiate()" for example in examples if !success(`$(Base.julia_cmd()) -e $script $example`) error( From 08c076e0c6fe769d30a9f70fc0232a315f60caca Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sun, 30 Jan 2022 14:57:34 +0100 Subject: [PATCH 06/10] Relative to pwd --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 13527cd3..b4406a91 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -12,7 +12,7 @@ const PATH_ApproximateGPs = dirname(dirname(pathof(ApproximateGPs))) # Install and precompile all packages # Workaround for https://github.com/JuliaLang/Pkg.jl/issues/2219 examples = filter!(isdir, readdir(joinpath(@__DIR__, "..", "examples"); join=true)) -let script = "using Pkg; Pkg.activate(ARGS[1]); Pkg.develop(PackageSpec(; path=relpath(\"$PATH_ApproximateGPs\", ARGS[1]))); Pkg.instantiate()" +let script = "using Pkg; Pkg.activate(ARGS[1]); Pkg.develop(PackageSpec(; path=relpath(\"$PATH_ApproximateGPs\", pwd()))); Pkg.instantiate()" for example in examples if !success(`$(Base.julia_cmd()) -e $script $example`) error( From 6be1dbf856c3e11cea0fc409f8b3eed4135d5ee3 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Mon, 31 Jan 2022 17:14:38 +0100 Subject: [PATCH 07/10] Use pkgdir --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index b4406a91..cf8c253f 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -7,7 +7,7 @@ ispath(EXAMPLES_OUT) && rm(EXAMPLES_OUT; recursive=true) mkpath(EXAMPLES_OUT) # Obtain path of ApproximateGPs so we can run examples with the same version -const PATH_ApproximateGPs = dirname(dirname(pathof(ApproximateGPs))) +const PATH_ApproximateGPs = pkgdir(ApproximateGPs) # Install and precompile all packages # Workaround for https://github.com/JuliaLang/Pkg.jl/issues/2219 From 08a3f7b36ab3e4650270b5f9505278cf85518f38 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 1 Feb 2022 03:07:57 +0100 Subject: [PATCH 08/10] Add special cases --- docs/make.jl | 69 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index cf8c253f..cb1c8e03 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,4 +1,5 @@ using ApproximateGPs +using Documenter ### Process examples # Always rerun examples @@ -6,13 +7,74 @@ const EXAMPLES_OUT = joinpath(@__DIR__, "src", "examples") ispath(EXAMPLES_OUT) && rm(EXAMPLES_OUT; recursive=true) mkpath(EXAMPLES_OUT) -# Obtain path of ApproximateGPs so we can run examples with the same version -const PATH_ApproximateGPs = pkgdir(ApproximateGPs) +# The following function returns a script for instantiating the package +# environment of an example +# It ensures that the version of the package in which module `mod` is defined +# (here `mod` will be ApproximateGPs loaded above) is added to the environment. +# Thus the docs and the examples will use the same version of this package. +# There are two special cases: +# - If the script is executed by a GH action triggered by a new tag (i.e., release) +# in the package repo, then this version of the package will be downloaded and installed +# instead of checking out the local path +# - If the script is executed by a GH action triggered by a new commit in the `devbranch` +# (by default `master`) in the package repo, then this revision of the package will be +# downloaded and installed instead of checking out the local path +# This ensures that in these two cases the resulting Manifest.toml files do not fix the +# local path of any package, and hence can be used to reproduce the package environment in +# a clean and reproducible way. +function instantiate_script(mod; org, name=string(nameof(mod)), devbranch="master") + github_repo = get(ENV, "GITHUB_REPOSITORY", "") + github_event_name = get(ENV, "GITHUB_EVENT_NAME", "") + + repo = org * "/" * name * ".jl" + if github_repo == repo && github_event_name == "push" + github_ref = get(ENV, "GITHUB_REF", "") + match_tag = match(r"^refs\/tags\/(.*)$", github_ref) + if match_tag !== nothing + # tagged release + tag_nobuild = Documenter.version_tag_strip_build(match_tag.captures[1]) + if tag_nobuild !== nothing + @info "Run examples with $name version $tag_nobuild" + return """ +using Pkg +Pkg.activate(ARGS[1]) +Pkg.add(PackageSpec(; name=$name, version=$version)) +Pkg.instantiate() +""" + end + else + # no release tag + match_branch = match(r"^refs\/heads\/(.*)$", github_ref) + if match_branch !== nothing && string(m.captures[1]) == devbranch + sha = get(ENV, "GITHUB_SHA", nothing) + if sha !== nothing + @info "Run examples with $name commit $sha" + return """ +using Pkg +Pkg.activate(ARGS[1]) +Pkg.add(PackageSpec(; name=$name, rev=$sha)) +Pkg.instantiate() +""" + end + end + end + end + + # Default: Use local path of provided module + pkgdir_mod = pkgdir(mod) + @info "Run examples with $name, local path $pkgdir_mod" + return """ +using Pkg +Pkg.activate(ARGS[1]) +Pkg.develop(PackageSpec(; path=pkgdir_mod)) +Pkg.instantiate() +""" +end # Install and precompile all packages # Workaround for https://github.com/JuliaLang/Pkg.jl/issues/2219 examples = filter!(isdir, readdir(joinpath(@__DIR__, "..", "examples"); join=true)) -let script = "using Pkg; Pkg.activate(ARGS[1]); Pkg.develop(PackageSpec(; path=relpath(\"$PATH_ApproximateGPs\", pwd()))); Pkg.instantiate()" +let script = instantiate_script(ApproximateGPs; org="JuliaGaussianProcesses") for example in examples if !success(`$(Base.julia_cmd()) -e $script $example`) error( @@ -42,7 +104,6 @@ end isempty(processes) || success(processes) || error("some examples were not run successfully") ### Build documentation -using Documenter # Doctest setup DocMeta.setdocmeta!( From a8f51615110f105e2c70f04fd1041c75efab4cf0 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 1 Feb 2022 03:15:15 +0100 Subject: [PATCH 09/10] Some fixes --- docs/make.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index cb1c8e03..ca2395c8 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -38,7 +38,7 @@ function instantiate_script(mod; org, name=string(nameof(mod)), devbranch="maste return """ using Pkg Pkg.activate(ARGS[1]) -Pkg.add(PackageSpec(; name=$name, version=$version)) +Pkg.add(PackageSpec(; name="$name", version="$version")) Pkg.instantiate() """ end @@ -52,7 +52,7 @@ Pkg.instantiate() return """ using Pkg Pkg.activate(ARGS[1]) -Pkg.add(PackageSpec(; name=$name, rev=$sha)) +Pkg.add(PackageSpec(; name="$name", rev="$sha")) Pkg.instantiate() """ end @@ -66,7 +66,7 @@ Pkg.instantiate() return """ using Pkg Pkg.activate(ARGS[1]) -Pkg.develop(PackageSpec(; path=pkgdir_mod)) +Pkg.develop(PackageSpec(; path="$pkgdir_mod")) Pkg.instantiate() """ end From 1f3e9e09b7d09f02d56f202cd67c9856167d66f2 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 1 Feb 2022 10:52:38 +0100 Subject: [PATCH 10/10] Use `--project` --- docs/make.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index ca2395c8..1092f5b8 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -37,7 +37,6 @@ function instantiate_script(mod; org, name=string(nameof(mod)), devbranch="maste @info "Run examples with $name version $tag_nobuild" return """ using Pkg -Pkg.activate(ARGS[1]) Pkg.add(PackageSpec(; name="$name", version="$version")) Pkg.instantiate() """ @@ -51,7 +50,6 @@ Pkg.instantiate() @info "Run examples with $name commit $sha" return """ using Pkg -Pkg.activate(ARGS[1]) Pkg.add(PackageSpec(; name="$name", rev="$sha")) Pkg.instantiate() """ @@ -65,7 +63,6 @@ Pkg.instantiate() @info "Run examples with $name, local path $pkgdir_mod" return """ using Pkg -Pkg.activate(ARGS[1]) Pkg.develop(PackageSpec(; path="$pkgdir_mod")) Pkg.instantiate() """ @@ -76,7 +73,7 @@ end examples = filter!(isdir, readdir(joinpath(@__DIR__, "..", "examples"); join=true)) let script = instantiate_script(ApproximateGPs; org="JuliaGaussianProcesses") for example in examples - if !success(`$(Base.julia_cmd()) -e $script $example`) + if !success(`$(Base.julia_cmd()) --project=$example -e $script`) error( "project environment of example ", basename(example),