name: Release on: push: tags: - 'v*' jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 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: Generate checksums working-directory: dist run: sha256sum netssh_* > checksums.txt - name: Create release id: create_release run: | TAG="${{ github.ref_name }}" 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 RELEASE=$(curl -sf -X POST \ -H "$AUTH" \ -H "Content-Type: application/json" \ "$API/releases" \ -d "{ \"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"## Installation\n\n\`\`\`sh\ncurl -fsSL https://git.zb-server.de/Sebi/ssh-netbox-wrapper/raw/branch/main/install.sh | bash\n\`\`\`\", \"draft\": false, \"prerelease\": false }") 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/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