diff --git a/.github/workflows/NotebookDifference.yaml b/.github/workflows/NotebookDifference.yaml new file mode 100644 index 00000000..b679fbbe --- /dev/null +++ b/.github/workflows/NotebookDifference.yaml @@ -0,0 +1,56 @@ +name: Compare notebook files +on: + # workflow_dispatch: + # push: + # paths-ignore: + # - "**.md" + # branches: + # - main + pull_request: + paths-ignore: + - "**.md" + +jobs: + notebook-changes-check: + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + path: source + + + - name: Checkout + uses: actions/checkout@v4 + with: + ref: dist + path: gh_pages_dir + + + - name: Install Julia + uses: julia-actions/setup-julia@v2 + with: + # note: this version should match the version in the other actions in this repo + version: "1.11" + + - name: Cache Julia artifacts & such + uses: julia-actions/cache@v2 + with: + cache-registries: "true" + + # We set up a folder that Pluto can use to cache exported notebooks. If the notebook file did not change, then Pluto can take the exported file from cache instead of running the notebook. + - name: Set up notebook state cache + uses: actions/cache@v4 + with: + path: pluto_state_cache + # use the same key as the export action on the main branch: + key: ${{ runner.os }}-pluto_state_cache-v3-${{ hashFiles('**/Project.toml', '**/Manifest.toml') }}-${{ github.run_id }} + # here, you want to use the same restore key, but without the Project/Manifest hash: + restore-keys: | + ${{ runner.os }}-pluto_state_cache-v3 + + - name: Compare notebooks in PR + run: | + julia --threads=auto source/tools/diff.jl + diff --git a/pluto-deployment-environment/Manifest.toml b/pluto-deployment-environment/Manifest.toml index e30e5649..0f1f0772 100644 --- a/pluto-deployment-environment/Manifest.toml +++ b/pluto-deployment-environment/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.11.3" manifest_format = "2.0" -project_hash = "13a51ad2b377d764861ea553e631182e0e81a599" +project_hash = "9854db52c26347aaaf320fc7b5e3c74d874b1bb3" [[deps.AbstractPlutoDingetjes]] deps = ["Pkg"] @@ -354,6 +354,14 @@ git-tree-sha1 = "9071bfe6d1c3c51f62918513e8dfa0705fbdef7e" uuid = "72656b73-756c-7461-726b-72656b6b696b" version = "1.2.1" +[[deps.PlutoNotebookComparison]] +deps = ["Compat", "ExpressionExplorer", "HTTP", "InteractiveUtils", "LibGit2", "Logging", "LoggingExtras", "Markdown", "Pkg", "Pluto", "PlutoSliderServer", "TOML", "URIs"] +git-tree-sha1 = "ad309f681e6f3812d943933ef736267911ebccc3" +repo-rev = "main" +repo-url = "https://github.com/JuliaPluto/PlutoNotebookComparison.jl" +uuid = "828d9ff0-206c-6161-646e-6576656f7242" +version = "1.0.0" + [[deps.PlutoSliderServer]] deps = ["AbstractPlutoDingetjes", "Base64", "BetterFileWatching", "Configurations", "Distributed", "FromFile", "Git", "Glob", "HTTP", "JSON", "Logging", "Pkg", "Pluto", "PlutoDependencyExplorer", "SHA", "Serialization", "Sockets", "TOML", "TerminalLoggers", "UUIDs"] git-tree-sha1 = "9e1a630079de12343df2ccf9a90c46177bd38780" diff --git a/pluto-deployment-environment/Project.toml b/pluto-deployment-environment/Project.toml index ccd0eeae..f3f0f5f8 100644 --- a/pluto-deployment-environment/Project.toml +++ b/pluto-deployment-environment/Project.toml @@ -1,3 +1,4 @@ [deps] Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781" +PlutoNotebookComparison = "828d9ff0-206c-6161-646e-6576656f7242" PlutoSliderServer = "2fc8631c-6f24-4c5b-bca7-cbb509c42db4" diff --git a/tools/diff.jl b/tools/diff.jl new file mode 100644 index 00000000..6ebabea0 --- /dev/null +++ b/tools/diff.jl @@ -0,0 +1,57 @@ +source = joinpath(@__DIR__, "..") + + +function tryexpanduser(path) + try + expanduser(path) + catch ex + path + end +end + +tamepath = abspath ∘ tryexpanduser + +pluto_state_cache = tamepath("pluto_state_cache") +gh_pages_dir = tamepath("gh_pages_dir") + +if !isdir(pluto_state_cache) || readdir(pluto_state_cache) == [] + @warn "Running this script without a GitHub Actions PlutoSliderServer cache. Using a local cache in the temp dir." + pluto_state_cache = joinpath(tempdir(), "bmlip cache") +end + +cd(source) + +using Pkg +Pkg.activate(joinpath(source, "pluto-deployment-environment")) +Pkg.instantiate() + +using PlutoNotebookComparison + + +sources_old = [ + PSSCache(pluto_state_cache) + WebsiteDir(gh_pages_dir) + WebsiteAddress("https://featured.plutojl.org/") + SafePreview() +] + +sources_new = [ + PSSCache(pluto_state_cache) + RunWithPlutoSliderServer(; Export_cache_dir=pluto_state_cache) +] + +drama_checkers = [ + DramaRestartRequired() + DramaNewError() + DramaBrokenImport() +] + +PlutoNotebookComparison.compare_PR(source; + sources_old, + sources_new, + drama_checkers, +) + + + + diff --git a/tools/update_notebook_packages.jl b/tools/update_notebook_packages.jl index 9088c0f6..1a213f7b 100644 --- a/tools/update_notebook_packages.jl +++ b/tools/update_notebook_packages.jl @@ -29,8 +29,8 @@ all_notebooks = filter(Pluto.is_pluto_notebook, all_files_recursive) level = getfield(Pkg, Symbol("UPLEVEL_$(ARGS[1])")) -for n in all_notebooks - @info "Updating" n +for (i,n) in enumerate(all_notebooks) + @info "Updating [$i/$(length(all_notebooks))] $n" Pluto.update_notebook_environment(n; backup=false, level) end