Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/release-verify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

## Verify

- `Koppel-Setup.exe` is not code signed yet, so Windows SmartScreen warns about it. Check it against `SHA256SUMS`.
- `SHA256SUMS` is signed with cosign, keyless, by this repository's release workflow. Check the signature, then the files:

```sh
cosign verify-blob --bundle SHA256SUMS.sigstore.json \
--certificate-identity-regexp '^https://github.com/matumi-software/koppel/.github/workflows/release.yml@refs/tags/v' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com SHA256SUMS
sha256sum -c SHA256SUMS --ignore-missing
```

- The image is signed the same way:

```sh
cosign verify matumisoftware/koppel:@VERSION@ \
--certificate-identity-regexp '^https://github.com/matumi-software/koppel/.github/workflows/release.yml@refs/tags/v' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
```
13 changes: 13 additions & 0 deletions .github/scripts/changelog-section.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Prints the CHANGELOG.md section of a version, without its heading: .github/scripts/changelog-section.sh 0.2.1
# Fails when CHANGELOG.md has no "## <version>" heading or the section is empty.
set -eu
cd "$(dirname "$0")/../.."
version=${1:?usage: $0 <version>}
body=$(awk -v v="$version" '
/^## / { if (on) exit; on = ($2 == v) ; next }
on { print }
' CHANGELOG.md | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}')
if ! grep -qE "^## ${version//./\.}( |$)" CHANGELOG.md; then echo "CHANGELOG.md has no section for $version." >&2; exit 1; fi
[ -n "$(printf '%s' "$body" | tr -d '[:space:]')" ] || { echo "The CHANGELOG.md section for $version is empty." >&2; exit 1; }
printf '%s\n' "$body" | sed '/./,$!d'
58 changes: 58 additions & 0 deletions .github/scripts/release-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# The released version appears by hand in the three composes, the README, docs/windows.md and
# docs/installers.md. The build reads it from src/Cargo.toml only, so a release has to find them all moved.
#
# .github/scripts/release-versions.sh check [<version>] fail and list every place that names another version
# .github/scripts/release-versions.sh write [<version>] rewrite those places to the version
#
# Without <version> it takes the workspace version from src/Cargo.toml. The places are the image tag
# (`matumisoftware/koppel:<version>`), the .deb file names and release download path in the README, and the
# README's "version <version> is the latest release". Prose such as "a 0.2.0 machine" is not touched: it
# names a version on purpose.
set -eu
cd "$(dirname "$0")/../.."

mode=${1:-}
case "$mode" in check | write) ;; *) echo "usage: $0 check|write [<version>]" >&2; exit 2 ;; esac
version=${2:-$(sed -n '/^\[workspace\.package\]/,/^\[/{s/^version *= *"\(.*\)"/\1/p}' src/Cargo.toml | head -1)}
[ -n "$version" ] || { echo "No version found in src/Cargo.toml." >&2; exit 2; }

ver='[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]*[0-9A-Za-z])?'
files="README.md docs/windows.md docs/installers.md src/installer/docker/docker-compose.yml
src/installer/docker/docker-compose.windows-client.yml src/installer/docker/docker-compose.windows-server.yml"
patterns=(
"matumisoftware/koppel:$ver"
"koppel_${ver}_(amd64|arm64|armhf)\.deb"
"releases/download/v$ver/"
"version $ver is the latest release"
)

if [ "$mode" = write ]; then
# Each pattern's version is the only part that changes, so rewrite it with the same lead-in and tail.
for f in $files; do
sed -E -i \
-e "s#(matumisoftware/koppel:)$ver#\1$version#g" \
-e "s#(koppel_)${ver}(_(amd64|arm64|armhf)\.deb)#\1$version\3#g" \
-e "s#(releases/download/v)$ver/#\1$version/#g" \
-e "s#(version )$ver( is the latest release)#\1$version\3#g" \
"$f"
done
echo "Wrote $version."
fi

