Release by itself at every merge #38
6 changed files with 147 additions and 4 deletions
88
.forgejo/workflows/release.yml
Normal file
88
.forgejo/workflows/release.yml
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
# What happens at every merge into main:
|
||||||
|
# 1. semantic-release reads the commits since the last release (Conventional Commits), works out the next version,
|
||||||
|
# writes CHANGELOG.md, makes the release on the forge and tags it. A merge with nothing to release (docs, tests, ci)
|
||||||
|
# makes none.
|
||||||
|
# 2. When there is a release, the image is built from the tag and pushed to git.kmalloc.org/squid/sonda as
|
||||||
|
# X.Y.Z, X.Y and latest.
|
||||||
|
# The runner has no Docker, so the image is built with kaniko, which needs no daemon.
|
||||||
|
# Secret needed: FORGEJO_TOKEN, a token of the owner with the scopes write:repository and write:package.
|
||||||
|
name: release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
# One release at a time: two merges close together must not make two versions at once.
|
||||||
|
concurrency:
|
||||||
|
group: release
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: docker
|
||||||
|
# The commit that the release makes (CHANGELOG.md) says [skip ci]; this is the belt for those braces.
|
||||||
|
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
|
||||||
|
outputs:
|
||||||
|
version: ${{ steps.version.outputs.version }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # the whole history: the next version depends on every commit since the last tag
|
||||||
|
token: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 24
|
||||||
|
- name: Release
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
|
GITEA_URL: https://git.kmalloc.org
|
||||||
|
GIT_AUTHOR_NAME: sonda-release
|
||||||
|
GIT_AUTHOR_EMAIL: squid@kmalloc.org
|
||||||
|
GIT_COMMITTER_NAME: sonda-release
|
||||||
|
GIT_COMMITTER_EMAIL: squid@kmalloc.org
|
||||||
|
run: >
|
||||||
|
npx --yes
|
||||||
|
-p semantic-release@25
|
||||||
|
-p @semantic-release/commit-analyzer@13.0.1
|
||||||
|
-p @semantic-release/release-notes-generator@14.1.1
|
||||||
|
-p @semantic-release/changelog@7.0.0
|
||||||
|
-p @semantic-release/git@11.0.1
|
||||||
|
-p conventional-changelog-conventionalcommits@8.0.0
|
||||||
|
-p @saithodev/semantic-release-gitea@2.1.0
|
||||||
|
semantic-release
|
||||||
|
- name: Which version was made, if any
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
# The tag of a release points at the commit the release made, which is where the checkout now is.
|
||||||
|
tag="$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)"
|
||||||
|
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "released: ${tag:-nothing}"
|
||||||
|
|
||||||
|
image:
|
||||||
|
needs: release
|
||||||
|
if: ${{ needs.release.outputs.version != '' }}
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: gcr.io/kaniko-project/executor:v1.23.2-debug
|
||||||
|
steps:
|
||||||
|
- name: Build the image from the tag and push it
|
||||||
|
env:
|
||||||
|
VERSION: ${{ needs.release.outputs.version }}
|
||||||
|
REGISTRY_USER: squid
|
||||||
|
REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
mkdir -p /kaniko/.docker
|
||||||
|
auth="$(printf '%s:%s' "$REGISTRY_USER" "$REGISTRY_TOKEN" | base64 | tr -d '\n')"
|
||||||
|
printf '{"auths":{"git.kmalloc.org":{"auth":"%s"}}}' "$auth" > /kaniko/.docker/config.json
|
||||||
|
image=git.kmalloc.org/squid/sonda
|
||||||
|
minor="${VERSION%.*}"
|
||||||
|
/kaniko/executor \
|
||||||
|
--dockerfile Dockerfile \
|
||||||
|
--context "git://git.kmalloc.org/squid/sonda.git#refs/tags/v${VERSION}" \
|
||||||
|
--build-arg "VERSION=${VERSION}" \
|
||||||
|
--label "org.opencontainers.image.version=${VERSION}" \
|
||||||
|
--destination "${image}:${VERSION}" \
|
||||||
|
--destination "${image}:${minor}" \
|
||||||
|
--destination "${image}:latest" \
|
||||||
|
--verbosity info
|
||||||
35
.releaserc.json
Normal file
35
.releaserc.json
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"branches": ["main"],
|
||||||
|
"tagFormat": "v${version}",
|
||||||
|
"plugins": [
|
||||||
|
["@semantic-release/commit-analyzer", { "preset": "conventionalcommits" }],
|
||||||
|
[
|
||||||
|
"@semantic-release/release-notes-generator",
|
||||||
|
{
|
||||||
|
"preset": "conventionalcommits",
|
||||||
|
"presetConfig": {
|
||||||
|
"types": [
|
||||||
|
{ "type": "feat", "section": "Features" },
|
||||||
|
{ "type": "fix", "section": "Bug fixes" },
|
||||||
|
{ "type": "perf", "section": "Performance" },
|
||||||
|
{ "type": "refactor", "section": "Refactoring" },
|
||||||
|
{ "type": "docs", "section": "Documentation" },
|
||||||
|
{ "type": "style", "hidden": true },
|
||||||
|
{ "type": "test", "hidden": true },
|
||||||
|
{ "type": "chore", "hidden": true },
|
||||||
|
{ "type": "ci", "hidden": true }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
["@semantic-release/changelog", { "changelogFile": "CHANGELOG.md", "changelogTitle": "# Changelog" }],
|
||||||
|
[
|
||||||
|
"@semantic-release/git",
|
||||||
|
{
|
||||||
|
"assets": ["CHANGELOG.md"],
|
||||||
|
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
["@saithodev/semantic-release-gitea", { "giteaUrl": "https://git.kmalloc.org" }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -20,7 +20,9 @@ COPY cmd ./cmd
|
||||||
COPY internal ./internal
|
COPY internal ./internal
|
||||||
COPY migrations ./migrations
|
COPY migrations ./migrations
|
||||||
COPY --from=web /src/internal/webui/dist ./internal/webui/dist
|
COPY --from=web /src/internal/webui/dist ./internal/webui/dist
|
||||||
RUN CGO_ENABLED=0 go build -tags webui -trimpath -ldflags="-s -w" -o /out/sondad ./cmd/sondad
|
# The version of the release (see .releaserc.json), as GET /version and the User-Agent of the providers say it.
|
||||||
|
ARG VERSION=dev
|
||||||
|
RUN CGO_ENABLED=0 go build -tags webui -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/sondad ./cmd/sondad
|
||||||
|
|
||||||
FROM alpine:3.22
|
FROM alpine:3.22
|
||||||
LABEL org.opencontainers.image.title="Sonda" \
|
LABEL org.opencontainers.image.title="Sonda" \
|
||||||
|
|
|
||||||
5
Makefile
5
Makefile
|
|
@ -8,8 +8,11 @@
|
||||||
|
|
||||||
.PHONY: build web test
|
.PHONY: build web test
|
||||||
|
|
||||||
|
# The version is the last release tag, and how far this checkout is from it (v1.2.3-4-gabcdef), or "dev" outside git.
|
||||||
|
VERSION ?= $(shell git describe --tags --always 2>/dev/null | sed 's/^v//' || echo dev)
|
||||||
|
|
||||||
build: web
|
build: web
|
||||||
CGO_ENABLED=0 go build -tags webui -trimpath -ldflags="-s -w" -o bin/sondad ./cmd/sondad
|
CGO_ENABLED=0 go build -tags webui -trimpath -ldflags="-s -w -X main.version=$(VERSION)" -o bin/sondad ./cmd/sondad
|
||||||
|
|
||||||
web:
|
web:
|
||||||
cd web && npm ci && npm run build
|
cd web && npm ci && npm run build
|
||||||
|
|
|
||||||
13
README.md
13
README.md
|
|
@ -403,6 +403,19 @@ What it does today: sign in (and create the first account of a new server), brow
|
||||||
|
|
||||||
More commands, all run in `web/`: `npm test`, `npm run build`, and `npm run gen:api`, which rebuilds `src/api/schema.d.ts` from the OpenAPI spec (it fetches the generator with `npx`, so it needs the network once). `npm run build` writes to `internal/webui/dist` (git-ignored), not to `web/dist`.
|
More commands, all run in `web/`: `npm test`, `npm run build`, and `npm run gen:api`, which rebuilds `src/api/schema.d.ts` from the OpenAPI spec (it fetches the generator with `npx`, so it needs the network once). `npm run build` writes to `internal/webui/dist` (git-ignored), not to `web/dist`.
|
||||||
|
|
||||||
|
## Releases
|
||||||
|
|
||||||
|
Every merge into `main` can make a release, by itself (`.forgejo/workflows/release.yml`, [semantic-release](https://semantic-release.gitbook.io)). The next version comes from the messages of the commits since the last one, written as [Conventional Commits](https://www.conventionalcommits.org):
|
||||||
|
|
||||||
|
| Commit | Release |
|
||||||
|
|---|---|
|
||||||
|
| `fix: ...`, `perf: ...` | patch (0.2.0 to 0.2.1) |
|
||||||
|
| `feat: ...` | minor (0.2.0 to 0.3.0) |
|
||||||
|
| `feat!: ...`, or `BREAKING CHANGE:` in the body | major (0.2.0 to 1.0.0) |
|
||||||
|
| `docs:`, `test:`, `chore:`, `ci:`, `style:` | none by themselves |
|
||||||
|
|
||||||
|
A release adds its entry to [CHANGELOG.md](CHANGELOG.md), tags the commit (`v0.3.0`), makes the release on the forge, and the image is built from the tag and pushed to `git.kmalloc.org/squid/sonda` as `0.3.0`, `0.3` and `latest`. The version is inside the binary: `GET /version` and the User-Agent of the providers say it (a build that no release made says `dev`). The commit that writes `CHANGELOG.md` says `[skip ci]`. The runner has no Docker, so the image is built with [kaniko](https://github.com/GoogleContainerTools/kaniko). The workflow needs the secret `FORGEJO_TOKEN`: a token of the owner with the scopes `write:repository` and `write:package`.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,10 @@ import (
|
||||||
|
|
||||||
const defaultConfigFile = "sonda.toml"
|
const defaultConfigFile = "sonda.toml"
|
||||||
|
|
||||||
// version goes into the User-Agent sent to providers.
|
// version goes into the User-Agent sent to providers, and is what GET /version says. The release sets it
|
||||||
const version = "0.1.0"
|
// (-ldflags "-X main.version=1.2.3": see the Dockerfile and the Makefile); a build that was not made by a release says
|
||||||
|
// "dev".
|
||||||
|
var version = "dev"
|
||||||
|
|
||||||
// lastfmMinInterval spaces the requests to Last.fm well below its limit.
|
// lastfmMinInterval spaces the requests to Last.fm well below its limit.
|
||||||
const lastfmMinInterval = 250 * time.Millisecond
|
const lastfmMinInterval = 250 * time.Millisecond
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue