Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.

Commit 5edde04

Browse files
authored
Merge pull request #38 from hatlabs/feat/use-shared-workflows
feat: migrate to shared-workflows
2 parents 47e7b4a + 7d5a9df commit 5edde04

6 files changed

Lines changed: 200 additions & 215 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# Calculate the next revision number for a given upstream version
3+
# Finds all git tags matching v<upstream-version>+<N> or v<upstream-version>+<N>_pre
4+
# Returns the next N value (highest N + 1), or 1 if no matching tags exist
5+
#
6+
# Usage: calculate-revision.sh <upstream-version>
7+
8+
set -euo pipefail
9+
10+
UPSTREAM_VERSION="${1:-}"
11+
12+
if [ -z "$UPSTREAM_VERSION" ]; then
13+
echo "Error: Upstream version is required" >&2
14+
echo "Usage: $0 <upstream-version>" >&2
15+
exit 1
16+
fi
17+
18+
# Remove 'v' prefix if present
19+
UPSTREAM_VERSION="${UPSTREAM_VERSION#v}"
20+
21+
# Find all tags matching the pattern: v{version}+{N} or v{version}+{N}_pre
22+
PATTERN="v${UPSTREAM_VERSION}+*"
23+
MATCHING_TAGS=$(git tag -l "$PATTERN" 2>/dev/null || true)
24+
25+
if [ -z "$MATCHING_TAGS" ]; then
26+
# No matching tags, this is the first build
27+
echo "1"
28+
exit 0
29+
fi
30+
31+
# Extract revision numbers from tags and find max
32+
MAX_REVISION=0
33+
while IFS= read -r tag; do
34+
# Extract the number between '+' and either end of string or '_'
35+
if [[ $tag =~ \+([0-9]+)(_.*)?$ ]]; then
36+
REVISION="${BASH_REMATCH[1]}"
37+
if [ "$REVISION" -gt "$MAX_REVISION" ]; then
38+
MAX_REVISION="$REVISION"
39+
fi
40+
fi
41+
done <<< "$MATCHING_TAGS"
42+
43+
# Return next revision number
44+
NEXT_REVISION=$((MAX_REVISION + 1))
45+
echo "$NEXT_REVISION"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Generate debian/changelog dynamically for CI builds
5+
# Usage: generate-changelog.sh --upstream <version> --revision <N>
6+
7+
UPSTREAM=""
8+
REVISION=""
9+
10+
while [[ $# -gt 0 ]]; do
11+
case $1 in
12+
--upstream)
13+
UPSTREAM="$2"
14+
shift 2
15+
;;
16+
--revision)
17+
REVISION="$2"
18+
shift 2
19+
;;
20+
*)
21+
echo "Error: Unknown option $1" >&2
22+
echo "Usage: $0 --upstream <version> --revision <N>" >&2
23+
exit 1
24+
;;
25+
esac
26+
done
27+
28+
if [ -z "$UPSTREAM" ] || [ -z "$REVISION" ]; then
29+
echo "Error: Both --upstream and --revision are required" >&2
30+
echo "Usage: $0 --upstream <version> --revision <N>" >&2
31+
exit 1
32+
fi
33+
34+
# Package name
35+
PACKAGE_NAME="halpi2-daemon"
36+
37+
# Debian version format: upstream-revision
38+
DEBIAN_VERSION="${UPSTREAM}-${REVISION}"
39+
40+
# Distribution (unstable for CI builds)
41+
DISTRIBUTION="unstable"
42+
43+
# Urgency
44+
URGENCY="medium"
45+
46+
# Maintainer information
47+
MAINTAINER_NAME="${MAINTAINER_NAME:-Hat Labs}"
48+
MAINTAINER_EMAIL="${MAINTAINER_EMAIL:-info@hatlabs.fi}"
49+
50+
# Date in RFC 2822 format
51+
DATE=$(date -R)
52+
53+
# Get recent changes from git log
54+
# Get commits since last published release tag
55+
LAST_TAG=$(git tag -l "v*" --sort=-version:refname | grep -v "_pre" | head -n1 || echo "")
56+
57+
if [ -n "$LAST_TAG" ]; then
58+
CHANGES=$(git log "${LAST_TAG}"..HEAD --pretty=format:" * %s" --no-merges || echo " * Build ${REVISION}")
59+
else
60+
# No previous tags, use recent commits
61+
CHANGES=$(git log -10 --pretty=format:" * %s" --no-merges || echo " * Build ${REVISION}")
62+
fi
63+
64+
# If no changes (shouldn't happen), use a default message
65+
if [ -z "$CHANGES" ]; then
66+
CHANGES=" * Build ${REVISION}"
67+
fi
68+
69+
# Generate debian/changelog entry
70+
cat > debian/changelog <<EOF
71+
${PACKAGE_NAME} (${DEBIAN_VERSION}) ${DISTRIBUTION}; urgency=${URGENCY}
72+
73+
${CHANGES}
74+
75+
-- ${MAINTAINER_NAME} <${MAINTAINER_EMAIL}> ${DATE}
76+
EOF
77+
78+
echo "Generated debian/changelog:"
79+
echo " Version: ${DEBIAN_VERSION}"
80+
echo " Distribution: ${DISTRIBUTION}"
81+
cat debian/changelog

