diff --git a/.gitignore b/.gitignore index b240aa10ae..c3d009c0a4 100644 --- a/.gitignore +++ b/.gitignore @@ -177,3 +177,6 @@ dmypy.json # .NET build artifacts /tests/**/bin/ /tests/**/obj/ + +# Canonical workshop +/.workshop.lock diff --git a/.workshop/dev.yaml b/.workshop/dev.yaml new file mode 100644 index 0000000000..c0c63e3294 --- /dev/null +++ b/.workshop/dev.yaml @@ -0,0 +1,43 @@ +name: dev +base: ubuntu@24.04 +sdks: + - name: uv + channel: latest/stable + - name: copilot + channel: latest/stable + - name: project-starcraft +actions: + setup: make setup + lint: make lint + format: make format + test: make test + test-fast: make test-fast + test-coverage: make test-coverage + schema: make schema + clean: make clean + lock: | + uv lock "$@" + make setup + install-branch: | + set -euo pipefail + if [[ $# -lt 2 ]]; then + echo "Usage: install-branch " >&2 + echo "" >&2 + echo "Examples:" >&2 + echo " workshop run -- install-branch craft-parts main" >&2 + echo " workshop run -- install-branch https://github.com/user/repo.git main" >&2 + exit 1 + fi + + REPO_OR_URL=$1 + BRANCH=$2 + + # Check if it's a URL (contains :// or ends with .git) + if [[ $REPO_OR_URL =~ "://" ]] || [[ $REPO_OR_URL == *.git ]]; then + REPO_URL=$REPO_OR_URL + else + # Assume it's a package name, use canonical org by default + REPO_URL="https://github.com/canonical/${REPO_OR_URL}" + fi + + uv pip install "git+${REPO_URL}@${BRANCH}" diff --git a/.workshop/starcraft/hooks/setup-base b/.workshop/starcraft/hooks/setup-base new file mode 100644 index 0000000000..b68d8df4ad --- /dev/null +++ b/.workshop/starcraft/hooks/setup-base @@ -0,0 +1,2 @@ +apt-get update +apt-get install make diff --git a/.workshop/starcraft/hooks/setup-project b/.workshop/starcraft/hooks/setup-project new file mode 100644 index 0000000000..5732bef59b --- /dev/null +++ b/.workshop/starcraft/hooks/setup-project @@ -0,0 +1,3 @@ +uv tool install ruff +uv tool install ty +make setup diff --git a/.workshop/starcraft/sdk.yaml b/.workshop/starcraft/sdk.yaml new file mode 100644 index 0000000000..f5248a2fee --- /dev/null +++ b/.workshop/starcraft/sdk.yaml @@ -0,0 +1,13 @@ +# For details: https://canonical-workshop.readthedocs-hosted.com/latest/explanation/sdks/sdks/#sketch-sdk +name: starcraft +plugs: +# Use this configuration to mount a host directory to the workshop +# models: +# interface: mount +# workshop-target: /home/workshop/models +slots: +# Use this configuration to expose a port, then add a corresponding system SDK plug +# More details: https://canonical-workshop.readthedocs-hosted.com/latest/how-to/customize-workshops/forward-ports/ +# my-web-server: +# interface: tunnel +# endpoint: 8080 diff --git a/docs/contribute/development.rst b/docs/contribute/development.rst index e649d5179d..818d222ee1 100644 --- a/docs/contribute/development.rst +++ b/docs/contribute/development.rst @@ -69,6 +69,59 @@ Inside the project directory, set up the development environment: If these commands complete without error, your environment is ready. +Develop with Workshop +--------------------- + +.. admonition:: Work in progress + :class: caution + + Workshop integration for Snapcraft is under active development. Some + features may be incomplete or subject to change. + +Local development environments require periodic maintenance and debugging. You can +instead develop inside a sandbox, where the required development software +is pre-installed and immutable. Snapcraft provides a development image that's +controlled with `Workshop `__. + +With the `Workshop Snap `__ installed, start the +development environment by running ``workshop launch dev`` from within the Snapcraft +directory. When the workshop starts, it automatically runs ``make setup`` inside the +container. From there, use the pre-configured actions to carry out common +development tasks: + +.. code-block:: bash + + workshop run -- setup # re-run the virtual environment setup + workshop run -- lint # run all linters + workshop run -- format # run the autoformatters + workshop run -- test # run the full test suite + workshop run -- test-fast # run the fast test suite + workshop run -- test-coverage # run tests with a coverage report + workshop run -- schema # regenerate the JSON schema + workshop run -- clean # remove temporary build artifacts + +Two additional actions support dependency work. + +The ``lock`` action runs ``uv lock`` with any arguments you pass, then re-runs +``make setup``: + +.. code-block:: bash + + workshop run -- lock --upgrade-package craft-parts + +The ``install-branch`` action installs a dependency directly from a Git branch. Pass a +short package name (resolves to the canonical GitHub organization by default) +or a full repository URL: + +.. code-block:: bash + + workshop run -- install-branch craft-parts main + workshop run -- install-branch https://github.com/user/craft-parts.git feat/my-fix + +Workshop provides most of the features needed for developing Snapcraft. Read the +`Workshop tutorial `__ +to learn what else Workshop can do. + Choose a task -------------