# Compare every match with the version. Anything left over is a place that still names another one.
fail=0
for f in $files; do
for p in "${patterns[@]}"; do
while IFS= read -r hit; do
[ -n "$hit" ] || continue
found=$(printf '%s' "$hit" | grep -oE "$ver" | head -1)
if [ "$found" != "$version" ]; then
echo "::error file=$f::$f names $found ('$hit'), the release is $version."
fail=1
fi
done < <(grep -oE "$p" "$f" || true)
done
done
[ "$fail" -eq 0 ] && echo "Every place names $version."
exit "$fail"
238 changes: 238 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
# Cuts a release from an annotated v* tag: checks the tag against the workspace version, the places that name
# the version and CHANGELOG.md, builds the three .deb files, the image and Koppel-Setup.exe, then pushes and
# signs the image, writes SHA256SUMS (signed too) and creates the GitHub release with the CHANGELOG section.
#
# git tag -a v0.2.1 -m "Koppel 0.2.1" && git push origin v0.2.1
#
# Run by hand (Actions, Release, Run workflow) it is a dry run: the same checks and builds, nothing pushed,
# signed or published. Use it to find a broken build before tagging.
#
# Repository secrets the owner adds (Settings, Secrets and variables, Actions), both for Docker Hub:
# DOCKERHUB_USERNAME the account that owns matumisoftware/koppel
# DOCKERHUB_TOKEN an access token for it with Read & Write on matumisoftware/koppel
# A tag run checks both first and stops, before building or pushing anything, when one is missing. Signing
# needs no secret: cosign signs keyless with this workflow's own GitHub identity, which is why only
# `publish` has `id-token: write`.
#
# Every action is pinned by commit SHA with its version in a comment, as in ci.yml.
name: Release

on:
push:
tags: ["v*"]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false

env:
IMAGE: matumisoftware/koppel

jobs:
verify:
name: Verify the tag
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
version: ${{ steps.version.outputs.version }}
prerelease: ${{ steps.version.outputs.prerelease }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Registry credentials
if: github.event_name == 'push'
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
missing=""
[ -n "$DOCKERHUB_USERNAME" ] || missing="$missing DOCKERHUB_USERNAME"
[ -n "$DOCKERHUB_TOKEN" ] || missing="$missing DOCKERHUB_TOKEN"
if [ -n "$missing" ]; then
echo "::error::Missing repository secrets:$missing. Add them under Settings, Secrets and variables, Actions, then run this workflow again for the tag. Nothing was built, pushed or published."
exit 1
fi
- name: Tag, version, places and changelog
id: version
run: |
set -eu
workspace=$(sed -n '/^\[workspace\.package\]/,/^\[/{s/^version *= *"\(.*\)"/\1/p}' src/Cargo.toml | head -1)
if [ "$GITHUB_EVENT_NAME" = push ]; then
tag=$GITHUB_REF_NAME
[ "$(git cat-file -t "refs/tags/$tag")" = tag ] || { echo "::error::$tag is a lightweight tag. Release from an annotated one: git tag -a $tag -m ..."; exit 1; }
[ "$tag" = "v$workspace" ] || { echo "::error::The tag is $tag but src/Cargo.toml says $workspace."; exit 1; }
git fetch --no-tags origin main
git merge-base --is-ancestor "$GITHUB_SHA" origin/main || { echo "::error::$tag is not on main."; exit 1; }
fi
echo "version=$workspace" >> "$GITHUB_OUTPUT"
case "$workspace" in *-*) echo "prerelease=true" >> "$GITHUB_OUTPUT" ;; *) echo "prerelease=false" >> "$GITHUB_OUTPUT" ;; esac
.github/scripts/release-versions.sh check "$workspace"
mkdir "$RUNNER_TEMP/notes"
.github/scripts/changelog-section.sh "$workspace" > "$RUNNER_TEMP/notes/changelog-section.md"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: notes
path: ${{ runner.temp }}/notes
retention-days: 7

