Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use starflow #2015

Merged
merged 14 commits into from
Dec 11, 2024
Merged
25 changes: 25 additions & 0 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: QA
on:
push:
branches:
- "main"
- "feature/*"
- "hotfix/*"
- "release/*"
- "renovate/*"
pull_request:
merge_group:

jobs:
lint:
uses: canonical/starflow/.github/workflows/lint-python.yaml@main
test:
uses: canonical/starflow/.github/workflows/test-python.yaml@main
with:
# Self-hosted Jammy and Noble runners, GH-hosted macos and Windows runners.
# Limiting to amd64 is a workaround for https://github.com/canonical/charmcraft/issues/2018
fast-test-platforms: '[["jammy", "amd64"], ["noble", "amd64"], "macos-13", "macos-14-large", "windows-2019", "windows-2022"]'
# Slow tests run on noble to avoid an issue with old skopeo versions.
slow-test-platforms: '["noble", "macos-14-large"]'
# Switch to just noble when we fix #2018
lowest-python-platform: self-hosted-linux-amd64-noble-large
2 changes: 2 additions & 0 deletions .github/workflows/security-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ jobs:
# contain vulnerable versions.
requirements-find-args: '! -name requirements-noble.txt ! -path "./tests/spread/*"'
osv-extra-args: '--config=source/osv-scanner.toml'
uv-export: false
uv-sync-extra-args: --no-dev
135 changes: 15 additions & 120 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,118 +13,6 @@ on:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Begin snap installs
run: |
echo "Installing snaps in the background while running apt and pip..."
sudo snap install --no-wait shellcheck ruff
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Configure environment
run: |
echo "::group::pip install"
python -m pip install tox
echo "::endgroup::"
echo "::group::Create virtual environments for linting processes."
tox run -m lint --notest
echo "::endgroup::"
echo "::group::Wait for snap to complete"
snap watch --last=install
echo "::endgroup::"
- name: Run Linters
run: tox run --skip-pkg-install --no-list-dependencies -m lint
run-tests:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04, macos-13, macos-14-large, windows-2019, windows-2022]
include:
- os: windows-2019
python-version: |
3.11
3.12
- os: windows-2022
python-version: |
3.11
3.12
- os: macos-14-large
python-version: |
3.10
3.12
3.13
- os: macos-13
python-version: |
3.10
3.12
3.13
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
if: ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install Ubuntu-specific dependencies
if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: |
sudo apt update
sudo apt install -y python3-pip python3-setuptools python3-wheel python3-venv libapt-pkg-dev
pipx install poetry
# Jammy runners have too old a version of pip.
if [[ $(lsb_release --codename --short) == 'jammy' ]]; then
python3 -m pip install -U pip
fi
- name: Setup LXD
uses: canonical/setup-lxd@v0.1.1
if: ${{ runner.os == 'Linux' }}
- name: Install skopeo (mac)
# This is only necessary for Linux until skopeo >= 1.11 is in repos.
# Once we're running on Noble, we can get skopeo from apt.
if: ${{ runner.os == 'macOS' }}
run: |
brew install skopeo
- name: Install skopeo (Linux)
if: ${{ runner.os == 'Linux' }}
run: |
if [[ $(cat /etc/os-release | grep VERSION_CODENAME) == 'VERSION_CODENAME=jammy' ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install skopeo
sudo rm -f /bin/skopeo
sudo ln -s $(which skopeo) /bin/skopeo
else
sudo apt install skopeo
fi
# Allow skopeo to access the contents of /run/containers
sudo chmod 777 /run/containers
# Add an xdg runtime dir for skopeo to look into for an auth.json file
sudo mkdir -p /run/user/$(id -u)
sudo chown $USER /run/user/$(id -u)
- name: Configure environment
run: |
pipx install tox
tox run --colored yes -m tests --notest
- name: Run tests
shell: bash
run: |
# -s == --kernel-name, but the long form isn't available on Mac OSX
if [[ $(uname -s) == "Linux" ]]; then
export XDG_RUNTIME_DIR=/run/user/$(id -u)
fi
tox run --skip-pkg-install --no-list-dependencies --result-json results/tox-${{ matrix.platform }}.json --colored yes -m tests

snap-build:
runs-on: ubuntu-22.04
steps:
Expand Down Expand Up @@ -238,17 +126,18 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
- name: Set up uv with caching
id: setup-uv
uses: astral-sh/setup-uv@v3
with:
python-version: '3.11'
enable-cache: true
- name: Install dependencies
run: |
pip install -U pyinstaller -r requirements.txt
pip install .
uv sync --no-dev
uv pip install pyinstaller
- name: Build
run: |
pyinstaller charmcraft.spec
uv run pyinstaller charmcraft.spec
- name: Upload unsigned exe
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -319,25 +208,31 @@ jobs:
run: brew install-bundler-gems
- name: Install dependencies with homebrew
run: |
brew install libgit2@1.7 # For building pygit2
brew install multipass
brew install libgit2@1.7 # For building pygit2
- name: Checkout code
uses: actions/checkout@v4
- name: Set up uv with caching
id: setup-uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Build and install Charmcraft
run: |
pip install -r requirements.txt .
uv sync --no-dev
- name: Check for fully-configured multipass
run: |
while ! multipass version; do
sleep 1
done
- name: Init and pack
run: |
source .venv/bin/activate
mkdir test-charm
cd test-charm
export CRAFT_VERBOSITY_LEVEL=trace
Expand Down
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v5.0.0"
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: check-toml
- id: fix-byte-order-marker
- id: mixed-line-ending
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.1"
hooks:
# Run the linter
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
# Run the formatter
- id: ruff-format
- repo: https://github.com/adrienverge/yamllint.git
rev: "v1.35.1"
hooks:
- id: yamllint
11 changes: 6 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ To set up an initial development environment:

git clone https://github.com/canonical/charmcraft.git
cd charmcraft
uv venv
. .venv/bin/activate
uv pip install -r requirements-dev.txt -e .
uv sync --all-extras

If you need `python-apt`, add `https://people.canonical.com/~lengau/pypi/` as an
extra index URL.

You will need a copy of `ruff` installed. On many Linux distributions, you
can install ruff with:
Expand All @@ -36,7 +37,7 @@ When you're done, make sure you run the tests.

You can do so with

uv pip install -r requirements-dev.txt
./run_tests
uv sync
uv run pytest

Contributions welcome!
83 changes: 83 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
PROJECT=charmcraft
ifneq ($(wildcard /etc/os-release),)
include /etc/os-release
export
endif

ifneq ($(VERSION_CODENAME),)
SETUP_TESTS_EXTRA_ARGS=--extra apt-$(VERSION_CODENAME)
endif

UV_FROZEN=true

include common.mk

.PHONY: format
format: format-ruff format-codespell ## Run all automatic formatters

.PHONY: lint
lint: lint-ruff lint-codespell lint-mypy lint-pyright lint-shellcheck lint-yaml lint-docs lint-twine ## Run all linters

.PHONY: pack
pack: pack-pip pack-snap ## Build all packages

.PHONY: pack-snap
pack-snap: snap/snapcraft.yaml ##- Build snap package
ifeq ($(shell which snapcraft),)
sudo snap install --classic snapcraft
endif
snapcraft pack

.PHONY: publish
publish: publish-pypi ## Publish packages

.PHONY: publish-pypi
publish-pypi: clean package-pip lint-twine ##- Publish Python packages to pypi
uv tool run twine upload dist/*

.PHONY: setup
setup: install-uv setup-precommit ## Set up a development environment
uv sync --frozen $(SETUP_TESTS_EXTRA_ARGS) --extra docs --extra lint --extra types

# Used for installing build dependencies in CI.
.PHONY: install-build-deps
install-build-deps: install-linux-build-deps install-macos-build-deps install-lint-build-deps
# Ensure the system pip is new enough. If we get an error about breaking system packages, it is.
sudo pip install 'pip>=22.2' || true

.PHONY: install-lint-build-deps
install-lint-build-deps:
ifeq ($(shell which apt-get),)
$(warning apt-get not found. Please install lint dependencies yourself.)
else
sudo $(APT) install python-apt-dev libapt-pkg-dev clang
endif

.PHONY: install-linux-build-deps
install-linux-build-deps:
ifneq ($(OS),Linux)
else ifeq ($(shell which apt-get),)
$(warning apt-get not found. Please install dependencies yourself.)
else
sudo $(APT) install skopeo
# Needed for integration testing the charm plugin.
sudo $(APT) install libyaml-dev python3-dev python3-pip python3-setuptools python3-venv python3-wheel
endif
ifneq ($(shell which snap),)
sudo snap install lxd
endif
ifneq ($(shell which lxd),)
sudo lxd init --auto
endif

.PHONY: install-macos-build-deps
install-macos-build-deps:
ifneq ($(OS),Darwin)
else ifeq ($(shell which brew),)
$(warning brew not installed. Please install dependencies yourself.)
else
brew install libgit2@1.7 # For building pygit2
sudo cp -R /usr/local/opt/libgit2@1.7/* /usr/local
brew install multipass
brew install skopeo
endif
Loading
Loading