Skip to content

Commit

Permalink
Merge pull request #261 from canonical/automated-versioning-scheme
Browse files Browse the repository at this point in the history
Automate versioning scheme for the client cargo and Debian packages
  • Loading branch information
nadzyah authored Dec 16, 2024
2 parents 5524c84 + 6edd421 commit 80c8025
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
branches: ["main"]
paths:
- "server/**"
- ".github/workflows/publish_server.yml"
- ".github/workflows/publish_server.yaml"
workflow_dispatch:
schedule:
- cron: '0 0 * * 0' # Rebuild every Sunday at 00:00
Expand Down Expand Up @@ -62,3 +62,4 @@ jobs:
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
upload-image: "true"
tag-prefix: "hwapi"
46 changes: 46 additions & 0 deletions .github/workflows/test_hwlib_debian_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,57 @@ concurrency:


jobs:
validate-version:
runs-on: [self-hosted, linux, large, noble, x64]
defaults:
run:
working-directory: client
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Get version from git tag
id: get-version
run: |
VERSION=$(git describe --tags --match 'v*.*.*' --dirty)
if [[ $VERSION == *-dirty ]]; then
echo "Version includes -dirty. Ensure working tree is clean before building."
exit 1
fi
# Extract base version (strip 'v', commit count, and hash)
BASE_VERSION=$(echo "$VERSION" | sed -E 's/^v([0-9]+\.[0-9]+\.[0-9]+)(-.*)?$/\1/')
echo "version=$BASE_VERSION" >> $GITHUB_OUTPUT
echo "Git tag base version: $BASE_VERSION"
- name: Check hwlib and hwctl Cargo versions
run: |
echo "Using Git tag version: ${{ steps.get-version.outputs.version }}"
for manifest in hwlib/Cargo.toml hwctl/Cargo.toml; do
CARGO_VERSION=$(cargo metadata --manifest-path "$manifest" --no-deps --format-version 1 | jq -r '.packages[0].version')
if [[ $CARGO_VERSION != ${{ steps.get-version.outputs.version }} ]]; then
echo "Version mismatch in $manifest: $CARGO_VERSION (expected ${{ steps.get-version.outputs.version }})"
exit 1
fi
done
- name: Check Debian changelog version
run: |
echo "Using Git tag version: ${{ steps.get-version.outputs.version }}"
DEBIAN_VERSION=$(dpkg-parsechangelog --show-field Version | cut -d'~' -f1)
if [[ $DEBIAN_VERSION != ${{ steps.get-version.outputs.version }} ]]; then
echo "Debian changelog version mismatch: $DEBIAN_VERSION (expected ${{ steps.get-version.outputs.version }})"
exit 1
fi
build:
runs-on: [self-hosted, linux, large, noble, x64]
defaults:
run:
working-directory: client
needs: [validate-version]
steps:
- name: Checkout the repository
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 45 additions & 3 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ installed on your system:
sudo apt-get install -y debhelper dh-cargo devscripts
```

### Building the rust lib
### Creating a new version

First, generate update to the changelog file using the `dch` tool:
To create a new version of the client package, follow these steps:

1. Update the Changelog
Generate update to the changelog file using the `dch` tool:

```bash
export [email protected]
Expand All @@ -121,7 +124,46 @@ dch -i # increment release number
dch -r # create release
```

Then you need to vendor the Rust dependencies:
2. Versioning Scheme

We follow the `MAJOR.MINOR.PATCH` semantic versioning convention for
this package:

* `MAJOR`: Incremented for incompatible API changes or significant functionality updates.
* `MINOR`: Incremented for backward-compatible feature additions.
* `PATCH`: Incremented for backward-compatible bug fixes.


For pre-releases targeted at a PPA, append the `~ppaN` suffix to the
version, where `N` represents the build number (e.g., `1.2.3~ppa1`). Once
the package is approved for publication to the main repository, remove
the `~ppaN` suffix to finalize the version.

3. Create a Matching Git Tag

Ensure the version is correctly tagged in Git. The tag should follow
the format `vMAJOR.MINOR.PATCH` and must be annotated to the same
commit as the changelog entry:

```
git tag -a v1.2.3 <commit_hash>
git push origin v1.2.3
```

4. Update Cargo Versions

If the new version includes changes to the MAJOR, MINOR, or PATCH
version numbers, update the version fields in the following files:

* `hwlib/Cargo.toml`
* `hwctl/Cargo.toml`

Make sure to commit these changes along with the updated changelog.

### Building the client package

After generating a new version, you need to vendor the Rust
dependencies:

```bash
./debian/vendor-rust.sh
Expand Down
7 changes: 7 additions & 0 deletions client/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
rust-hwlib (0.9.0~ppa1) oracular; urgency=medium

* Release 0.9.0 version of the client.
* Fix error-handling in hwctl.

-- Nadzeya Hutsko <[email protected]> Tue, 10 Dec 2024 16:40:46 +0200

rust-hwlib (0.0.1~ppa3) oracular; urgency=medium

* Provide both hwlib library and hwctl CLI tool.
Expand Down
4 changes: 2 additions & 2 deletions client/hwctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "hwctl"
description = "hwlib backed CLI tool for collecting and sending hardware information to hwapi to find testing status of device models"
license = "GPL-3.0-only"
version = "0.1.0"
version = "0.9.0"
edition = "2021"

[package.metadata.vendor-filter]
Expand All @@ -12,6 +12,6 @@ all-features = false

[target.'cfg(target_os = "linux")'.dependencies]
tokio = { version = "1.38.0", features = ["rt", "macros"], default-features = false }
hwlib = { path = "../hwlib", version = "0.1.0" }
hwlib = { path = "../hwlib" }
serde_json = "~1.0.0"
anyhow = "~1.0.0"
2 changes: 1 addition & 1 deletion client/hwlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "hwlib"
description = "Collects and sends hardware information to hwapi to find testing status of the device model"
license = "GPL-3.0-only"
version = "0.1.0"
version = "0.9.0"
edition = "2021"
authors = [
"Canonical Hardware Certification <[email protected]>",
Expand Down

0 comments on commit 80c8025

Please sign in to comment.