packages:
name: Linux packages and image
needs: verify
runs-on: ubuntu-latest
timeout-minutes: 75
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Build the .deb files
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: src
file: src/installer/docker/Dockerfile
target: linux-packages
outputs: type=local,dest=${{ runner.temp }}/packages
cache-from: type=gha,scope=koppel-docker
cache-to: type=gha,scope=koppel-docker,mode=max
- name: Check the packages
env:
VERSION: ${{ needs.verify.outputs.version }}
run: |
set -eu
for arch in amd64 arm64 armhf; do
deb="$RUNNER_TEMP/packages/koppel_${VERSION}_${arch}.deb"
[ -f "$deb" ] || { echo "::error::$deb was not built."; exit 1; }
dpkg-deb --info "$deb" | grep -E 'Package|Version|Architecture'
done
# Builds the image for all three platforms and keeps it in the cache; `publish` pushes it from there.
- name: Build the image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: src
file: src/installer/docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v6
outputs: type=cacheonly
cache-from: type=gha,scope=koppel-docker
cache-to: type=gha,scope=koppel-docker,mode=max
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: debs
path: ${{ runner.temp }}/packages/*.deb
if-no-files-found: error
retention-days: 7

windows:
name: Windows installer
needs: verify
runs-on: windows-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6
with:
package_json_file: src/ui/package.json
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version-file: src/ui/.nvmrc
cache: pnpm
cache-dependency-path: src/ui/pnpm-lock.yaml
- name: Install Rust
working-directory: src
shell: bash
run: |
rustup toolchain install
rustup show active-toolchain
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
with:
workspaces: src
key: installer
# The notices script needs cargo-about, at the version the Linux build uses.
- name: Install cargo-about
working-directory: src
shell: bash
run: |
version=$(sed -n 's/^ARG CARGO_ABOUT_VERSION=//p' installer/docker/Dockerfile)
cargo install --locked --features cli "cargo-about@$version"
- name: Build Koppel-Setup.exe
working-directory: src
shell: pwsh
run: ./installer/windows/build.ps1
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: installer
path: src/installer/windows/bin/Koppel-Setup.exe
if-no-files-found: error
retention-days: 7

publish:
name: Push, sign and publish
needs: [verify, packages, windows]
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
id-token: write
env:
VERSION: ${{ needs.verify.outputs.version }}
PRERELEASE: ${{ needs.verify.outputs.prerelease }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: ${{ runner.temp }}/artifacts
merge-multiple: true
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# `latest` follows only a final release, never a pre-release tag such as v0.3.0-rc.1.
- name: Image tags
id: tags
run: |
tags="$IMAGE:$VERSION"
[ "$PRERELEASE" = true ] || tags="$tags"$'\n'"$IMAGE:latest"
{ echo 'tags<<END'; echo "$tags"; echo END; } >> "$GITHUB_OUTPUT"
- name: Push the image
id: push
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: src
file: src/installer/docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v6
push: true
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha,scope=koppel-docker
- uses: sigstore/cosign-installer@756fe2d284c7292c4e9b62c8a28f1e5629c59532 # v4.1.3
- name: Sign the image
env:
DIGEST: ${{ steps.push.outputs.digest }}
run: cosign sign --yes "$IMAGE@$DIGEST"
- name: Checksums
working-directory: ${{ runner.temp }}/artifacts
run: |
set -eu
ls -l
sha256sum koppel_*.deb Koppel-Setup.exe > SHA256SUMS
cat SHA256SUMS
cosign sign-blob --yes --bundle SHA256SUMS.sigstore.json SHA256SUMS
- name: Release notes
run: |
set -eu
{ cat "$RUNNER_TEMP/artifacts/changelog-section.md"; sed "s/@VERSION@/$VERSION/" .github/release-verify.md; } > "$RUNNER_TEMP/release-notes.md"
- name: Create the release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
working-directory: ${{ runner.temp }}/artifacts
run: |
set -eu
flags=""
[ "$PRERELEASE" != true ] || flags="--prerelease"
gh release create "$TAG" --repo "$GITHUB_REPOSITORY" --verify-tag --title "Koppel $VERSION" \
--notes-file "$RUNNER_TEMP/release-notes.md" $flags \
koppel_*.deb Koppel-Setup.exe SHA256SUMS SHA256SUMS.sigstore.json
34 changes: 24 additions & 10 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,34 @@ To release:

1. Set the version under `[workspace.package]` in `src/Cargo.toml`. The Windows installer, the `.deb`
files and the image all take it from there.
2. Set the image tag in the three composes in `src/installer/docker` (`docker-compose.yml`,
`docker-compose.windows-client.yml`, `docker-compose.windows-server.yml`), in the build command in
`docs/windows.md` and in the README. They name the released version.
2. Move the other places that name it: run `.github/scripts/release-versions.sh write` (the image tag in the
three composes in `src/installer/docker`, in `docs/windows.md` and `docs/installers.md`, and the README's
status line, image tag and `.deb` names). The release workflow runs the same script with `check` and stops
when a place still names another version.
3. For a new usbip-win2 version, run `src/installer/windows/export-usbip-win2.ps1` (it rewrites `SHA256SUMS`; `-SumsOnly` regenerates only that), then add the new version to `$usbipWin2Pins` in `src/installer/windows/build.ps1` (signer thumbprints and the hashes of the two unsigned DLLs, taken from a copy you checked by hand: `SHA256SUMS` alone could be regenerated to match a swapped file) and check which CLI11 tag its licence comes from.
4. Add the version to `CHANGELOG.md`.
5. Build and push the image for all three platforms, from `src/`, with the version and `latest`:
4. Add the version to `CHANGELOG.md` as `## <version> (<date>)`. Its section becomes the release notes.
5. Merge to `main`, then tag the merge commit with an annotated tag and push it:

```sh
docker buildx build -f installer/docker/Dockerfile --platform linux/amd64,linux/arm64,linux/arm/v6 \
-t matumisoftware/koppel:<version> -t matumisoftware/koppel:latest --push .
git tag -a v<version> -m "Koppel <version>"
git push origin v<version>
```
6. Build the three `.deb` files with `src/installer/linux/build.ps1` and `Koppel-Setup.exe` with
`src/installer/windows/build.ps1`, and publish them. Record the image size per platform in the release
notes.

`.github/workflows/release.yml` takes it from there. It fails fast unless the tag is annotated, equals the
workspace version and sits on `main`, the places in step 2 agree and `CHANGELOG.md` has the section. It then builds the three `.deb` files, the image for all three platforms and
`Koppel-Setup.exe` (on a Windows runner, unsigned: the release notes say so), pushes the image as
`matumisoftware/koppel:<version>` and `latest` (`latest` only for a final version, not `-rc` and the like),
signs the image and `SHA256SUMS` with cosign (keyless, through the workflow's own GitHub identity, so no
signing secret), and creates the GitHub release with the changelog section, the files, `SHA256SUMS` and its
signature bundle. A tag is never moved (the release tags ruleset forbids it): a failed release is fixed
with a new patch version, or by re-running the failed jobs while the tag has no release yet.

The push needs two repository secrets, `DOCKERHUB_USERNAME` and `DOCKERHUB_TOKEN` (a Docker Hub access
token with Read & Write on `matumisoftware/koppel`). Until both are set, a tag run stops in its first job,
before building or pushing anything. Without them, release by hand: `docker buildx build -f installer/docker/Dockerfile --platform linux/amd64,linux/arm64,linux/arm/v6 -t matumisoftware/koppel:<version> -t matumisoftware/koppel:latest --push .` from `src/`,
`src/installer/linux/build.ps1` and `src/installer/windows/build.ps1`, and publish the files.
6. Record the image size per platform in the release notes. To try the builds before tagging, run the Release
workflow by hand from the Actions tab: it is a dry run that builds everything and publishes nothing.

## The Rust workspace

Expand Down
Loading