94 lines
3.1 KiB
YAML
94 lines
3.1 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
release:
|
|
name: Build and Release
|
|
runs-on: nix
|
|
|
|
steps:
|
|
- name: Check out Repository
|
|
uses: https://git.konstantinfickel.de/actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Extract version and handle tagging
|
|
id: version
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
# Manual trigger: read version from Cargo.toml
|
|
VERSION_LINE=$(grep '^version' Cargo.toml | head -1)
|
|
VERSION="${VERSION_LINE#*\"}"
|
|
VERSION="${VERSION%\"*}"
|
|
TAG="v${VERSION}"
|
|
|
|
# Check if tag already exists
|
|
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
|
echo "::error::Version ${VERSION} is already released"
|
|
exit 1
|
|
fi
|
|
|
|
# Create and push the tag
|
|
git tag "$TAG"
|
|
git push origin "$TAG"
|
|
|
|
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
|
|
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
|
|
else
|
|
# Tag push trigger: extract version from tag
|
|
VERSION="${GITHUB_REF_NAME#v}"
|
|
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
|
|
echo "TAG=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Build .deb package
|
|
run: nix build .#streamd-deb -o result-deb
|
|
|
|
- name: Build static binary
|
|
run: nix build .#streamd-musl -o result-musl
|
|
|
|
- name: Prepare release artifacts
|
|
run: |
|
|
mkdir -p release
|
|
cp result-deb release/streamd_${{ steps.version.outputs.VERSION }}_amd64.deb
|
|
cp result-musl/bin/streamd release/streamd-${{ steps.version.outputs.VERSION }}-linux-x86_64
|
|
|
|
- name: Create release
|
|
env:
|
|
FORGEJO_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
TAG: ${{ steps.version.outputs.TAG }}
|
|
run: |
|
|
# Create the release
|
|
release_response=$(curl -sS -X POST \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\": \"${TAG}\", \"name\": \"${TAG}\", \"body\": \"Release ${TAG}\"}" \
|
|
"https://git.konstantinfickel.de/api/v1/repos/kfickel/streamd/releases")
|
|
|
|
release_id=$(echo "$release_response" | jq -r '.id')
|
|
|
|
if [ -z "$release_id" ] || [ "$release_id" = "null" ]; then
|
|
echo "Failed to create release:"
|
|
echo "$release_response"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Created release with ID: $release_id"
|
|
|
|
# Upload assets
|
|
for file in release/*; do
|
|
filename=$(basename "$file")
|
|
echo "Uploading $filename..."
|
|
curl -sS -X POST \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary "@$file" \
|
|
"https://git.konstantinfickel.de/api/v1/repos/kfickel/streamd/releases/${release_id}/assets?name=${filename}"
|
|
done
|
|
|
|
echo "Release ${TAG} created successfully"
|