.github/scripts/rename-packages.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Rename packages with distro+component suffix
5+
# Usage: rename-packages.sh --version <debian-version> --distro <distro> --component <component>
6+
#
7+
# This script handles the ARM64 architecture package naming for HALPI2 daemon
8+
9+
VERSION=""
10+
DISTRO=""
11+
COMPONENT=""
12+
13+
while [[ $# -gt 0 ]]; do
14+
case $1 in
15+
--version)
16+
VERSION="$2"
17+
shift 2
18+
;;
19+
--distro)
20+
DISTRO="$2"
21+
shift 2
22+
;;
23+
--component)
24+
COMPONENT="$2"
25+
shift 2
26+
;;
27+
*)
28+
echo "Error: Unknown option $1" >&2
29+
echo "Usage: $0 --version <debian-version> --distro <distro> --component <component>" >&2
30+
exit 1
31+
;;
32+
esac
33+
done
34+
35+
if [ -z "$VERSION" ] || [ -z "$DISTRO" ] || [ -z "$COMPONENT" ]; then
36+
echo "Error: All options are required" >&2
37+
exit 1
38+
fi
39+
40+
# Package name and architecture
41+
PACKAGE_NAME="halpi2-daemon"
42+
ARCH="arm64"
43+
44+
OLD_NAME="${PACKAGE_NAME}_${VERSION}_${ARCH}.deb"
45+
NEW_NAME="${PACKAGE_NAME}_${VERSION}_${ARCH}+${DISTRO}+${COMPONENT}.deb"
46+
47+
if [ -f "$OLD_NAME" ]; then
48+
echo "Renaming package: $OLD_NAME -> $NEW_NAME"
49+
mv "$OLD_NAME" "$NEW_NAME"
50+
echo "Package renamed successfully"
51+
else
52+
echo "Error: Expected package not found: $OLD_NAME" >&2
53+
echo "Available .deb files:" >&2
54+
ls -la *.deb 2>/dev/null || echo "None found" >&2
55+
exit 1
56+
fi

.github/workflows/main.yml

Lines changed: 9 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -4,156 +4,13 @@ on:
44
push:
55
branches: [main]
66

