Skip to content

👷 Testing all reactive notebooks #65

👷 Testing all reactive notebooks

👷 Testing all reactive notebooks #65

name: Test
run-name: 👷 Testing all reactive notebooks
on: [pull_request]
env:
JOLIN_SITE: "nosite.nosite"
JOLIN_ENVIRONMENT: "test"
jobs:
job-matrix:
runs-on: ubuntu-latest
container: jolincompany/jolin_cloud_cicd:latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: |
echo matrix=$(julia -e '
import Pkg
Pkg.Registry.add("General")
Pkg.Registry.add(Pkg.RegistrySpec(url="https://github.com/jolin-io/JolinRegistry.jl"))
Pkg.add("JolinPlutoCICD")
using JolinPlutoCICD
print(JolinPlutoCICD.json_common_prefix_common_suffix_and_all_notebook_paths(ARGS[1]))
' .) >> "$GITHUB_OUTPUT"
job-run:
name: ${{ matrix.notebook_path }}
runs-on: ubuntu-latest
container: jolincompany/jolin_cloud_cicd:latest
needs: job-matrix
strategy:
matrix: ${{ fromJSON(needs.job-matrix.outputs.matrix) }}
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
steps:
- uses: actions/checkout@v3
# set JOLIN_REPO environment variable
- run: echo "JOLIN_REPO=github.com/${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- run: |
julia -e '
import Pkg
Pkg.Registry.add("General")
Pkg.Registry.add(Pkg.RegistrySpec(url="https://github.com/jolin-io/JolinRegistry.jl"))
Pkg.add("JolinPlutoCICD")
'
# we need to create temporary environment under GITHUB_WORKSPACE, because only files under this directory will be hashed
- run: |
echo notebook_env=$(julia -e '
using JolinPlutoCICD
env_dir = JolinPlutoCICD.create_pluto_env(ARGS[1], parentdir=joinpath(ENV["GITHUB_WORKSPACE"], "_temp_envs"))
# we want to cache .CondaPkg, hence it already needs to exist
mkpath(joinpath(env_dir, ".CondaPkg"))
# we need to strip the GITHUB_WORKSPACE because hashFiles only works with paths relative to GITHUB_WORKSPACE
env_dir_relative = lstrip(env_dir[begin+length(ENV["GITHUB_WORKSPACE"]) : end], ' "'/'" ')
print(env_dir_relative)
' "${{ matrix.prefix }}${{ matrix.notebook_path }}${{ matrix.suffix }}") >> "$GITHUB_ENV"
# fixing permission error for hashfiles (actually works)
# adapted from https://github.com/cypress-io/github-action/issues/446#issuecomment-968192021
- run: chown -R 1001:1001 $GITHUB_WORKSPACE/$notebook_env
- uses: actions/cache@v3
with:
path: |
~/.julia
$GITHUB_WORKSPACE/$notebook_env/.CondaPkg
key: ${{ runner.os }}-${{ hashFiles(format('{0}/*.toml', env.notebook_env)) }}
restore-keys: ${{ runner.os }}-
- run: |
# initialize conda first
julia -e '
# because of the caching JolinPlutoCICD might be no longer installed
if Base.identify_package("JolinPlutoCICD") === nothing
import Pkg
Pkg.Registry.add("General")
Pkg.Registry.add(Pkg.RegistrySpec(url="https://github.com/jolin-io/JolinRegistry.jl"))
Pkg.add("JolinPlutoCICD")
end
import JolinPlutoCICD
eval(JolinPlutoCICD.expr_resolve_condapkg(ARGS[1]))
' "$GITHUB_WORKSPACE/$notebook_env"
# set R_HOME if conda was actually initialized - needed before Pkg.instantiate()
if [ -d "$GITHUB_WORKSPACE/$notebook_env/.CondaPkg" ]; then
echo R_HOME="$GITHUB_WORKSPACE/$notebook_env/.CondaPkg/env/lib/R" >> "$GITHUB_ENV"
fi
- run: |
julia --project=$GITHUB_WORKSPACE/$notebook_env -e '
import Pkg
Pkg.instantiate()
'
- working-directory: ./
run: |
julia --project=$GITHUB_WORKSPACE/$notebook_env -e '
if endswith(ARGS[1], ".jl")
include(ARGS[1])
elseif endswith(ARGS[1], ".py")
import PythonCall
PythonCall.pyexec(@NamedTuple{}, readchomp(ARGS[1]), Main)
elseif endswith(ARGS[1], ".R") || endswith(ARGS[1], ".r")
import RCall
reval(readchomp(ARGS[1]))
end
' "${{ matrix.prefix }}${{ matrix.notebook_path }}${{ matrix.suffix }}"