Files
ssh-netbox-wrapper/.gitea/workflows/release.yml
T
2026-10-27 18:38:54 +01:00

104 lines
3.3 KiB
YAML

name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Run tests
run: go test ./...
- name: Build binaries
run: |
mkdir -p dist
for platform in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64; do
GOOS=${platform%/*}
GOARCH=${platform#*/}
out="dist/netssh_${GOOS}_${GOARCH}"
echo "→ $out"
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH \
go build -trimpath -ldflags="-s -w" \
-o "$out" ./cmd/netssh
done
- name: Package installer
run: install -m 755 install.sh dist/install.sh
- name: Generate checksums
working-directory: dist
run: sha256sum netssh_* install.sh > checksums.txt
- name: Generate release notes
env:
RELEASE_TAG: ${{ github.ref_name }}
REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
run: bash scripts/release-notes.sh "$RELEASE_TAG" "$REPOSITORY_URL" > dist/release-notes.md
- name: Create release
id: create_release
env:
TAG: ${{ github.ref_name }}
run: |
API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}"
AUTH="Authorization: token ${{ secrets.GITEA_TOKEN }}"
# Delete existing release for this tag if present
EXISTING=$(curl -sf -H "$AUTH" "$API/releases/tags/$TAG" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true)
if [ -n "$EXISTING" ]; then
echo "Deleting existing release $EXISTING"
curl -sf -X DELETE -H "$AUTH" "$API/releases/$EXISTING"
fi
# Serialize Markdown as JSON without hand-escaping quotes or newlines.
python3 - <<'PY_RELEASE' > dist/release.json
import json
import os
import sys
from pathlib import Path
tag = os.environ["TAG"]
json.dump({
"tag_name": tag,
"name": tag,
"body": Path("dist/release-notes.md").read_text(),
"draft": False,
"prerelease": False,
}, sys.stdout)
PY_RELEASE
RELEASE=$(curl -sf -X POST \
-H "$AUTH" \
-H "Content-Type: application/json" \
"$API/releases" \
--data-binary @dist/release.json)
RELEASE_ID=$(echo "$RELEASE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
echo "release_id=$RELEASE_ID" >> "$GITHUB_OUTPUT"
- name: Upload assets
run: |
RELEASE_ID="${{ steps.create_release.outputs.release_id }}"
for file in dist/netssh_* dist/install.sh dist/checksums.txt; do
name=$(basename "$file")
echo "↑ $name"
curl -sf -X POST \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets?name=${name}" \
--data-binary "@$file"
done