added release upload to workflow

This commit is contained in:
markusro committed 2026-10-18 19:36:21 +02:00
1 parent 458715c19a
commit 81c6c3f87c
1 file changed
+53 -13
+53 -13
View File
@@ -2,8 +2,7 @@ name: Build Debian Packages
on: on:
push: push:
branches: [ "main" ] tags: [ "v*" ] # releases are tag-driven now
pull_request:
workflow_dispatch: workflow_dispatch:
jobs: jobs:
@@ -16,14 +15,14 @@ jobs:
codename: bookworm codename: bookworm
- target: debian13 - target: debian13
codename: trixie codename: trixie
runs-on: ${{ matrix.target }} runs-on: ${{ matrix.target }}
steps: steps:
- name: Install Node.js and git - name: Install Node.js and git
run: | run: |
apt-get update apt-get update
apt-get -y install nodejs git lsb-release apt-get -y install nodejs git lsb-release jq
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v3
@@ -31,20 +30,61 @@ jobs:
github-server-url: https://gitea.pkm.physik.tu-darmstadt.de github-server-url: https://gitea.pkm.physik.tu-darmstadt.de
- name: Install build dependencies - name: Install build dependencies
run: | run: bash requirements.debian
bash requirements.debian
- name: Build Package - name: Build Package
run: | run: dpkg-buildpackage -us -uc -b
dpkg-buildpackage -us -uc -b
- name: Collect Artifacts - name: Collect Artifacts
run: | run: |
mkdir -p artifacts mkdir -p artifacts
mv -v ../*.deb artifacts/ mv -v ../*.deb artifacts/
- name: Upload Artifacts - name: Publish release with assets
uses: actions/upload-artifact@v3 env:
with: GITEA_TOKEN: ${{ secrets.DEB_UPLOAD_TOKEN }}
name: python3-damaris-${{ matrix.codename }}.gz SLUG: ${{ gitea.repository }} # owner/repo
path: artifacts/*.deb TAG: ${{ gitea.ref_name }} # e.g. v1.2.3
CODENAME: ${{ matrix.codename }}
run: |
set -euo pipefail
API="https://gitea.pkm.physik.tu-darmstadt.de/api/v1"
AUTH="Authorization: token ${GITEA_TOKEN}"
# 1. Find an existing release for this tag, if any
release_id=$(curl -s -H "$AUTH" \
"$API/repos/$SLUG/releases/tags/$TAG" | jq -r '.id // empty')
# 2. Create the release if it does not exist yet
if [ -z "$release_id" ]; then
echo "Creating release $TAG"
release_id=$(curl -s -X POST -H "$AUTH" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg tag "$TAG" \
'{tag_name:$tag, name:$tag, draft:false, prerelease:false}')" \
"$API/repos/$SLUG/releases" | jq -r '.id')
else
echo "Reusing existing release $TAG (id=$release_id)"
fi
echo "release_id=$release_id"
# 3. Upload each .deb as an asset
for deb in artifacts/*.deb; do
asset="${CODENAME}_$(basename "$deb")" # avoid bookworm/trixie name clash
echo "Uploading $asset"
# delete any existing asset with the same name (idempotent re-runs)
existing=$(curl -s -H "$AUTH" \
"$API/repos/$SLUG/releases/$release_id/assets" \
| jq -r --arg n "$asset" '.[] | select(.name==$n) | .id')
if [ -n "$existing" ]; then
curl -s -X DELETE -H "$AUTH" \
"$API/repos/$SLUG/releases/$release_id/assets/$existing"
fi
curl --fail --show-error --silent \
-X POST -H "$AUTH" \
-F "attachment=@$deb;filename=$asset" \
"$API/repos/$SLUG/releases/$release_id/assets"
done