Skip to content

Commit

Permalink
Add instantiate utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHatherly committed Apr 18, 2024
1 parent 5978de2 commit c301851
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 19 deletions.
25 changes: 6 additions & 19 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,10 @@ jobs:
- uses: julia-actions/install-juliaup@5e96cfab3bb0500aa42f2843f46c24b91cfcc3cd
with:
julia-version: "1.10.2"
- run: |
juliaup default 1.10.2
juliaup add 1.10.1
- run: julia +1.10.1 --project=test/multiversion/envs/CommonMark_1.10.1 -e 'import Pkg; Pkg.instantiate()'
env:
JULIA_PKG_PRECOMPILE_AUTO: "0"

- run: julia +1.10.2 --project=test/multiversion/envs/CommonMark_1.10.2 -e 'import Pkg; Pkg.instantiate()'
env:
JULIA_PKG_PRECOMPILE_AUTO: "0"
- run: juliaup default 1.10.2

- run: julia --project -e 'import Pkg; Pkg.instantiate()'
- run: julia --project -e 'import PackageBundler; PackageBundler.instantiate("test/multiversion/envs")'
- run: julia --project test/multiversion/bundle.jl

- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
Expand Down Expand Up @@ -140,17 +131,13 @@ jobs:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
with:
persist-credentials: false
- uses: julia-actions/setup-julia@f2258781c657ad9b4b88072c5eeaf9ec8c370874
- uses: julia-actions/install-juliaup@5e96cfab3bb0500aa42f2843f46c24b91cfcc3cd
with:
version: ${{ matrix.version }}
julia-version: "${{ matrix.version }}"
- run: juliaup default ${{ matrix.version }}
- uses: julia-actions/cache@dc1a3cdeacb521b0ca93cfc66143fcadb15a5bd0
- uses: julia-actions/julia-buildpkg@90dd6f23eb49626e4e6612cb9d64d456f86e6a1c

# `PackageBundler.bundle()` expects the environments to be bundled to have
# already been instantiated (hence downloaded) prior to running it. We
# don't need to precompile it though.
- run: julia --project=test/envs/CustomEnv -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; import Pkg; Pkg.instantiate()'

- run: julia --project -e 'import PackageBundler; PackageBundler.instantiate("test/envs")'
- uses: julia-actions/julia-runtest@79a7e100883947123f8263c5f06e6c0ea3eb972f
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
with:
Expand Down
1 change: 1 addition & 0 deletions src/PackageBundler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,6 @@ end

include("openssl.jl")
include("code_stripping.jl")
include("utilities.jl")

end # module PackageBundler
73 changes: 73 additions & 0 deletions src/utilities.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
instantiate(environments::String)
Scan the directory `environments` for subdirectories containing a
`Manifest.toml` file and instantiate them all using the appropriate `julia`
version as specified in the `Manifest.toml` file. This uses either `juliaup` or
`asdf` to switch between `julia` versions as needed. Make sure to have either of
those installed, as well as the expected `julia` versions.
"""
function instantiate(environments::String)
if ispath(environments)
if isfile(environments)
error("The path '$environments' is a file, not a directory.")
end
else
error("The path '$environments' does not exist.")
end
for each in readdir(environments; join = true)
manifest = joinpath(each, "Manifest.toml")
if isfile(manifest)
@info "Instantiating $each"
toml = TOML.parsefile(manifest)
julia_version = toml["julia_version"]
if !isnothing(Sys.which("juliaup"))
@info "Checking whether Julia '$julia_version' is installed, if not, installing it."
run(`juliaup add $julia_version`)
withenv("JULIA_PKG_PRECOMPILE_AUTO" => 0) do
run(
`julia +$(julia_version) --project=$each -e 'import Pkg; Pkg.instantiate()'`,
)
end
elseif !isnothing(Sys.which("asdf"))
# Using the `ASDF_JULIA_VERSION` environment variable to control the
# `julia` version used doesn't appear to have an effect. Instead
# compute the exact path to the binary and use that instead.
asdf_dir = get(
ENV,
"ASDF_DATA_DIR",
get(ENV, "ASDF_DIR", joinpath(homedir(), ".asdf")),
)
if isdir(asdf_dir)
julia_path = joinpath(
asdf_dir,
"installs",
"julia",
"$(julia_version)",
"bin",
"julia",
)
if !isfile(julia_path)
@info "Installing Julia '$julia_version', since it does not appear to be installed."
run(`asdf install julia $julia_version`)
end
if isfile(julia_path)
withenv("JULIA_PKG_PRECOMPILE_AUTO" => 0) do
run(
`$julia_path --project=$each -e 'import Pkg; Pkg.instantiate()'`,
)
end
else
error(
"The `julia` binary for version $julia_version failed to install.",
)
end
else
error("`asdf` is not installed in a known location. $asdf_dir")
end
else
error("`asdf` or `juliaup` is required to instantiate the environments.")
end
end
end
end

0 comments on commit c301851

Please sign in to comment.