Reputation: 3036
I'd like to reference some commands I've set up in my justfile
to be used in some steps of the CI pipeline (namely in my actions.yaml
file) and I'm encountering issues. For personal preference, I'd like just
commands to be run on powershell
both locally and in the CI pipeline.
My justfile
is as follows (it is meant to be run on a Windows machine):
# Use PowerShell instead of sh, https://just.systems/man/en/chapter_3.html
set shell := ["powershell.exe", "-c"]
help:
@just --list
install:
@echo "🚀 Installing dependencies"
@poetry install --with dev
install-pre-commit:
@echo "🚀 Setting up the hooks"
@poetry run pre-commit install
check-project:
@echo "🚀 Checking consistency between poetry.lock and pyproject.toml"
@poetry check --lock
@echo "🚀 Running the hooks against all files"
@poetry run pre-commit run --all-files
ruff:
@echo "🚀 Linting the project with Ruff"
@poetry run ruff check src tests
ruff-show-violations:
@echo "🚀 Linting the project with Ruff and show violations"
@poetry run ruff check --show-source --show-fixes src tests
ruff-fix:
@echo "🚀 Linting the project with Ruff and autofix violations (where possible)"
@poetry run ruff check --fix src tests
black:
@echo "🚀 Formatting the code with Black"
@poetry run black src tests
black-check:
@echo "🚀 Checking formatting advices from Black"
@poetry run black --check --diff src tests
lint-and-format: ruff black
test:
@echo "🚀 Testing code with pytest"
@poetry run pytest --verbose tests
test-and-report-cov:
@echo "🚀 Testing code with pytest and generating coverage report"
@poetry run pytest --cov=./ --cov-report=xml
And here is part of my actions.yaml
file:
jobs:
lint-and-test:
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv if cache exists
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies if cache does not exist
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install project
run: poetry install --no-interaction
- name: Setup just
uses: taiki-e/install-action@just
- name: Enforce code style (Ruff)
run: just ruff-show-violations
- name: Verify code formatting (Black)
run: just black-check
- name: Run tests
run: just test
- name: Generate test coverage report
run: just test-and-report-cov
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
the most relevant steps in this regard being the definition of the default shell
, just's setup (taiki-e/install-action@just
, as per the manual) and the successive steps where just
is invoked to run commands.
Along with the described setup, I get
> just ruff-show-violations
> shell: /usr/bin/pwsh -command ". '{0}'"
> env:
> PYTHON_VERSION: 3.10
> POETRY_VERSION: 1.6.1
pythonLocation: /opt/hostedtoolcache/Python/3.10.13/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.10.13/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.13/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.13/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.13/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.13/x64/lib
VENV: .venv/bin/activate
**error: Recipe `ruff-show-violations` could not be run because just could not find the shell: No such file or directory (os error 2)
Error: Process completed with exit code 1.**
Based on the error message and in the idea of ensuring compatibility between set shell := ["powershell.exe", "-c"]
in justfile
and the setup of the default shell in actions.yaml
(namely, trying to ensure alignment between the local execution environment and the Linux environment the Github Actions workflow runs on), I've tried to play around with these two with no luck. Neither setting pwsh
nor powershell
as default shell seems to work; specifying the shell at the level of single steps (with shell:
option) doesn't work as well.
How to invoke just
in GitHub Actions jobs' steps and run them on powershell
?
Setting things up to run on bash
, you won't incur in any issue. Namely, removing set shell := ["powershell.exe", "-c"]
from justfile
(thus reverting to bash
by default) and specifying bash
to be the default shell on which to run jobs in actions.yaml
I could get a working configuration. However, I am yet to find a configuration that could properly run everything on powershell
.
Not completely sure about that, but I also noticed that - no matter what the default shell configuration was - taiki-e/install-action@just
kept on running on bash
, which might be the root cause of the problem. Plus, it doesn't accept a shell
input (that I tried to pass via with: shell: ...
option) with which one could try to force the shell where to run the specific step on.
IOW, with
jobs:
lint-and-test:
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
...
...
- name: Setup just
uses: taiki-e/install-action@just
with:
shell: pwsh
I got
Warning: Unexpected input(s) 'shell', valid inputs are ['tool', 'checksum']
Run taiki-e/install-action@just
with:
shell: pwsh
tool: just
checksum: true
env:
PYTHON_VERSION: 3.10
POETRY_VERSION: 1.6.1
pythonLocation: /opt/hostedtoolcache/Python/3.10.13/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.10.13/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.13/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.13/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.13/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.13/x64/lib
VENV: .venv/bin/activate
Run bash --noprofile --norc "${GITHUB_ACTION_PATH:?}/main.sh"
info: host platform: x86_64_linux
info: installing just@latest
info: downloading https://github.com/casey/just/releases/download/1.23.0/just-1.23.0-x86_64-unknown-linux-musl.tar.gz
info: verifying sha256 checksum for just-1.23.0-x86_64-unknown-linux-musl.tar.gz
info: just installed at /home/runner/.cargo/bin/just
+ just --version
just 1.23.0
Upvotes: 0
Views: 1504