Tip: use Julia as custom shell in GitHub Actions

This isn’t maybe very well-known, but in GitHub Actions you can run commands using custom shells, including julia.

For example, in a package I always want to test on CI a package using the latest development revision of a dependency. You can achieve this with a step like:

      - name: Install extra dependency on main branch
        shell: julia --color=yes --project=. {0}
        run: |
          using Pkg
          Pkg.add(PackageSpec(; name="AnExtraPackage", rev="main"))

This isn’t much different from the standard

      - name: Install extra dependency on main branch
        run: |
          julia --project=. -e 'using Pkg; Pkg.add(PackageSpec(; name="AnExtraPackage", rev="main"))'

but using the custom shell makes it nicer to write a multiline Julia script.

42 Likes

Does it work with ]add APackage@1.2.3?

No because ]add... isn’t valid Julia syntax (ERROR: syntax: unexpected "]"). You could use the pkg"..." string literal, but its usage is frowned upon in scripts, because the syntax may break.

1 Like

A quick comment about where this can be important: if you want to develop a dependency that lives in a subdir package, you might use 'using Pkg; Pkg.develop(path=joinpath(pwd(), "SubdirPackage"))' in your CI.yml file. But Windows seems to choke on some aspect of escaping. Using a Julia shell to run that command fixes the problem. (Thanks to @fredrikekre for pointing this out.)

3 Likes