Make IJulia use Python package provided by CondaPkg.jl
Set the JUPYTER
environment variable to CondaPkg.jl
-provided jupyter
and IJulia.jl
will take it to start the kernel. 1
Set the JUPYTER
environment variable to CondaPkg.jl
-provided jupyter
and IJulia.jl
will take it to start the kernel. 1
Use the stack function.
Use heredoc to pass the string as-is between two delimiters (e.g. EOF
)
cat << "EOF" >> ~/.xprofile
# ~/.xprofile
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
ibus-daemon -drx
EOF
Will append the following lines to ~/.xprofile
:
Reload nvidia GPU driver to fix "NVML: Driver/library version mismatch" error without rebooting. Source
name: Create and publish a Docker image
on:
push:
branches: ['main']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# GITHUB_TOKEN permissions
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Running jobs in a container in GitHub actions.
name: container
on: push
jobs:
node-docker:
runs-on: ubuntu-latest
container:
image: node:14.15.0-alpine3.12
steps:
- name: Log the node version
run: |
node -v
cat /etc/os-release
Use the regular docker run command. Here we use >
to fold commands in YAML.
julia
and adds it to PATH
.Example workflow:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-docdeploy@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
with:
files: lcov.info
Using Julia shell to run Julia scripts is much cleaner than julia -e 'code'
.1
For example, the two steps do the same:
- name: Run Julia command
shell: julia --color=yes --project=. --threads=auto {0}
run: |
println("Hello, Julia!")
println("This is fine.")
- name: Run Julia command
run: julia --color=yes --project=. --threads=auto -e '
println("Hello, Julia!")
println("This is fine.")'
In GNU/Linux systems like Ubuntu, PyCall.jl
may not be able to install python packages for PyCall.jl
because it will first try to use the system Python (/usr/bin/python
) and pip
. It would fail due to lack of superuser privileges.
To solve this, you can set the PYTHON
environment variable to where the Python executable is.2
PYTHON:''
) variable will force Julia to install a local miniconda distribution.setup-python
action.The actions/setup-node action installs Node.js and caches package dependencies.
Publish your website to GitHub pages with GitHub actions (CI/CD).
The benefit of using the official workflow is that you do not need an orphan branch to hold the webpages.
jobs:
build:
runs-on: ubuntu-latest
steps:
# After the website is built
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
if: ${{ github.ref == 'refs/heads/main' }}
with:
path: ./site
# Deployment job
deploy:
needs: build
if: ${{ github.ref == 'refs/heads/main' }}
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
actions: read # to download an artifact uploaded by `actions/upload-pages-artifact@v3`
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
In the repository settings => Pages => Build and deployment => Select GitHub actions
as the page source.
You need to give write permission to GITHUB_TOKEN
in the workflow file for the following actions to work
Use peaceiris/actions-gh-pages
# After the website was built
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }} # You need an SSH deploy key if deploying to another repo
publish_dir: ./public
force_orphan: true
commit_message: ${{ github.event.head_commit.message }}
Or JamesIves/github-pages-deploy-action
# After the website was built
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./public # The folder the action should deploy.
In the repository settings => Pages => Build and deployment => Select Deploy from a branch
as the page source.
The actions/setup-python actions installs python
with a specific version and could cache downloaded Python packages. (But not the installed environment)
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- run: pip install -r requirements.txt
The following workflow caches the virtual environment folder1, which is faster than caching the whole Python environment.
- name: Setup Python
uses: actions/setup-python@v5
id: setup-python
with:
python-version: '3.x'
- name: Cache virtualenv
uses: actions/cache@v4
id: cache-venv
with:
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('requirements.txt') }}
path: .venv
- name: Install Python dependencies
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
echo ".venv/bin" >> $GITHUB_PATH
echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV
echo "PYTHON=${VIRTUAL_ENV}/bin/python" >> $GITHUB_ENV
echo "JULIA_PYTHONCALL_EXE=${VIRTUAL_ENV}/bin/python">> $GITHUB_ENV
uv
uv is a drop-in replacement for pip
, an extremely fast Python package and project manager written in Rust.
The GitHub actions workflow:
name: UV example
jobs:
python-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install requirements
run: uv pip install --system -r requirements.txt
The mamba-org/setup-micromamba action installs the micromamba package manager and conda package dependencies. It also caches the Python runtime environment.