Files
ssh-netbox-wrapper/.gitea/workflows/release.yml
Sebastian UnterschützandClaude Opus 5.5 786768ec53 feat: add netssh version and --version
`netssh --version` used to be passed to ssh and failed with
"unknown option -- -". Release builds now embed the tag via
-X main.version; other builds fall back to the module build info.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:23:19 +01:00

106 lines
3.4 KiB
YAML

name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
env:
GITEA_PUBLIC_URL: https://git.zb-server.de
GITEA_REPOSITORY: ${{ github.repository }}
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 -X main.version=${GITHUB_REF_NAME}" \
-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 }}
run: bash scripts/release-notes.sh "$RELEASE_TAG" "$GITEA_PUBLIC_URL/$GITEA_REPOSITORY" > dist/release-notes.md
- name: Create release
id: create_release
env:
TAG: ${{ github.ref_name }}
run: |
API="$GITEA_PUBLIC_URL/api/v1/repos/$GITEA_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" \
"$GITEA_PUBLIC_URL/api/v1/repos/$GITEA_REPOSITORY/releases/${RELEASE_ID}/assets?name=${name}" \
--data-binary "@$file"
done