diff --git a/.woodpecker/release-pr-and-publish.yaml b/.woodpecker/release-pr-and-publish.yaml new file mode 100644 index 0000000..92dc7f8 --- /dev/null +++ b/.woodpecker/release-pr-and-publish.yaml @@ -0,0 +1,45 @@ +when: + - repo: wvhulle/bootvine + event: [push, manual] + branch: main + +depends_on: + - rust-and-flake-checks + +clone: + - name: clone-with-history-and-tags + image: woodpeckerci/plugin-git + settings: + depth: 0 + partial: false + tags: true + +variables: + - &release_env + NIX_CONFIG: | + experimental-features = nix-command flakes + build-users-group = + accept-flake-config = true + GIT_AUTHOR_NAME: release-plz + GIT_AUTHOR_EMAIL: willemvanhulle@protonmail.com + GIT_COMMITTER_NAME: release-plz + GIT_COMMITTER_EMAIL: willemvanhulle@protonmail.com + CODEBERG_TOKEN: + from_secret: codeberg_token + CARGO_REGISTRY_TOKEN: + from_secret: cargo_registry_token + +steps: + - name: publish-crate-and-tag-release + image: nixos/nix:latest + environment: *release_env + commands: + - git remote set-url origin "https://wvhulle:$${CODEBERG_TOKEN}@codeberg.org/$${CI_REPO}.git" + - git checkout -B main "$${CI_COMMIT_SHA}" + - nix run .#release-plz-release + + - name: update-release-pr + image: nixos/nix:latest + environment: *release_env + commands: + - nix run .#release-plz-release-pr diff --git a/docs/development.md b/docs/development.md index 2501f58..ebd7777 100644 --- a/docs/development.md +++ b/docs/development.md @@ -36,6 +36,22 @@ pull requests. Builds on `main` are pushed to the `wvhulle` [Cachix](https://www `nixConfig` in `flake.nix` offers as a substituter. The two VM checks need KVM, which Codeberg's runners lack, so they only run locally. +## Releases + +`.woodpecker/release-pr-and-publish.yaml` runs +[release-plz](https://release-plz.dev) after the checks pass on `main`. It +keeps a pull request labelled `release` open on Codeberg that bumps the version +in `Cargo.toml` and adds the new commits to `CHANGELOG.md`. Only `feat`, `fix` +and `perf` commits open one; a `!` or a `BREAKING CHANGE` footer bumps the +minor version while bootvine is below 1.0. Merging that pull request publishes +the crate to crates.io, tags the merge `v` and creates a Codeberg +release with the changelog. Settings are in `release-plz.toml`. + +The pipeline needs two Woodpecker secrets: `codeberg_token`, a Codeberg access +token with repository write access, and `cargo_registry_token`, a crates.io +token that may publish new crates and updates. Preview the next release +locally from the dev shell with `release-plz update`. + ## Testing | What | Command | diff --git a/flake.nix b/flake.nix index 1c58dfe..777efef 100644 --- a/flake.nix +++ b/flake.nix @@ -36,12 +36,16 @@ inherit system; overlays = [ (import rust-overlay) ]; }; - craneLib = (crane.mkLib pkgs).overrideToolchain ( - p: p.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml - ); + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; in f { - inherit system pkgs craneLib; + inherit + system + pkgs + craneLib + rustToolchain + ; builds = import ./crane-builds.nix { inherit lib pkgs craneLib; }; } ); @@ -75,9 +79,34 @@ pkgs, system, builds, + rustToolchain, ... }: + let + runReleasePlzOnCodeberg = subcommand: description: { + type = "app"; + meta.description = description; + program = lib.getExe ( + pkgs.writeShellApplication { + name = "release-plz-${subcommand}"; + runtimeInputs = [ + pkgs.release-plz + pkgs.gitMinimal + pkgs.pkg-config + pkgs.stdenv.cc + rustToolchain + ]; + text = '' + export PKG_CONFIG_PATH="${lib.getDev pkgs.dbus}/lib/pkgconfig" + exec release-plz ${subcommand} --forge gitea --git-token "$CODEBERG_TOKEN" + ''; + } + ); + }; + in { + release-plz-release = runReleasePlzOnCodeberg "release" "Publish unpublished versions to crates.io and tag them with a Codeberg release"; + release-plz-release-pr = runReleasePlzOnCodeberg "release-pr" "Open or update the Codeberg pull request that bumps the version and changelog"; sample-machine-vm = { type = "app"; meta.description = "Boot a sample machine with bootvine and slow sample units in QEMU"; @@ -156,6 +185,8 @@ packages = [ pkgs.prek pkgs.convco + pkgs.release-plz + pkgs.git-cliff ]; }; } diff --git a/release-plz.toml b/release-plz.toml new file mode 100644 index 0000000..a32a212 --- /dev/null +++ b/release-plz.toml @@ -0,0 +1,36 @@ +[workspace] +release_always = false +semver_check = false +git_release_type = "prod" +release_commits = "^(feat|fix|perf)[(:!]" +pr_labels = ["release"] + +[[package]] +name = "bootvine" +changelog_path = "CHANGELOG.md" +git_tag_name = "v{{ version }}" +git_release_name = "v{{ version }}" + +[[package]] +name = "xtask" +release = false + +[changelog] +tag_pattern = "v[0-9].*" +sort_commits = "oldest" +protect_breaking_commits = true +commit_parsers = [ + { message = "^feat", group = "Added" }, + { message = "^fix", group = "Fixed" }, + { message = "^doc", group = "Documentation" }, + { message = "^perf", group = "Performance" }, + { message = "^refactor", group = "Changed" }, + { message = "^style", group = "Changed" }, + { message = "^test", group = "Testing" }, + { message = "^chore: release", skip = true }, + { message = "^chore", group = "Miscellaneous" }, + { message = "^ci", group = "CI" }, + { message = "^build", group = "Build" }, + { message = "^[Mm]erge", skip = true }, + { message = ".*", group = "Other" }, +]