diff --git a/.github/workflows/__shared-ci.yml b/.github/workflows/__shared-ci.yml index e11f26f..da4198c 100644 --- a/.github/workflows/__shared-ci.yml +++ b/.github/workflows/__shared-ci.yml @@ -24,6 +24,11 @@ jobs: permissions: contents: read id-token: write + test-release: + uses: $/.github/workflows/__test-workflow-release.yml + permissions: + actions: read + contents: read test-action-setup-go: uses: $/.github/workflows/__test-action-setup-go.yml permissions: @@ -50,3 +55,8 @@ jobs: uses: $/.github/workflows/__test-action-parse-ci-reports.yml permissions: contents: read + test-action-package: + uses: $/.github/workflows/__test-action-package.yml + permissions: + actions: read + contents: read diff --git a/.github/workflows/__test-action-package.yml b/.github/workflows/__test-action-package.yml new file mode 100644 index 0000000..069f7d5 --- /dev/null +++ b/.github/workflows/__test-action-package.yml @@ -0,0 +1,47 @@ +--- +name: Internal - Test package action +"on": + workflow_call: null +permissions: {} +jobs: + package: + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + artifact-id: ${{ steps.package.outputs.artifact-id }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + fetch-depth: 0 + - name: Assert - Package contract tests + uses: hoverkraft-tech/ci-github-nodejs/actions/test@191d7230d57982bfc11d57f68b005f386a6d7fbf # 3.1.1 + with: + command: test:ci + arguments: '["actions/package/action.test.cjs"]' + coverage: "" + comment: "false" + - name: Act - Package fixture + id: package + uses: $/actions/package + with: + working-directory: tests/go-project + verify: + needs: package + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + steps: + - uses: hoverkraft-tech/ci-github-common/actions/download-artifact@af0bdd6313bd49aaf4a8a7f0de005fb0db856b03 # 4.3.3 + with: + artifact-ids: ${{ needs.package.outputs.artifact-id }} + path: ${{ runner.temp }}/go-release-fixture + - name: Verify retained archives and checksums + shell: bash + working-directory: ${{ runner.temp }}/go-release-fixture + run: | + sha256sum --check checksums.txt + tar -xzf sample_*.tar.gz + test "$(./sample)" = 5 diff --git a/.github/workflows/__test-workflow-continuous-integration.yml b/.github/workflows/__test-workflow-continuous-integration.yml index 7f94995..873ef02 100644 --- a/.github/workflows/__test-workflow-continuous-integration.yml +++ b/.github/workflows/__test-workflow-continuous-integration.yml @@ -28,6 +28,7 @@ jobs: working-directory: tests/go-project go-versions: '["1.26", "1.27"]' dependency-review: false + package: "true" checks-disabled: uses: $/.github/workflows/continuous-integration.yml permissions: diff --git a/.github/workflows/__test-workflow-release.yml b/.github/workflows/__test-workflow-release.yml new file mode 100644 index 0000000..6faebb6 --- /dev/null +++ b/.github/workflows/__test-workflow-release.yml @@ -0,0 +1,20 @@ +--- +name: Internal - Test release workflows +"on": + workflow_call: null +permissions: {} +jobs: + contracts: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: hoverkraft-tech/ci-github-nodejs/actions/test@191d7230d57982bfc11d57f68b005f386a6d7fbf # 3.1.1 + with: + command: test:ci + arguments: '["tests/release.test.cjs"]' + coverage: "" + comment: "false" diff --git a/.github/workflows/continuous-integration.md b/.github/workflows/continuous-integration.md index f2b93bd..c4cf08a 100644 --- a/.github/workflows/continuous-integration.md +++ b/.github/workflows/continuous-integration.md @@ -94,6 +94,12 @@ with: inside the checkout. Each invocation uses a unique artifact name. Build output is not published as a release. +Set `package: "true"` to produce GoReleaser snapshot archives after enabled checks. +For releases, pass `package: '{"tag":"v1.2.3"}'` using the tag from +[prepare-package-release](prepare-package-release.md). The immutable +`package-artifact-id` is passed unchanged to [release](release.md). Packaging uses +the primary Go version and the project GoReleaser configuration; it never publishes. + ### Reports and permissions Tests retain JUnit and supported coverage files for seven days, including after @@ -111,7 +117,9 @@ JUnit, not native Go coverage. Coverage details remain in each test job summary. `test: '{"coverage":"codecov"}'` enables OIDC upload. The expected coverage file is `coverage.out`. A custom command must produce -the applicable file. `coverage` controls publication, not collection, and an +the applicable file. `test: '{"coverage":"coveralls"}'` publishes that same profile +to Coveralls with the job token and retains GitHub summaries/artifacts; enable +the repository in Coveralls first. `coverage` controls publication, not collection, and an empty value still retains JUnit results. The reusable workflow declares `id-token: write` for Codecov and callers must grant it, including for default GitHub reports. Standalone GitHub reporting requires only read permissions. @@ -144,7 +152,7 @@ on: permissions: {} jobs: continuous-integration: - uses: hoverkraft-tech/ci-github-go/.github/workflows/continuous-integration.yml@3a72b809f7253a916ee2f4bcee59a66bbba131d3 # main + uses: hoverkraft-tech/ci-github-go/.github/workflows/continuous-integration.yml@86f7d46b31948da93b2bcf78478e3180b908a6b6 # feat/reusable-go-release-workflows permissions: contents: read id-token: write @@ -168,7 +176,7 @@ jobs: # Default: `true` lint: "true" - # true for default tests, a trusted Bash command, or a JSON object with command, coverage (`github`, `codecov` or empty), and race (boolean). false, null or empty disables tests. Coverage publication runs only on the last version; the command controls collection. + # true for default tests, a trusted Bash command, or a JSON object with command, coverage (`github`, `codecov`, `coveralls` or empty), and race (boolean). false, null or empty disables tests. Coverage publication runs only on the last version; the command controls collection. # Default: `true` test: "true" @@ -184,6 +192,10 @@ jobs: # Default: `true` build: "true" + # true for GoReleaser snapshot archives, or JSON with tag, goreleaser-version and artifact-paths. false, null or empty disables packaging. Runs after all enabled checks pass. + # Default: `false` + package: "false" + # Pinned golangci-lint v2 release used by the lint action. # Default: `v2.15.0` golangci-lint-version: v2.15.0 @@ -197,18 +209,19 @@ jobs: ### Workflow Call Inputs -| **Input** | **Description** | **Required** | **Type** | **Default** | -| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------- | ------------------- | -| **`runs-on`** | JSON array of Linux runner labels for all jobs. | **false** | **string** | `["ubuntu-latest"]` | -| **`checks`** | Enable all checks, including build. | **false** | **boolean** | `true` | -| **`working-directory`** | One project directory inside the checkout. Use a caller matrix for multiple projects. | **false** | **string** | `.` | -| **`go-versions`** | JSON array of Go versions. The last entry runs lint, audit and build and publishes coverage. Empty runs project detection once. An empty entry uses the project version. | **false** | **string** | - | -| **`lint`** | true for default checks, a trusted Bash command, or a JSON object with command. false, null or empty disables lint. | **false** | **string** | `true` | -| **`test`** | true for default tests, a trusted Bash command, or a JSON object with command, coverage (`github`, `codecov` or empty), and race (boolean). false, null or empty disables tests. Coverage publication runs only on the last version; the command controls collection. | **false** | **string** | `true` | -| **`audit`** | Check production dependencies for known vulnerabilities. | **false** | **boolean** | `true` | -| **`dependency-review`** | Review dependency changes on pull requests. Requires GitHub dependency review availability. | **false** | **boolean** | `true` | -| **`build`** | true for go build, a trusted Bash command, or a JSON object with command and artifact (one project-relative directory). false, null or empty disables build. | **false** | **string** | `true` | -| **`golangci-lint-version`** | Pinned golangci-lint v2 release used by the lint action. | **false** | **string** | `v2.15.0` | +| **Input** | **Description** | **Required** | **Type** | **Default** | +| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------- | ------------------- | +| **`runs-on`** | JSON array of Linux runner labels for all jobs. | **false** | **string** | `["ubuntu-latest"]` | +| **`checks`** | Enable all checks, including build. | **false** | **boolean** | `true` | +| **`working-directory`** | One project directory inside the checkout. Use a caller matrix for multiple projects. | **false** | **string** | `.` | +| **`go-versions`** | JSON array of Go versions. The last entry runs lint, audit and build and publishes coverage. Empty runs project detection once. An empty entry uses the project version. | **false** | **string** | - | +| **`lint`** | true for default checks, a trusted Bash command, or a JSON object with command. false, null or empty disables lint. | **false** | **string** | `true` | +| **`test`** | true for default tests, a trusted Bash command, or a JSON object with command, coverage (`github`, `codecov`, `coveralls` or empty), and race (boolean). false, null or empty disables tests. Coverage publication runs only on the last version; the command controls collection. | **false** | **string** | `true` | +| **`audit`** | Check production dependencies for known vulnerabilities. | **false** | **boolean** | `true` | +| **`dependency-review`** | Review dependency changes on pull requests. Requires GitHub dependency review availability. | **false** | **boolean** | `true` | +| **`build`** | true for go build, a trusted Bash command, or a JSON object with command and artifact (one project-relative directory). false, null or empty disables build. | **false** | **string** | `true` | +| **`package`** | true for GoReleaser snapshot archives, or JSON with tag, goreleaser-version and artifact-paths. false, null or empty disables packaging. Runs after all enabled checks pass. | **false** | **string** | `false` | +| **`golangci-lint-version`** | Pinned golangci-lint v2 release used by the lint action. | **false** | **string** | `v2.15.0` | @@ -219,9 +232,10 @@ jobs: ## Outputs -| **Output** | **Description** | -| ----------------------- | ---------------------------------------------------- | -| **`build-artifact-id`** | Build artifact ID when build.artifact is configured. | +| **Output** | **Description** | +| ------------------------- | ------------------------------------------------------------------------------------ | +| **`package-artifact-id`** | Immutable GoReleaser archive artifact ID, available only after successful packaging. | +| **`build-artifact-id`** | Build artifact ID when build.artifact is configured. | diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9539d4f..6005250 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -64,6 +64,12 @@ # inside the checkout. Each invocation uses a unique artifact name. # Build output is not published as a release. # +# Set `package: "true"` to produce GoReleaser snapshot archives after enabled checks. +# For releases, pass `package: '{"tag":"v1.2.3"}'` using the tag from +# [prepare-package-release](prepare-package-release.md). The immutable +# `package-artifact-id` is passed unchanged to [release](release.md). Packaging uses +# the primary Go version and the project GoReleaser configuration; it never publishes. +# # ### Reports and permissions # # Tests retain JUnit and supported coverage files for seven days, including after @@ -81,7 +87,9 @@ # # `test: '{"coverage":"codecov"}'` enables OIDC upload. The expected coverage file is # `coverage.out`. A custom command must produce -# the applicable file. `coverage` controls publication, not collection, and an +# the applicable file. `test: '{"coverage":"coveralls"}'` publishes that same profile +# to Coveralls with the job token and retains GitHub summaries/artifacts; enable +# the repository in Coveralls first. `coverage` controls publication, not collection, and an # empty value still retains JUnit results. The reusable workflow declares # `id-token: write` for Codecov and callers must grant it, including for default # GitHub reports. Standalone GitHub reporting requires only read permissions. @@ -117,7 +125,7 @@ name: Go Continuous Integration type: string default: "true" test: - description: true for default tests, a trusted Bash command, or a JSON object with command, coverage (`github`, `codecov` or empty), and race (boolean). false, null or empty disables tests. Coverage publication runs only on the last version; the command controls collection. + description: true for default tests, a trusted Bash command, or a JSON object with command, coverage (`github`, `codecov`, `coveralls` or empty), and race (boolean). false, null or empty disables tests. Coverage publication runs only on the last version; the command controls collection. type: string default: "true" audit: @@ -132,11 +140,18 @@ name: Go Continuous Integration description: true for go build, a trusted Bash command, or a JSON object with command and artifact (one project-relative directory). false, null or empty disables build. type: string default: "true" + package: + description: true for GoReleaser snapshot archives, or JSON with tag, goreleaser-version and artifact-paths. false, null or empty disables packaging. Runs after all enabled checks pass. + type: string + default: "false" golangci-lint-version: description: Pinned golangci-lint v2 release used by the lint action. type: string default: v2.15.0 outputs: + package-artifact-id: + description: Immutable GoReleaser archive artifact ID, available only after successful packaging. + value: ${{ jobs.package.outputs.artifact-id }} build-artifact-id: description: Build artifact ID when build.artifact is configured. value: ${{ jobs.build.outputs.artifact-id }} @@ -151,6 +166,7 @@ jobs: lint: ${{ steps.config.outputs.lint }} test: ${{ steps.config.outputs.test }} build: ${{ steps.config.outputs.build }} + package: ${{ steps.config.outputs.package }} steps: - id: config uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 @@ -159,6 +175,7 @@ jobs: LINT: ${{ inputs.lint }} TEST: ${{ inputs.test }} BUILD: ${{ inputs.build }} + PACKAGE: ${{ inputs.package }} with: script: | const versions = process.env.VERSIONS.trim() ? JSON.parse(process.env.VERSIONS) : ['']; @@ -185,13 +202,18 @@ jobs: } const lint = options('lint', process.env.LINT, {command: ''}); const test = options('test', process.env.TEST, {"command": "", "coverage": "github", "race": true}); - if (test && !['', 'github', 'codecov'].includes(test.coverage)) throw new Error('test.coverage must be github, codecov or empty.'); + if (test && !['', 'github', 'codecov', 'coveralls'].includes(test.coverage)) throw new Error('test.coverage must be github, codecov, coveralls or empty.'); const build = options('build', process.env.BUILD, {command: 'go build -mod=readonly -trimpath ./...', artifact: ''}); const artifact = build?.artifact; if (artifact && (artifact === '.' || artifact.startsWith('/') || artifact.includes('\\') || artifact.split('/').includes('..') || /[\r\n*?]/.test(artifact))) { throw new Error('build.artifact must be one directory inside working-directory.'); } if (build && !build.command.trim()) throw new Error('build.command must not be empty.'); + const packaging = options('package', process.env.PACKAGE, { + tag: '', 'goreleaser-version': '~> v2', + 'artifact-paths': 'dist/*.tar.gz\ndist/*.zip\ndist/checksums.txt' + }); + core.setOutput('package', JSON.stringify(packaging)); core.setOutput('build', JSON.stringify(build)); core.setOutput('versions', versions); core.setOutput('primary-version', versions.at(-1)); @@ -299,3 +321,28 @@ jobs: retention-days: 7 outputs: artifact-id: ${{ steps.upload-build.outputs.artifact-id }} + package: + if: >- + !cancelled() && inputs.checks && needs.configuration.result == 'success' && + needs.configuration.outputs.package != 'null' && + !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') + needs: [configuration, dependency-review, lint, test, audit, build] + runs-on: ${{ fromJSON(inputs.runs-on) }} + timeout-minutes: 30 + permissions: + contents: read + outputs: + artifact-id: ${{ steps.package.outputs.artifact-id }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + fetch-depth: 0 + - id: package + uses: $/actions/package + with: + working-directory: ${{ inputs.working-directory }} + go-version: ${{ needs.configuration.outputs.primary-version }} + tag: ${{ fromJSON(needs.configuration.outputs.package).tag }} + goreleaser-version: ${{ fromJSON(needs.configuration.outputs.package).goreleaser-version }} + artifact-paths: ${{ fromJSON(needs.configuration.outputs.package).artifact-paths }} diff --git a/.github/workflows/prepare-package-release.md b/.github/workflows/prepare-package-release.md new file mode 100644 index 0000000..0567baa --- /dev/null +++ b/.github/workflows/prepare-package-release.md @@ -0,0 +1,73 @@ + + +# GitHub Reusable Workflow: Prepare Go Package Release + +
dist/\*.tar.gz
dist/\*.zip
dist/checksums.txt |
+
+
+
+
+## Outputs
+
+| **Output** | **Description** |
+| ----------------- | --------------------------------------------------------------------------------- |
+| **`artifact-id`** | Immutable artifact ID containing archives and checksums from this run and commit. |
+
+
diff --git a/actions/package/action.test.cjs b/actions/package/action.test.cjs
new file mode 100644
index 0000000..39defee
--- /dev/null
+++ b/actions/package/action.test.cjs
@@ -0,0 +1,97 @@
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const path = require("node:path");
+const { spawnSync, execFileSync } = require("node:child_process");
+const test = require("node:test");
+const YAML = require("yaml");
+const { createWorkspace } = require("../../tests/action-test-helpers.cjs");
+const action = YAML.parse(
+ fs.readFileSync(path.join(__dirname, "action.yml"), "utf8"),
+);
+const packageStep = (id) => action.runs.steps.find((entry) => entry.id === id);
+const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
+const context = { runId: 42, sha: "abc123" };
+
+test("packaging keeps existing tags intact and fails on a conflicting commit", (t) => {
+ const directory = createWorkspace(t);
+ const git = (...args) =>
+ execFileSync("git", args, {
+ cwd: directory,
+ encoding: "utf8",
+ env: { ...process.env, GIT_CONFIG_GLOBAL: "/dev/null" },
+ }).trim();
+ git("init", "--quiet");
+ git(
+ "-c",
+ "user.name=Test",
+ "-c",
+ "user.email=test@example.com",
+ "-c",
+ "commit.gpgsign=false",
+ "commit",
+ "--allow-empty",
+ "-m",
+ "fixture",
+ );
+ const sha = git("rev-parse", "HEAD");
+ const tag = (value, commit = sha) =>
+ spawnSync("bash", ["-euo", "pipefail", "-c", packageStep("tag").run], {
+ cwd: directory,
+ encoding: "utf8",
+ timeout: 10000,
+ env: {
+ ...process.env,
+ GIT_CONFIG_GLOBAL: "/dev/null",
+ RELEASE_TAG: value,
+ GITHUB_SHA: commit,
+ },
+ });
+ assert.equal(tag("").status, 0);
+ assert.equal(git("tag", "--list"), "");
+ for (let attempt = 0; attempt < 2; attempt++)
+ assert.equal(tag("v1.2.3").status, 0);
+ assert.equal(git("rev-parse", "v1.2.3"), sha);
+ assert.notEqual(tag("v1.2.3", "different").status, 0);
+ assert.equal(git("rev-parse", "v1.2.3"), sha);
+ assert.notEqual(tag("-invalid").status, 0);
+});
+
+test("artifact paths stay inside the project and names bind archives to tag and run", async () => {
+ const configure = new AsyncFunction(
+ "require",
+ "core",
+ "context",
+ "process",
+ packageStep("artifact").with.script,
+ );
+ const outputs = {};
+ const run = (files) =>
+ configure(
+ require,
+ {
+ setOutput: (key, value) => {
+ outputs[key] = value;
+ },
+ },
+ context,
+ {
+ env: {
+ GITHUB_WORKSPACE: "/workspace",
+ DIRECTORY: "project",
+ PATHS: files,
+ TAG: "v1.2.3",
+ GITHUB_RUN_ATTEMPT: "2",
+ },
+ },
+ );
+ await run("dist/*.tar.gz\ndist/checksums.txt");
+ assert.equal(
+ outputs.paths,
+ ["dist/*.tar.gz", "dist/checksums.txt"]
+ .map((file) => path.join("/workspace/project", file))
+ .join("\n"),
+ );
+ assert.match(outputs.name, /^go-release-v1\.2\.3-42-2-/);
+ for (const value of ["", "../secret", "/etc/passwd"])
+ await assert.rejects(() => run(value));
+});
diff --git a/actions/package/action.yml b/actions/package/action.yml
new file mode 100644
index 0000000..e2c5043
--- /dev/null
+++ b/actions/package/action.yml
@@ -0,0 +1,96 @@
+# Package Go binaries using the project GoReleaser v2 configuration without publishing.
+# Check out the full Git history before calling this action. An empty tag produces
+# snapshot archives; a planned tag packages the current commit and rejects tag conflicts.
+# Only a local tag is created. The uploaded archives and checksums retain their run,
+# commit and tag identity for release.yml. Call after all required validation.
+# Requires a Linux runner with a supported Go toolchain. See the
+# [release workflow](../../.github/workflows/release.md) for the complete release flow.
+---
+name: Go - Package
+description: Package GoReleaser archives and checksums without publishing.
+author: Hoverkraft
+branding:
+ icon: package
+ color: blue
+inputs:
+ working-directory:
+ description: Go project containing the GoReleaser v2 configuration.
+ default: .
+ go-version:
+ description: Go version for packaging; empty uses project detection.
+ default: ""
+ tag:
+ description: Planned semantic-version tag, optionally prefixed with v. Empty builds snapshots.
+ default: ""
+ goreleaser-version:
+ description: GoReleaser v2 version constraint.
+ default: "~> v2"
+ artifact-paths:
+ description: Archive and checksum globs relative to working-directory, one per line.
+ default: |
+ dist/*.tar.gz
+ dist/*.zip
+ dist/checksums.txt
+outputs:
+ artifact-id:
+ description: Immutable artifact ID containing archives and checksums from this run and commit.
+ value: ${{ steps.upload.outputs.artifact-id }}
+runs:
+ using: composite
+ steps:
+ - uses: $/actions/setup-go
+ with:
+ working-directory: ${{ inputs.working-directory }}
+ go-version: ${{ inputs.go-version }}
+ - name: Set planned version locally
+ id: tag
+ shell: bash
+ env:
+ RELEASE_TAG: ${{ inputs.tag }}
+ run: |
+ if [ -z "$RELEASE_TAG" ]; then exit 0; fi
+ if ! [[ "$RELEASE_TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
+ echo 'tag must be a semantic version, optionally prefixed with v.' >&2
+ exit 1
+ fi
+ if commit=$(git rev-parse --verify --quiet "refs/tags/$RELEASE_TAG^{commit}"); then
+ test "$commit" = "$GITHUB_SHA" || { echo 'Tag belongs to a different commit.' >&2; exit 1; }
+ else
+ git -c tag.gpgSign=false tag -- "$RELEASE_TAG" "$GITHUB_SHA"
+ fi
+ - name: Package without publication
+ uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0
+ with:
+ version: ${{ inputs.goreleaser-version }}
+ workdir: ${{ inputs.working-directory }}
+ args: release --clean --skip=publish ${{ inputs.tag == '' && '--snapshot' || '' }}
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
+ - id: artifact
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
+ env:
+ DIRECTORY: ${{ inputs.working-directory }}
+ PATHS: ${{ inputs.artifact-paths }}
+ TAG: ${{ inputs.tag }}
+ with:
+ script: |
+ const path = require('node:path');
+ const files = process.env.PATHS.split(/\r?\n/).map(value => value.trim()).filter(Boolean);
+ if (!files.length) throw new Error('artifact-paths must contain at least one path.');
+ const root = path.resolve(process.env.GITHUB_WORKSPACE);
+ const directory = path.resolve(root, process.env.DIRECTORY);
+ const resolved = files.map(file => path.resolve(directory, file));
+ if (resolved.some(file => !file.startsWith(directory + path.sep))) {
+ throw new Error('artifact-paths must stay inside working-directory.');
+ }
+ core.setOutput('paths', resolved.join('\n'));
+ core.setOutput('name', `go-release-${process.env.TAG || 'snapshot'}-${context.runId}-${process.env.GITHUB_RUN_ATTEMPT}-${require('node:crypto').randomUUID()}`);
+ - name: Retain packaged archives
+ id: upload
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+ with:
+ name: ${{ steps.artifact.outputs.name }}
+ path: ${{ steps.artifact.outputs.paths }}
+ if-no-files-found: error
+ compression-level: 0
+ retention-days: 7
diff --git a/actions/test/README.md b/actions/test/README.md
index 2a95a25..490faba 100644
--- a/actions/test/README.md
+++ b/actions/test/README.md
@@ -48,7 +48,9 @@ Run [setup-go](../setup-go/README.md) first with the same `working-directory`.
`coverage: "github"` is the default. Set `coverage: "codecov"` and grant the
-job `id-token: write` for OIDC upload of `coverage.out`. An empty coverage
+job `id-token: write` for OIDC upload of `coverage.out`. Use `coverage: "coveralls"`
+to send the same Go profile to Coveralls with the job token and keep native
+GitHub summaries and artifacts. Enable the repository in Coveralls first. An empty coverage
value disables publication while retaining JUnit; collection is controlled by
the command. Custom commands must produce the applicable report files.
@@ -70,7 +72,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int
## Usage
```yaml
-- uses: hoverkraft-tech/ci-github-go/actions/test@3a72b809f7253a916ee2f4bcee59a66bbba131d3 # main
+- uses: hoverkraft-tech/ci-github-go/actions/test@2db38ba3c9d23770c04b71866551231470cd2994 # feat/reusable-go-release-workflows
with:
# Go module directory.
# Default: `.`
@@ -83,7 +85,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int
# Default: `true`
race: "true"
- # Publication only: `github` (native go tool cover summary), `codecov`, or empty. Collection is controlled by the test command.
+ # Publication only: `github` (native go tool cover summary), `codecov`, `coveralls`, or empty. Collection is controlled by the test command.
# Default: `github`
coverage: github
@@ -97,13 +99,13 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int
## Inputs
-| **Input** | **Description** | **Required** | **Default** |
-| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------- |
-| **`working-directory`** | Go module directory. | **false** | `.` |
-| **`command`** | Trusted Bash command replacing the default test command. Generate junit.xml and coverage.out for reporting. | **false** | - |
-| **`race`** | Enable the race detector for the default command. Requires CGO and a C compiler. | **false** | `true` |
-| **`coverage`** | Publication only: `github` (native go tool cover summary), `codecov`, or empty. Collection is controlled by the test command. | **false** | `github` |
-| **`report-group`** | Outer calling job ID for consolidated ci-reports. Defaults to the current job ID. No individual PR comments are posted. | **false** | - |
+| **Input** | **Description** | **Required** | **Default** |
+| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------ | ----------- |
+| **`working-directory`** | Go module directory. | **false** | `.` |
+| **`command`** | Trusted Bash command replacing the default test command. Generate junit.xml and coverage.out for reporting. | **false** | - |
+| **`race`** | Enable the race detector for the default command. Requires CGO and a C compiler. | **false** | `true` |
+| **`coverage`** | Publication only: `github` (native go tool cover summary), `codecov`, `coveralls`, or empty. Collection is controlled by the test command. | **false** | `github` |
+| **`report-group`** | Outer calling job ID for consolidated ci-reports. Defaults to the current job ID. No individual PR comments are posted. | **false** | - |
@@ -114,10 +116,10 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int
## Outputs
-| **Output** | **Description** |
-| -------------------------- | ------------------------------------------------------------------------------- |
-| **`report-artifact-id`** | Native report artifact ID. Empty when no reports were produced. |
-| **`coverage-artifact-id`** | Native coverage.out artifact ID for GitHub coverage, or empty when unavailable. |
+| **Output** | **Description** |
+| -------------------------- | -------------------------------------------------------------------------------------------- |
+| **`report-artifact-id`** | Native report artifact ID. Empty when no reports were produced. |
+| **`coverage-artifact-id`** | Native coverage.out artifact ID for GitHub or Coveralls coverage, or empty when unavailable. |
diff --git a/actions/test/action.test.cjs b/actions/test/action.test.cjs
index 25ba88b..d01049e 100644
--- a/actions/test/action.test.cjs
+++ b/actions/test/action.test.cjs
@@ -34,11 +34,13 @@ test("test configuration rejects unsupported coverage destinations", (t) => {
}).status,
0,
);
- assert.equal(
- runActionStep(actionFile, "validate", directory, {
- COVERAGE: "",
- RACE: "true",
- }).status,
- 0,
- );
+ for (const coverage of ["", "github", "codecov", "coveralls"]) {
+ assert.equal(
+ runActionStep(actionFile, "validate", directory, {
+ COVERAGE: coverage,
+ RACE: "true",
+ }).status,
+ 0,
+ );
+ }
});
diff --git a/actions/test/action.yml b/actions/test/action.yml
index 26de574..216a985 100644
--- a/actions/test/action.yml
+++ b/actions/test/action.yml
@@ -20,7 +20,9 @@ description: |
`coverage: "github"` is the default. Set `coverage: "codecov"` and grant the
- job `id-token: write` for OIDC upload of `coverage.out`. An empty coverage
+ job `id-token: write` for OIDC upload of `coverage.out`. Use `coverage: "coveralls"`
+ to send the same Go profile to Coveralls with the job token and keep native
+ GitHub summaries and artifacts. Enable the repository in Coveralls first. An empty coverage
value disables publication while retaining JUnit; collection is controlled by
the command. Custom commands must produce the applicable report files.
@@ -46,7 +48,7 @@ inputs:
description: Enable the race detector for the default command. Requires CGO and a C compiler.
default: "true"
coverage:
- description: "Publication only: `github` (native go tool cover summary), `codecov`, or empty. Collection is controlled by the test command."
+ description: "Publication only: `github` (native go tool cover summary), `codecov`, `coveralls`, or empty. Collection is controlled by the test command."
default: github
report-group:
description: Outer calling job ID for consolidated ci-reports. Defaults to the current job ID. No individual PR comments are posted.
@@ -56,7 +58,7 @@ outputs:
description: Native report artifact ID. Empty when no reports were produced.
value: ${{ steps.report-artifact.outputs.artifact-id }}
coverage-artifact-id:
- description: Native coverage.out artifact ID for GitHub coverage, or empty when unavailable.
+ description: Native coverage.out artifact ID for GitHub or Coveralls coverage, or empty when unavailable.
value: ${{ steps.report-artifact.outputs.coverage-artifact-id }}
runs:
using: composite
@@ -72,7 +74,7 @@ runs:
COVERAGE: ${{ inputs.coverage }}
run: |
case "$RACE" in true|false) ;; *) echo 'race must be true or false.' >&2; exit 1 ;; esac
- case "$COVERAGE" in github|codecov|'') ;; *) echo 'coverage must be github, codecov or empty.' >&2; exit 1 ;; esac
+ case "$COVERAGE" in github|codecov|coveralls|'') ;; *) echo 'coverage must be github, codecov, coveralls or empty.' >&2; exit 1 ;; esac
- id: run
shell: bash
working-directory: ${{ steps.directory.outputs.absolute-path }}
@@ -104,10 +106,10 @@ runs:
report-paths: auto:test
report-name: Go test results
group: ${{ inputs.report-group || github.job }}
- native-coverage: ${{ inputs.coverage == 'github' }}
+ native-coverage: ${{ (inputs.coverage == 'github' || inputs.coverage == 'coveralls') }}
- id: go-coverage
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
- if: ${{ !cancelled() && steps.run.outcome != 'skipped' && inputs.coverage == 'github' }}
+ if: ${{ !cancelled() && steps.run.outcome != 'skipped' && (inputs.coverage == 'github' || inputs.coverage == 'coveralls') }}
env:
DIRECTORY: ${{ steps.directory.outputs.absolute-path }}
with:
@@ -125,3 +127,10 @@ runs:
working-directory: ${{ steps.directory.outputs.absolute-path }}
files: coverage.out
fail-ci-if-error: "true"
+ - name: Upload coverage to Coveralls
+ if: ${{ !cancelled() && steps.run.outcome != 'skipped' && inputs.coverage == 'coveralls' }}
+ uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
+ with:
+ base-path: ${{ steps.directory.outputs.absolute-path }}
+ file: ${{ steps.directory.outputs.absolute-path }}/coverage.out
+ format: golang
diff --git a/docs/README.md b/docs/README.md
index 472d897..409c998 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -4,3 +4,8 @@
- [Development](development/README.md): setup, tests, linting and maintenance.
- [Tooling decision](adr/0001-language-ci.md): scope and trade-offs.
- [Workflow reference](../.github/workflows/continuous-integration.md): usage, configuration, inputs and outputs.
+
+- [Release preparation](../.github/workflows/prepare-package-release.md): plan or recover a release.
+- [Package action](../actions/package/README.md): snapshot and planned binary archives.
+- [Release publication](../.github/workflows/release.md): publish validated archives without rebuilding.
+- [Release flow decision](adr/0003-consistent-consumer-release-flow.md): boundaries and trade-offs.
diff --git a/docs/adr/0002-consumer-release-artifacts.md b/docs/adr/0002-consumer-release-artifacts.md
new file mode 100644
index 0000000..7f69b72
--- /dev/null
+++ b/docs/adr/0002-consumer-release-artifacts.md
@@ -0,0 +1,30 @@
+# ADR 0002: Separate consumer packaging from publication
+
+- Status: Superseded by [ADR 0003](0003-consistent-consumer-release-flow.md)
+- Date: 2026-11-25
+
+## Context
+
+next-ip needs the same GoReleaser packaging in PR validation and releases. Its
+release job must publish the validated archives without rebuilding them with a
+write token. The existing build action checks compilation but does not package
+platform archives or manage planned release versions.
+
+## Decision
+
+Provide `build-release.yml` for read-only packaging and `release.yml` for
+publication. Consumers retain their release planning, no-change gates and required
+validation in their own workflow. GoReleaser owns project targets and archive layout;
+ci-github-publish owns release configuration, notes, assets and optional summaries.
+
+A unique artifact ID carries archives and checksums between jobs. Before publication,
+verify its run, source commit, planned tag and expiry. Snapshot artifacts cannot be
+published. Existing local tags must resolve to the source commit; never move them.
+Only the publication job receives write permissions and optional environment approval.
+
+## Consequences
+
+Consumers can validate snapshots without publishing and retry publication with the
+same retained artifact. Deleted or expired artifacts require packaging again.
+Required application checks remain the caller's responsibility, expressed by `needs`.
+No consumer-specific credentials or registry policy enter the public workflow.
diff --git a/docs/adr/0003-consistent-consumer-release-flow.md b/docs/adr/0003-consistent-consumer-release-flow.md
new file mode 100644
index 0000000..ddf9f72
--- /dev/null
+++ b/docs/adr/0003-consistent-consumer-release-flow.md
@@ -0,0 +1,29 @@
+# ADR 0003: Use the shared prepare, validate and release flow
+
+- Status: Accepted
+- Date: 2026-11-26
+- Supersedes: [ADR 0002](0002-consumer-release-artifacts.md)
+
+## Context
+
+Review of the consumer release workflows requested the same public naming and
+behavior used by the Node.js and PHP repositories. Standalone release packaging
+left change detection and recovery logic duplicated in consumers.
+
+## Decision
+
+Use `prepare-package-release.yml` to plan the tag and return `ready`, `no-changes`
+or `released`, including verification for manual tag recovery. Only `ready` continues.
+The `package` option in `continuous-integration.yml` calls the standalone package
+action after enabled checks pass. `release.yml` publishes the retained archives.
+
+GoReleaser still owns targets and archive layout. Packaging creates only a local
+tag. Publication verifies artifact run, source commit, tag and expiry, and cannot
+publish snapshots. The shared release action owns notes and asset recovery.
+
+## Consequences
+
+Consumers follow the same three phases as sibling language repositories, while
+keeping project-specific validation. Existing tag conflict and artifact provenance
+checks remain. Dedicated hosted tests cover archive transfer; local contract tests
+cover preparation status and failure paths without publishing a release.
diff --git a/docs/development/README.md b/docs/development/README.md
index c779a66..505542f 100644
--- a/docs/development/README.md
+++ b/docs/development/README.md
@@ -89,9 +89,17 @@ and Renovate automation. Enable the CI bot only after repository settings and
branch protection are configured. Release and generated-documentation writes
are gated on the client ID. Public CI needs none of these credentials.
-The release automation versions this Actions repository. It does not publish
-consumer libraries or application binaries. Configure consumer publishing in
-the consumer repository using its registry and release policy.
+The internal release automation versions this Actions repository. Consumer releases
+use `prepare-package-release.yml`, `continuous-integration.yml` with packaging enabled,
+and `release.yml`. Preparation returns `ready`, `no-changes` or `released`; only
+`ready` continues. The package action keeps platform targets and archive layout in
+the consumer's GoReleaser configuration. Publication consumes the validated artifact
+without rebuilding. See the generated workflow references.
+
+Contract tests cover preparation triggers, no-change and published-release gates,
+tag recovery, tag collisions and artifact provenance. The dedicated package action
+workflow verifies a real GoReleaser archive transfer, checksums and executable.
+The reusable CI fixture also exercises its optional packaging stage.
## Branding
diff --git a/tests/config.test.cjs b/tests/config.test.cjs
index aecdd55..4eb6519 100644
--- a/tests/config.test.cjs
+++ b/tests/config.test.cjs
@@ -115,3 +115,22 @@ test("rejects unsafe build artifact directories and empty commands", async () =>
false,
);
});
+
+test("accepts Coveralls coverage configuration", async () => {
+ const result = await parse({ TEST: '{"coverage":"coveralls"}' });
+ assert.equal(JSON.parse(result.test).coverage, "coveralls");
+});
+
+test("packaging is opt-in and accepts only declared GoReleaser settings", async () => {
+ assert.equal((await parse()).package, "null");
+ const snapshot = JSON.parse((await parse({ PACKAGE: "true" })).package);
+ assert.equal(snapshot.tag, "");
+ assert.match(snapshot["artifact-paths"], /checksums[.]txt/);
+ const release = JSON.parse(
+ (await parse({ PACKAGE: '{"tag":"v1.2.3"}' })).package,
+ );
+ assert.equal(release.tag, "v1.2.3");
+ for (const value of ['{"tag":false}', '{"unknown":true}', "go build", "[]"]) {
+ await assert.rejects(() => parse({ PACKAGE: value }));
+ }
+});
diff --git a/tests/go-project/.goreleaser.yml b/tests/go-project/.goreleaser.yml
new file mode 100644
index 0000000..e65528f
--- /dev/null
+++ b/tests/go-project/.goreleaser.yml
@@ -0,0 +1,14 @@
+---
+version: 2
+project_name: sample
+builds:
+ - main: ./cmd/sample
+ env: [CGO_ENABLED=0]
+ goos: [linux]
+ goarch: [amd64]
+archives:
+ - formats: [tar.gz]
+checksum:
+ name_template: checksums.txt
+changelog:
+ disable: true
diff --git a/tests/go-project/cmd/sample/main.go b/tests/go-project/cmd/sample/main.go
new file mode 100644
index 0000000..b77c8f5
--- /dev/null
+++ b/tests/go-project/cmd/sample/main.go
@@ -0,0 +1,11 @@
+package main
+
+import (
+ "fmt"
+
+ sample "example.com/ci-go-fixture"
+)
+
+func main() {
+ fmt.Println(sample.Sum(2, 3))
+}
diff --git a/tests/release.test.cjs b/tests/release.test.cjs
new file mode 100644
index 0000000..8d125a6
--- /dev/null
+++ b/tests/release.test.cjs
@@ -0,0 +1,172 @@
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const test = require("node:test");
+const YAML = require("yaml");
+
+function step(workflow, job, id) {
+ return YAML.parse(
+ fs.readFileSync(`.github/workflows/${workflow}.yml`, "utf8"),
+ ).jobs[job].steps.find((entry) => entry.id === id);
+}
+const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
+const verify = new AsyncFunction(
+ "github",
+ "context",
+ "process",
+ step("release", "verify", "verify").with.script,
+);
+const context = {
+ repo: { owner: "example", repo: "app" },
+ runId: 42,
+ sha: "abc123",
+ eventName: "workflow_dispatch",
+};
+const artifact = {
+ name: "go-release-v1.2.3-42-1-unique",
+ expired: false,
+ workflow_run: { id: 42, head_sha: "abc123" },
+};
+function check(data = artifact, overrides = {}, event = context.eventName) {
+ return verify(
+ { rest: { actions: { getArtifact: async () => ({ data }) } } },
+ { ...context, eventName: event },
+ { env: { TAG: "v1.2.3", ARTIFACT_ID: "123", ...overrides } },
+ );
+}
+
+test("release accepts this run's artifact, including a previous attempt", async () => {
+ await check();
+});
+
+test("release rejects mismatched artifacts and untrusted publication contexts", async () => {
+ for (const invalid of [
+ { ...artifact, expired: true },
+ { ...artifact, workflow_run: { id: 41, head_sha: context.sha } },
+ { ...artifact, workflow_run: { id: context.runId, head_sha: "other" } },
+ { ...artifact, name: "go-release-snapshot-42-1-unique" },
+ { ...artifact, name: "go-release-v1.2.4-42-1-unique" },
+ ])
+ await assert.rejects(
+ () => check(invalid),
+ /Expected an available release artifact/,
+ );
+ for (const id of ["", "0", "1,2", "1e3", "9007199254740992"]) {
+ await assert.rejects(
+ () => check(artifact, { ARTIFACT_ID: id }),
+ /positive integer/,
+ );
+ }
+ await assert.rejects(
+ () => check(artifact, { TAG: "../tag" }),
+ /semantic version/,
+ );
+ await assert.rejects(
+ () => check(artifact, {}, "pull_request_target"),
+ /cannot publish/,
+ );
+});
+
+function preparation(id, args) {
+ return new AsyncFunction(
+ ...args,
+ step("prepare-package-release", "prepare", id).with.script,
+ );
+}
+
+test("preparation allows trusted default-branch runs and manual tag retries", async () => {
+ const event = preparation("event", ["context"]);
+ const payload = { repository: { default_branch: "main" } };
+ for (const [eventName, ref] of [
+ ["workflow_dispatch", "refs/heads/main"],
+ ["schedule", "refs/heads/main"],
+ ["workflow_dispatch", "refs/tags/v1.2.3"],
+ ])
+ await event({ eventName, ref, payload });
+ for (const [eventName, ref] of [
+ ["pull_request", "refs/heads/main"],
+ ["workflow_dispatch", "refs/heads/feature"],
+ ["schedule", "refs/tags/v1.2.3"],
+ ])
+ await assert.rejects(
+ () => event({ eventName, ref, payload }),
+ /Release preparation requires/,
+ );
+});
+
+test("preparation preserves the planned identity and recognizes tag recovery", async () => {
+ const identity = preparation("identity", ["context", "process", "core"]);
+ const run = async (ref, tag, changes) => {
+ const outputs = {};
+ await identity(
+ { ref },
+ { env: { TAG: tag, HAS_CHANGES: changes } },
+ {
+ setOutput: (key, value) => {
+ outputs[key] = value;
+ },
+ },
+ );
+ return outputs;
+ };
+ assert.deepEqual(await run("refs/heads/main", "v1.2.3", "false"), {
+ "has-changes": false,
+ tag: "v1.2.3",
+ });
+ assert.deepEqual(await run("refs/heads/main", "v1.2.3-rc.1", "true"), {
+ "has-changes": true,
+ tag: "v1.2.3-rc.1",
+ });
+ assert.deepEqual(await run("refs/tags/v1.2.3", "", ""), {
+ "has-changes": true,
+ tag: "v1.2.3",
+ });
+ await assert.rejects(
+ () => run("refs/tags/invalid", "", ""),
+ /semantic versions/,
+ );
+});
+
+test("preparation skips no-change and published releases without suppressing invalid verification", async () => {
+ const result = preparation("result", ["process", "core"]);
+ const run = async (changes, releases) => {
+ const outputs = {};
+ await result(
+ {
+ env: {
+ HAS_CHANGES: changes,
+ TAG: "v1.2.3",
+ RELEASES: JSON.stringify(releases),
+ },
+ },
+ {
+ setOutput: (key, value) => {
+ outputs[key] = value;
+ },
+ info() {},
+ },
+ );
+ return outputs;
+ };
+ assert.deepEqual(await run("false", undefined), {
+ status: "no-changes",
+ tag: "",
+ });
+ assert.deepEqual(await run("true", [{ tag: "v1.2.3", published: false }]), {
+ status: "ready",
+ tag: "v1.2.3",
+ });
+ assert.deepEqual(await run("true", [{ tag: "v1.2.3", published: true }]), {
+ status: "released",
+ tag: "",
+ });
+ for (const invalid of [
+ [],
+ [{ tag: "v1.2.4", published: false }],
+ [{ tag: "v1.2.3" }],
+ ]) {
+ await assert.rejects(
+ () => run("true", invalid),
+ /verified publication state/,
+ );
+ }
+});