7-
permissions:
8-
contents: write
9-
10-
env:
11-
APT_DISTRO: ${{ vars.APT_DISTRO || 'trixie' }}
12-
APT_COMPONENT: ${{ vars.APT_COMPONENT || 'hatlabs' }}
13-
147
jobs:
15-
test:
16-
runs-on: ubuntu-latest
17-
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v6
20-
21-
- name: Run tests
22-
uses: ./.github/actions/run-tests
23-
24-
build-and-release:
25-
needs: test
26-
runs-on: ubuntu-latest-arm64
27-
steps:
28-
- name: Checkout code
29-
uses: actions/checkout@v6
30-
with:
31-
fetch-depth: 0
32-
33-
- name: Read version from VERSION
34-
id: version
35-
run: .github/scripts/read-version.sh
36-
37-
- name: Check if published release exists
38-
id: check
39-
run: .github/scripts/check-release-exists.sh "${{ steps.version.outputs.version }}" prerelease
40-
env:
41-
GH_TOKEN: ${{ github.token }}
42-
43-
- name: Build .deb package
44-
if: steps.check.outputs.action == 'create'
45-
uses: ./.github/actions/build-deb
46-
47-
- name: Rename package with distro+component suffix
48-
if: steps.check.outputs.action == 'create'
49-
run: |
50-
VERSION="${{ steps.version.outputs.version }}"
51-
OLD_NAME="halpi2-daemon_${VERSION}_arm64.deb"
52-
NEW_NAME="halpi2-daemon_${VERSION}_arm64+${APT_DISTRO}+${APT_COMPONENT}.deb"
53-
54-
if [ -f "$OLD_NAME" ]; then
55-
echo "📦 Renaming package: $(basename $OLD_NAME) → $(basename $NEW_NAME)"
56-
mv "$OLD_NAME" "$NEW_NAME"
57-
echo "✅ Package renamed successfully"
58-
echo "Package location: $NEW_NAME"
59-
else
60-
echo "❌ Error: Expected package not found: $OLD_NAME"
61-
exit 1
62-
fi
63-
64-
- name: Generate release notes
65-
if: steps.check.outputs.action == 'create'
66-
id: notes
67-
run: .github/scripts/generate-release-notes.sh "${{ steps.version.outputs.version }}" "${{ steps.version.outputs.tag_version }}" prerelease
68-
env:
69-
GH_TOKEN: ${{ github.token }}
70-
71-
- name: Delete existing pre-release
72-
if: steps.check.outputs.action == 'create'
73-
run: |
74-
TAG_VERSION="${{ steps.version.outputs.tag_version }}"
75-
if gh release view "v${TAG_VERSION}" &>/dev/null; then
76-
IS_PRERELEASE=$(gh release view "v${TAG_VERSION}" --json isPrerelease --jq '.isPrerelease')
77-
if [ "$IS_PRERELEASE" = "true" ]; then
78-
echo "🗑️ Deleting existing pre-release v${TAG_VERSION}"
79-
gh release delete "v${TAG_VERSION}" --yes --cleanup-tag
80-
fi
81-
fi
82-
env:
83-
GH_TOKEN: ${{ github.token }}
84-
85-
- name: Create pre-release
86-
if: steps.check.outputs.action == 'create'
87-
run: |
88-
TAG_VERSION="${{ steps.version.outputs.tag_version }}"
89-
if ! ls *.deb 1> /dev/null 2>&1; then
90-
echo "❌ Error: No .deb files found"
91-
exit 1
92-
fi
93-
echo "📦 Creating pre-release v${TAG_VERSION}"
94-
gh release create "v${TAG_VERSION}" \
95-
--prerelease \
96-
--title "v${TAG_VERSION} (Pre-release)" \
97-
--notes-file release_notes.md \
98-
*.deb
99-
echo "✅ Pre-release created successfully"
100-
env:
101-
GH_TOKEN: ${{ github.token }}
102-
103-
- name: Create draft release
104-
if: steps.check.outputs.action == 'create'
105-
run: |
106-
VERSION="${{ steps.version.outputs.version }}"
107-
TAG_VERSION="${{ steps.version.outputs.tag_version }}"
108-
109-
# Check if draft release already exists
110-
if gh release view "v${VERSION}" &>/dev/null; then
111-
IS_DRAFT=$(gh release view "v${VERSION}" --json isDraft --jq '.isDraft')
112-
IS_PRERELEASE=$(gh release view "v${VERSION}" --json isPrerelease --jq '.isPrerelease')
113-
114-
if [ "$IS_DRAFT" = "true" ] && [ "$IS_PRERELEASE" = "false" ]; then
115-
echo "Draft release v${VERSION} already exists, skipping creation"
116-
fi
117-
else
118-
# Generate release notes for draft
119-
.github/scripts/generate-release-notes.sh "${VERSION}" "${VERSION}" draft
120-
121-
echo "📋 Creating draft release v${VERSION} with .deb package"
122-
gh release create "v${VERSION}" \
123-
--draft \
124-
--title "v${VERSION}" \
125-
--notes-file release_notes.md \
126-
*.deb
127-
echo "✅ Draft release created successfully with .deb attached"
128-
fi
129-
env:
130-
GH_TOKEN: ${{ github.token }}
131-
132-
- name: Dispatch to APT repository
133-
if: steps.check.outputs.action == 'create'
134-
uses: peter-evans/repository-dispatch@v4
135-
with:
136-
token: ${{ secrets.REPO_DISPATCH_PAT }}
137-
repository: hatlabs/apt.hatlabs.fi
138-
event-type: package-updated
139-
client-payload: |
140-
{
141-
"repository": "${{ github.repository }}",
142-
"distro": "${{ env.APT_DISTRO }}",
143-
"channel": "unstable",
144-
"component": "${{ env.APT_COMPONENT }}"
145-
}
146-
147-
- name: Report success
148-
if: steps.check.outputs.action == 'create'
149-
run: |
150-
VERSION="${{ steps.version.outputs.version }}"
151-
TAG_VERSION="${{ steps.version.outputs.tag_version }}"
152-
echo "=== Main Branch CI/CD Complete ==="
153-
echo "Package version: ${VERSION}"
154-
echo "Release tag: v${TAG_VERSION}"
155-
echo "Release URL: https://github.com/${{ github.repository }}/releases/tag/v${TAG_VERSION}"
156-
echo ""
157-
echo "✅ Pre-release created with .deb package"
158-
echo "✅ Draft release created with .deb attached"
159-
echo "✅ Dispatched to apt.hatlabs.fi unstable channel"
8+
build-release:
9+
uses: hatlabs/shared-workflows/.github/workflows/build-release.yml@main
10+
with:
11+
package-name: halpi2-daemon
12+
package-description: 'HALPI2 hardware daemon (Python implementation)'
13+
apt-component: hatlabs
14+
runs-on: ubuntu-latest-arm64
15+
secrets:
16+
APT_REPO_PAT: ${{ secrets.APT_REPO_PAT }}

.github/workflows/pr.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,8 @@ name: Pull Request Checks
22

33
on:
44
pull_request:
5-
branches: [ main ]
6-
7-
permissions:
8-
contents: read
5+
branches: [main]
96

107
jobs:
11-
tests:
12-
runs-on: ubuntu-latest
13-
14-
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v6
17-
18-
- name: Run tests
19-
uses: ./.github/actions/run-tests
8+
checks:
9+
uses: hatlabs/shared-workflows/.github/workflows/pr-checks.yml@main

0 commit comments

Comments
 (0)