Author SHA1 Message Date
software-maintainer 1fbb05339c Upgrade Go toolchain pins and add Gitea Actions CI checks
Bump the go directive and mise tool pin to Go 1.27.1, the newest toolchain available in the build environment; module versions already resolve to the newest releases present in the pinned module cache.

Add .gitea/workflows/ci.yml, which runs on every pull request and every push to main and invokes scripts/check.sh (gofmt, go mod verify, go vet, go build, go test -cover). Also cover the Gitea client token/slug handling with unit tests and document the CI workflow.

Add the mise check task so the CI checks can be run locally.
2026-10-28 07:45:30 +00:00
Thomas 55d4259f4a Fixes? 2026-05-13 22:07:06 +02:00
Thomas 98a030bcc2 workflow docs 2026-03-13 00:59:27 +01:00
8 changed files with 267 additions and 14 deletions

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
name: ci
on:
pull_request:
push:
branches: [main]
jobs:
check:
name: build and test
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
- name: Run checks
run: ./scripts/check.sh
+27 -4
View File
@@ -250,7 +250,8 @@ pre_tag = "" # Set by `stamp preview enter`; leave blank for nor
|----------|---------| |----------|---------|
| `STAMP_REPO` | Repository slug `owner/repo` — required for `publish`, `comment`, and `release-pr` | | `STAMP_REPO` | Repository slug `owner/repo` — required for `publish`, `comment`, and `release-pr` |
| `GITHUB_TOKEN` | GitHub token for releases and PR comments — automatically provided by the GitHub Actions runner; no manual setup needed | | `GITHUB_TOKEN` | GitHub token for releases and PR comments — automatically provided by the GitHub Actions runner; no manual setup needed |
| `GITEA_TOKEN` | Gitea access token — **must be created manually** (Gitea Actions does not inject one automatically); create a token in your Gitea account settings and store it as a repository secret | | `GITEA_TOKEN` | Auto-injected by Gitea Actions — has limited scopes and **cannot create PRs or post comments**; do not use this for stamp |
| `STAMP_GITEA_TOKEN` | PAT you create manually with `repository` (read/write) and `issue` (read/write) scopes; used by stamp for all Gitea API calls. Store it as a repository secret. The name `GITEA_TOKEN` is reserved by Gitea Actions, which is why a different name is required. |
| `GITEA_BASE_URL` | Gitea instance URL (e.g. `https://gitea.example.com`) — also enables Gitea mode | | `GITEA_BASE_URL` | Gitea instance URL (e.g. `https://gitea.example.com`) — also enables Gitea mode |
## CI Integration ## CI Integration
@@ -305,7 +306,7 @@ jobs:
- name: Comment on PR - name: Comment on PR
run: stamp comment --pr=${{ gitea.event.pull_request.number }} run: stamp comment --pr=${{ gitea.event.pull_request.number }}
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} STAMP_GITEA_TOKEN: ${{ secrets.STAMP_GITEA_TOKEN }}
GITEA_BASE_URL: ${{ gitea.server_url }} GITEA_BASE_URL: ${{ gitea.server_url }}
STAMP_REPO: ${{ gitea.repository }} STAMP_REPO: ${{ gitea.repository }}
``` ```
@@ -345,6 +346,11 @@ jobs:
# A full clone is needed so stamp can fetch and reset the release branch. # A full clone is needed so stamp can fetch and reset the release branch.
fetch-depth: 0 fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install stamp - name: Install stamp
run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest
@@ -372,6 +378,12 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
token: ${{ secrets.STAMP_GITEA_TOKEN }}
- name: Configure git
run: |
git config user.name "stamp-bot"
git config user.email "stamp-bot@users.noreply.gitea.com"
- name: Install stamp - name: Install stamp
run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest
@@ -379,7 +391,7 @@ jobs:
- name: Create or update release PR - name: Create or update release PR
run: stamp release-pr --base=main run: stamp release-pr --base=main
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} STAMP_GITEA_TOKEN: ${{ secrets.STAMP_GITEA_TOKEN }}
GITEA_BASE_URL: ${{ gitea.server_url }} GITEA_BASE_URL: ${{ gitea.server_url }}
STAMP_REPO: ${{ gitea.repository }} STAMP_REPO: ${{ gitea.repository }}
``` ```
@@ -404,6 +416,11 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install stamp - name: Install stamp
run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest
@@ -431,6 +448,12 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
token: ${{ secrets.STAMP_GITEA_TOKEN }}
- name: Configure git
run: |
git config user.name "stamp-bot"
git config user.email "stamp-bot@users.noreply.gitea.com"
- name: Install stamp - name: Install stamp
run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest
@@ -438,7 +461,7 @@ jobs:
- name: Publish releases - name: Publish releases
run: stamp publish run: stamp publish
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} STAMP_GITEA_TOKEN: ${{ secrets.STAMP_GITEA_TOKEN }}
GITEA_BASE_URL: ${{ gitea.server_url }} GITEA_BASE_URL: ${{ gitea.server_url }}
STAMP_REPO: ${{ gitea.repository }} STAMP_REPO: ${{ gitea.repository }}
``` ```
+50 -5
View File
@@ -18,6 +18,28 @@ It works with any project type and supports monorepos.
--- ---
## Continuous Integration
Every pull request and every push to `main` runs the `ci` workflow in
[`.gitea/workflows/ci.yml`](../.gitea/workflows/ci.yml). Its single `check` job
runs [`scripts/check.sh`](../scripts/check.sh), which:
1. fails if any Go file is not `gofmt`-formatted,
2. runs `go mod verify` to confirm the dependency modules match `go.sum`,
3. runs `go vet ./...` and `go build ./...`,
4. runs `go test -cover ./...`.
Run the same checks locally with:
```sh
./scripts/check.sh
```
The job fails when any check fails, so a pull request cannot land with broken
code or tests.
---
## Two Release Workflows ## Two Release Workflows
### Direct release ### Direct release
@@ -187,6 +209,11 @@ jobs:
# Full clone so stamp can fetch and reset the release branch. # Full clone so stamp can fetch and reset the release branch.
fetch-depth: 0 fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install stamp - name: Install stamp
run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest
@@ -215,6 +242,11 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install stamp - name: Install stamp
run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest
@@ -246,6 +278,12 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
token: ${{ secrets.STAMP_GITEA_TOKEN }}
- name: Configure git
run: |
git config user.name "stamp-bot"
git config user.email "stamp-bot@users.noreply.gitea.com"
- name: Install stamp - name: Install stamp
run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest
@@ -253,7 +291,7 @@ jobs:
- name: Create or update release PR - name: Create or update release PR
run: stamp release-pr --base=main run: stamp release-pr --base=main
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} STAMP_GITEA_TOKEN: ${{ secrets.STAMP_GITEA_TOKEN }}
GITEA_BASE_URL: ${{ gitea.server_url }} GITEA_BASE_URL: ${{ gitea.server_url }}
STAMP_REPO: ${{ gitea.repository }} STAMP_REPO: ${{ gitea.repository }}
``` ```
@@ -275,6 +313,12 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
token: ${{ secrets.STAMP_GITEA_TOKEN }}
- name: Configure git
run: |
git config user.name "stamp-bot"
git config user.email "stamp-bot@users.noreply.gitea.com"
- name: Install stamp - name: Install stamp
run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest run: go install git.thokra.dev/thokra/stamp/cmd/stamp@latest
@@ -282,12 +326,12 @@ jobs:
- name: Publish releases - name: Publish releases
run: stamp publish run: stamp publish
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} STAMP_GITEA_TOKEN: ${{ secrets.STAMP_GITEA_TOKEN }}
GITEA_BASE_URL: ${{ gitea.server_url }} GITEA_BASE_URL: ${{ gitea.server_url }}
STAMP_REPO: ${{ gitea.repository }} STAMP_REPO: ${{ gitea.repository }}
``` ```
> **Note on `GITEA_TOKEN`:** Gitea Actions does not automatically inject a token the way GitHub Actions does. You must create a personal access token (or a bot account token) in your Gitea account settings with repository read/write permissions, then store it as a repository secret named `GITEA_TOKEN`. > **Note on `STAMP_GITEA_TOKEN`:** Gitea Actions auto-injects a `GITEA_TOKEN` for each run, but that token has limited scopes and cannot create PRs or post comments. Because `GITEA_TOKEN` is a reserved name you cannot override it with a secret of the same name. Instead, create a PAT in your Gitea account settings with **`repository` (read/write)** and **`issue` (read/write)** scopes, then store it as a repository secret named `STAMP_GITEA_TOKEN`. stamp reads `STAMP_GITEA_TOKEN` first and falls back to `GITEA_TOKEN`.
--- ---
@@ -346,7 +390,7 @@ jobs:
- name: Comment on PR - name: Comment on PR
run: stamp comment --pr=${{ gitea.event.pull_request.number }} run: stamp comment --pr=${{ gitea.event.pull_request.number }}
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} STAMP_GITEA_TOKEN: ${{ secrets.STAMP_GITEA_TOKEN }}
GITEA_BASE_URL: ${{ gitea.server_url }} GITEA_BASE_URL: ${{ gitea.server_url }}
STAMP_REPO: ${{ gitea.repository }} STAMP_REPO: ${{ gitea.repository }}
``` ```
@@ -459,5 +503,6 @@ Tag format: `<name>@v<version>` for monorepos (e.g. `my-app@v1.3.0`), or `v<vers
|----------|---------| |----------|---------|
| `STAMP_REPO` | Repository slug `owner/repo` — required for `publish`, `comment`, and `release-pr` | | `STAMP_REPO` | Repository slug `owner/repo` — required for `publish`, `comment`, and `release-pr` |
| `GITHUB_TOKEN` | GitHub token — automatically injected by GitHub Actions; no setup needed | | `GITHUB_TOKEN` | GitHub token — automatically injected by GitHub Actions; no setup needed |
| `GITEA_TOKEN` | Gitea access token — must be created manually and stored as a secret | | `GITEA_TOKEN` | Auto-injected by Gitea Actions with limited scopes — **do not use this for stamp** |
| `STAMP_GITEA_TOKEN` | PAT you create manually with `repository` (read/write) and `issue` (read/write) scopes. The name `GITEA_TOKEN` is reserved by Gitea Actions, so a different name is required. |
| `GITEA_BASE_URL` | Gitea instance URL (e.g. `https://gitea.example.com`) — presence of this variable also activates Gitea mode | | `GITEA_BASE_URL` | Gitea instance URL (e.g. `https://gitea.example.com`) — presence of this variable also activates Gitea mode |
+1 -1
View File
@@ -1,6 +1,6 @@
module git.thokra.dev/thokra/stamp module git.thokra.dev/thokra/stamp
go 1.26.1 go 1.27.1
require ( require (
code.gitea.io/sdk/gitea v0.23.2 code.gitea.io/sdk/gitea v0.23.2
+32 -3
View File
@@ -8,6 +8,17 @@ import (
giteaSDK "code.gitea.io/sdk/gitea" giteaSDK "code.gitea.io/sdk/gitea"
) )
// isPRsDisabledError returns true when the Gitea server rejects a PR operation
// because the Pull Requests unit is disabled on the repository.
func isPRsDisabledError(err error) bool {
if err == nil {
return false
}
msg := err.Error()
return strings.Contains(msg, "Can't read pulls") ||
strings.Contains(msg, "UnitTypeCode")
}
const prMarker = "<!-- stamp-release-pr -->" const prMarker = "<!-- stamp-release-pr -->"
// Client wraps the Gitea API. // Client wraps the Gitea API.
@@ -19,12 +30,18 @@ type Client struct {
const commentMarker = "<!-- stamp-pr-comment -->" const commentMarker = "<!-- stamp-pr-comment -->"
// NewClient creates a Gitea client from GITEA_TOKEN and GITEA_BASE_URL environment variables. // NewClient creates a Gitea client from GITEA_BASE_URL and a token environment variable.
// The token is read from STAMP_GITEA_TOKEN first, falling back to GITEA_TOKEN.
// STAMP_GITEA_TOKEN should be used in CI to avoid the reserved GITEA_TOKEN name that
// Gitea Actions injects automatically (with limited scopes).
// The repoSlug must be in "owner/repo" format. // The repoSlug must be in "owner/repo" format.
func NewClient(repoSlug string) (*Client, error) { func NewClient(repoSlug string) (*Client, error) {
token := os.Getenv("GITEA_TOKEN") token := os.Getenv("STAMP_GITEA_TOKEN")
if token == "" { if token == "" {
return nil, fmt.Errorf("GITEA_TOKEN environment variable is not set") token = os.Getenv("GITEA_TOKEN")
}
if token == "" {
return nil, fmt.Errorf("neither STAMP_GITEA_TOKEN nor GITEA_TOKEN environment variable is set")
} }
baseURL := os.Getenv("GITEA_BASE_URL") baseURL := os.Getenv("GITEA_BASE_URL")
if baseURL == "" { if baseURL == "" {
@@ -87,6 +104,12 @@ func (c *Client) UpsertPR(head, base, title, body string) (int64, string, error)
State: giteaSDK.StateOpen, State: giteaSDK.StateOpen,
}) })
if err != nil { if err != nil {
if isPRsDisabledError(err) {
return 0, "", fmt.Errorf(
"pull requests are disabled on %s/%s — enable them under Settings → General → Features → Pull Requests",
c.owner, c.repo,
)
}
return 0, "", fmt.Errorf("listing pull requests: %w", err) return 0, "", fmt.Errorf("listing pull requests: %w", err)
} }
@@ -116,6 +139,12 @@ func (c *Client) UpsertPR(head, base, title, body string) (int64, string, error)
Body: markedBody, Body: markedBody,
}) })
if err != nil { if err != nil {
if isPRsDisabledError(err) {
return 0, "", fmt.Errorf(
"pull requests are disabled on %s/%s — enable them under Settings → General → Features → Pull Requests",
c.owner, c.repo,
)
}
return 0, "", fmt.Errorf("creating pull request: %w", err) return 0, "", fmt.Errorf("creating pull request: %w", err)
} }
return pr.Index, pr.HTMLURL, nil return pr.Index, pr.HTMLURL, nil
+100
View File
@@ -0,0 +1,100 @@
package gitea
import (
"errors"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestIsPRsDisabledError(t *testing.T) {
tests := []struct {
name string
err error
want bool
}{
{name: "nil error", err: nil, want: false},
{name: "pulls unit disabled", err: errors.New(`Get "https://gitea.example.com/api/v1/repos/o/r/pulls": Can't read pulls`), want: true},
{name: "code unit disabled", err: errors.New("repository unit UnitTypeCode is disabled"), want: true},
{name: "unrelated error", err: errors.New("connection refused"), want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isPRsDisabledError(tt.err); got != tt.want {
t.Fatalf("isPRsDisabledError(%v) = %v, want %v", tt.err, got, tt.want)
}
})
}
}
// newVersionServer starts a stub Gitea API server that only answers the
// version probe performed by the SDK client constructor.
func newVersionServer(t *testing.T) *httptest.Server {
t.Helper()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/version" {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"version":"1.22.0"}`))
}))
t.Cleanup(srv.Close)
return srv
}
func TestNewClientRequiresToken(t *testing.T) {
t.Setenv("STAMP_GITEA_TOKEN", "")
t.Setenv("GITEA_TOKEN", "")
t.Setenv("GITEA_BASE_URL", "https://gitea.example.com")
_, err := NewClient("owner/repo")
if err == nil {
t.Fatal("expected an error when no token is configured")
}
if !strings.Contains(err.Error(), "STAMP_GITEA_TOKEN") {
t.Fatalf("expected error to mention STAMP_GITEA_TOKEN, got %v", err)
}
}
func TestNewClientPrefersStampToken(t *testing.T) {
srv := newVersionServer(t)
t.Setenv("STAMP_GITEA_TOKEN", "stamp-token")
t.Setenv("GITEA_TOKEN", "fallback-token")
t.Setenv("GITEA_BASE_URL", srv.URL)
c, err := NewClient("owner/repo")
if err != nil {
t.Fatalf("NewClient returned error: %v", err)
}
if c == nil || c.owner != "owner" || c.repo != "repo" {
t.Fatalf("unexpected client: %+v", c)
}
}
func TestNewClientFallsBackToGiteaToken(t *testing.T) {
srv := newVersionServer(t)
t.Setenv("STAMP_GITEA_TOKEN", "")
t.Setenv("GITEA_TOKEN", "fallback-token")
t.Setenv("GITEA_BASE_URL", srv.URL)
if _, err := NewClient("owner/repo"); err != nil {
t.Fatalf("NewClient returned error: %v", err)
}
}
func TestNewClientRejectsInvalidSlug(t *testing.T) {
t.Setenv("STAMP_GITEA_TOKEN", "stamp-token")
t.Setenv("GITEA_TOKEN", "")
t.Setenv("GITEA_BASE_URL", "https://gitea.example.com")
_, err := NewClient("not-a-slug")
if err == nil {
t.Fatal("expected an error for a slug without owner/repo")
}
if !strings.Contains(err.Error(), "invalid repo slug") {
t.Fatalf("expected an invalid slug error, got %v", err)
}
}
+5 -1
View File
@@ -1,5 +1,5 @@
[tools] [tools]
go = "1.26.1" go = "1.27.1"
[tasks.build] [tasks.build]
run = "go build -o bin/stamp ./cmd/stamp" run = "go build -o bin/stamp ./cmd/stamp"
@@ -12,3 +12,7 @@ run = "golangci-lint run"
[tasks.install] [tasks.install]
run = "go install ./cmd/stamp" run = "go install ./cmd/stamp"
[tasks.check]
description = "Run formatting, vet, build, and tests (the same checks CI runs)"
run = "./scripts/check.sh"
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# check.sh runs every verification step required before a change can land.
# `.gitea/workflows/ci.yml` invokes it on every pull request and every push to
# main, so this script is the single source of truth for what "CI passed" means.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
echo '==> gofmt'
unformatted="$(gofmt -l .)"
if [ -n "$unformatted" ]; then
echo 'These files are not gofmt-formatted:' >&2
printf '%s\n' "$unformatted" >&2
exit 1
fi
echo '==> go mod verify'
go mod verify
echo '==> go vet'
go vet ./...
echo '==> go build'
go build ./...
echo '==> go test'
go test -cover ./...