Releases are published only for manually pushed v* tags again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+12
-48
@@ -1,8 +1,5 @@
|
||||
name: build
|
||||
|
||||
# Every push to main is released: it gets the next patch tag (v0.1.3 -> v0.1.4)
|
||||
# and a Gitea release with the deb/rpm. Pushing a v* tag by hand releases that
|
||||
# exact version instead (use it to bump minor/major).
|
||||
on:
|
||||
push:
|
||||
branches: ["**"]
|
||||
@@ -17,8 +14,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: https://gitea.com/actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # tags + history for the version and release notes
|
||||
|
||||
- uses: https://gitea.com/actions/setup-go@v5
|
||||
with:
|
||||
@@ -29,27 +24,6 @@ jobs:
|
||||
go vet ./...
|
||||
go test ./...
|
||||
|
||||
- name: release version
|
||||
id: ver
|
||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git fetch --tags --force -q
|
||||
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
|
||||
tag="${GITHUB_REF#refs/tags/}"
|
||||
else
|
||||
# re-run of an already released commit keeps its tag
|
||||
tag=$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1 || true)
|
||||
if [ -z "$tag" ]; then
|
||||
last=$(git tag | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1 || true)
|
||||
IFS=. read -r major minor patch <<<"${last:-v0.0.0}"
|
||||
tag="${major}.${minor}.$((patch + 1))"
|
||||
fi
|
||||
fi
|
||||
echo "release $tag"
|
||||
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
||||
echo "VERSION=${tag#v}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: install nfpm
|
||||
run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
|
||||
|
||||
@@ -68,41 +42,31 @@ jobs:
|
||||
dist/*.rpm
|
||||
|
||||
- name: publish release
|
||||
if: steps.ver.outputs.tag != ''
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
API: ${{ github.api_url }}/repos/${{ github.repository }}
|
||||
TAG: ${{ steps.ver.outputs.tag }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
auth="Authorization: token $GITEA_TOKEN"
|
||||
tag="${GITHUB_REF#refs/tags/}"
|
||||
|
||||
# release notes: commit subjects since the previous release tag
|
||||
prev=$(git tag --merged HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | grep -vx "$TAG" | sort -V | tail -1 || true)
|
||||
git log --no-merges --pretty='- %s' ${prev:+"$prev"..}HEAD > notes.md
|
||||
body=$(python3 -c 'import json,os,sys; print(json.dumps({"tag_name": os.environ["TAG"], "name": os.environ["TAG"], "target_commitish": os.environ["GITHUB_SHA"], "body": open("notes.md").read()}))')
|
||||
|
||||
# creating the release also creates the tag on this commit
|
||||
release_id=$(curl -sf -X POST "$API/releases" -H "$auth" \
|
||||
-H "Content-Type: application/json" -d "$body" \
|
||||
release_id=$(curl -sf -X POST "$API/releases" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"$tag\",\"name\":\"$tag\"}" \
|
||||
| grep -oP '"id":\s*\K[0-9]+' | head -1) || \
|
||||
release_id=$(curl -sf "$API/releases/tags/$TAG" -H "$auth" \
|
||||
release_id=$(curl -sf "$API/releases/tags/$tag" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
| grep -oP '"id":\s*\K[0-9]+' | head -1)
|
||||
|
||||
if [ -z "$release_id" ]; then
|
||||
echo "could not create or find a release for tag $TAG" >&2
|
||||
echo "could not create or find a release for tag $tag" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
existing=$(curl -sf "$API/releases/$release_id/assets" -H "$auth" || true)
|
||||
for f in dist/*.deb dist/*.rpm; do
|
||||
[ -e "$f" ] || continue
|
||||
name=$(basename "$f")
|
||||
if grep -q "\"name\":\"$name\"" <<<"$existing"; then
|
||||
echo "$name already attached"
|
||||
continue
|
||||
fi
|
||||
curl -sf -X POST "$API/releases/$release_id/assets?name=$name" \
|
||||
-H "$auth" -F "attachment=@${f}"
|
||||
curl -sf -X POST "$API/releases/$release_id/assets?name=$(basename "$f")" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-F "attachment=@${f}"
|
||||
done
|
||||
echo "released $TAG: ${{ github.server_url }}/${{ github.repository }}/releases/tag/$TAG"
|
||||
|
||||
@@ -43,14 +43,6 @@ One-time tool setup:
|
||||
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
|
||||
```
|
||||
|
||||
## Releases
|
||||
|
||||
CI (`.gitea/workflows/build.yml`) releases every push to `main`: it tags the
|
||||
commit with the next patch version (v0.1.3 → v0.1.4), builds deb + rpm with
|
||||
that version and publishes a Gitea release with both packages and the commit
|
||||
subjects as notes. To bump minor/major, push a tag yourself (`git tag v0.2.0 &&
|
||||
git push origin v0.2.0`); later pushes to main continue from it.
|
||||
|
||||
## Packaging
|
||||
|
||||
`packaging/nfpm.yaml` builds both formats from one spec:
|
||||
|
||||
Reference in New Issue
Block a user