Skip to content

Commit e4e361a

Browse files
committed
Add package-build, release GitHub workflows
1 parent 02b0da4 commit e4e361a

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: package-build
2+
on:
3+
pull_request:
4+
push:
5+
tags:
6+
- 'v*'
7+
permissions:
8+
actions: read
9+
contents: read
10+
pull-requests: write
11+
concurrency:
12+
group: "${{ github.ref }}"
13+
cancel-in-progress: true
14+
jobs:
15+
build-debian:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: "Update changelog"
20+
run: |
21+
set -ex
22+
OLD_VERSION=$(dpkg-parsechangelog -SVersion)
23+
SOURCE=$(dpkg-parsechangelog -SSource)
24+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
25+
VERSION_SUFFIX="+gh"
26+
else
27+
VERSION_SUFFIX="+autobuild${GITHUB_RUN_NUMBER}"
28+
fi
29+
cat > debian/changelog <<EOT
30+
${SOURCE} (${OLD_VERSION}${VERSION_SUFFIX}) UNRELEASED; urgency=medium
31+
32+
* Automated Build
33+
34+
-- Automated Build <builder@localhost> $(date -R)
35+
EOT
36+
- uses: jtdor/build-deb-action@v1
37+
- name: Archive build result
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: packages
41+
if-no-files-found: error
42+
retention-days: 14
43+
path: |
44+
debian/artifacts/*.deb
45+
debian/artifacts/*.tar.*
46+
- name: Comment PR with artifact link
47+
if: github.event_name == 'pull_request'
48+
uses: actions/github-script@v7
49+
with:
50+
script: |
51+
const runId = context.runId;
52+
const repoOwner = context.repo.owner;
53+
const repoName = context.repo.repo;
54+
55+
// Get the artifact download URL
56+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
57+
owner: repoOwner,
58+
repo: repoName,
59+
run_id: runId
60+
});
61+
62+
const packagesArtifact = artifacts.data.artifacts.find(artifact => artifact.name === 'packages');
63+
if (!packagesArtifact) {
64+
console.log('No packages artifact found');
65+
return;
66+
}
67+
68+
const artifactUrl = `https://github.com/${repoOwner}/${repoName}/actions/runs/${runId}/artifacts/${packagesArtifact.id}`;
69+
70+
github.rest.issues.createComment({
71+
issue_number: context.issue.number,
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
body: `📦 Built packages are ready! [Download here](${artifactUrl}).`
75+
});

.github/workflows/release.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
7+
jobs:
8+
create-release:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
actions: read
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Extract version from tag
17+
id: version
18+
run: |
19+
TAG_NAME="${GITHUB_REF#refs/tags/}"
20+
VERSION="${TAG_NAME#v}"
21+
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
22+
echo "tag=${TAG_NAME}" >> "$GITHUB_OUTPUT"
23+
24+
- name: Extract changelog entry
25+
id: changelog
26+
run: |
27+
VERSION="${{ steps.version.outputs.version }}"
28+
29+
# Extract and clean changelog for this specific version
30+
CHANGES=$(dpkg-parsechangelog -l debian/changelog --since "${VERSION}" --until "${VERSION}" --show-field Changes | \
31+
sed '/^[a-zA-Z0-9-].*([^)]*)[[:space:]]*.*$/d' | \
32+
sed 's/^[[:space:]]*\.[[:space:]]*$//' | \
33+
sed '/^[[:space:]]*$/d' | \
34+
sed 's/^[[:space:]]*\*[[:space:]]*/- /' | \
35+
sed 's/^[[:space:]]*\\+[[:space:]]*/ - /')
36+
37+
# Set as output for use in release
38+
{
39+
echo 'description<<EOF'
40+
echo "$CHANGES"
41+
echo 'EOF'
42+
} >> "$GITHUB_OUTPUT"
43+
44+
- name: Wait for and get package build run ID
45+
id: build-run
46+
uses: actions/github-script@v7
47+
with:
48+
script: |
49+
const maxWaitTime = 10 * 60 * 1000; // 10 minutes
50+
const pollInterval = 30 * 1000; // 30 seconds
51+
const startTime = Date.now();
52+
53+
while (Date.now() - startTime < maxWaitTime) {
54+
const runs = await github.rest.actions.listWorkflowRuns({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
workflow_id: 'package-build.yml',
58+
head_sha: context.sha,
59+
status: 'completed',
60+
conclusion: 'success'
61+
});
62+
63+
if (runs.data.workflow_runs.length > 0) {
64+
const runId = runs.data.workflow_runs[0].id;
65+
console.log(`Found successful package-build run: ${runId}`);
66+
return runId;
67+
}
68+
69+
console.log('Package-build workflow not completed yet, waiting...');
70+
await new Promise(resolve => setTimeout(resolve, pollInterval));
71+
}
72+
73+
throw new Error('Package-build workflow did not complete successfully within 10 minutes');
74+
75+
- name: Download build artifacts
76+
uses: actions/download-artifact@v4
77+
with:
78+
name: packages
79+
path: artifacts/
80+
run-id: ${{ steps.build-run.outputs.result }}
81+
github-token: ${{ secrets.GITHUB_TOKEN }}
82+
83+
- name: Create GitHub Release
84+
run: |
85+
DEB_FILE=$(find artifacts -name "*.deb" -printf "%f\n" | head -1)
86+
gh release create "${{ steps.version.outputs.tag }}" \
87+
--title "Release ${{ steps.version.outputs.tag }}" \
88+
--notes "## Changes in ${{ steps.version.outputs.version }}
89+
90+
${{ steps.changelog.outputs.description }}
91+
92+
---
93+
94+
📦 **Installation:**
95+
Download the package and install with:
96+
\`\`\`bash
97+
sudo apt install ./${DEB_FILE}
98+
\`\`\`" \
99+
artifacts/*
100+
env:
101+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)