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
|
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:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["**"]
|
branches: ["**"]
|
||||||
@@ -17,8 +14,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: https://gitea.com/actions/checkout@v4
|
- 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
|
- uses: https://gitea.com/actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
@@ -29,27 +24,6 @@ jobs:
|
|||||||
go vet ./...
|
go vet ./...
|
||||||
go test ./...
|
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
|
- name: install nfpm
|
||||||
run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
|
run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
|
||||||
|
|
||||||
@@ -68,41 +42,31 @@ jobs:
|
|||||||
dist/*.rpm
|
dist/*.rpm
|
||||||
|
|
||||||
- name: publish release
|
- name: publish release
|
||||||
if: steps.ver.outputs.tag != ''
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
API: ${{ github.api_url }}/repos/${{ github.repository }}
|
API: ${{ github.api_url }}/repos/${{ github.repository }}
|
||||||
TAG: ${{ steps.ver.outputs.tag }}
|
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
auth="Authorization: token $GITEA_TOKEN"
|
tag="${GITHUB_REF#refs/tags/}"
|
||||||
|
|
||||||
# release notes: commit subjects since the previous release tag
|
release_id=$(curl -sf -X POST "$API/releases" \
|
||||||
prev=$(git tag --merged HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | grep -vx "$TAG" | sort -V | tail -1 || true)
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
git log --no-merges --pretty='- %s' ${prev:+"$prev"..}HEAD > notes.md
|
-H "Content-Type: application/json" \
|
||||||
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()}))')
|
-d "{\"tag_name\":\"$tag\",\"name\":\"$tag\"}" \
|
||||||
|
|
||||||
# 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" \
|
|
||||||
| grep -oP '"id":\s*\K[0-9]+' | head -1) || \
|
| 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)
|
| grep -oP '"id":\s*\K[0-9]+' | head -1)
|
||||||
|
|
||||||
if [ -z "$release_id" ]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
existing=$(curl -sf "$API/releases/$release_id/assets" -H "$auth" || true)
|
|
||||||
for f in dist/*.deb dist/*.rpm; do
|
for f in dist/*.deb dist/*.rpm; do
|
||||||
[ -e "$f" ] || continue
|
[ -e "$f" ] || continue
|
||||||
name=$(basename "$f")
|
curl -sf -X POST "$API/releases/$release_id/assets?name=$(basename "$f")" \
|
||||||
if grep -q "\"name\":\"$name\"" <<<"$existing"; then
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
echo "$name already attached"
|
-F "attachment=@${f}"
|
||||||
continue
|
|
||||||
fi
|
|
||||||
curl -sf -X POST "$API/releases/$release_id/assets?name=$name" \
|
|
||||||
-H "$auth" -F "attachment=@${f}"
|
|
||||||
done
|
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
|
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
|
||||||
|
|
||||||
`packaging/nfpm.yaml` builds both formats from one spec:
|
`packaging/nfpm.yaml` builds both formats from one spec:
|
||||||
|
|||||||
Reference in New Issue
Block a user