From 2db38ba3c9d23770c04b71866551231470cd2994 Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Wed, 25 Nov 2026 22:13:25 +0100 Subject: [PATCH 1/4] feat: add reusable Go release workflows and Coveralls support --- .github/workflows/__shared-ci.yml | 5 + .github/workflows/__test-workflow-release.yml | 44 +++++ .github/workflows/build-release.md | 104 ++++++++++++ .github/workflows/build-release.yml | 118 +++++++++++++ .github/workflows/continuous-integration.md | 32 ++-- .github/workflows/continuous-integration.yml | 8 +- .github/workflows/release.md | 104 ++++++++++++ .github/workflows/release.yml | 106 ++++++++++++ README.md | 2 + actions/test/README.md | 30 ++-- actions/test/action.test.cjs | 16 +- actions/test/action.yml | 21 ++- docs/README.md | 4 + docs/adr/0002-consumer-release-artifacts.md | 30 ++++ docs/development/README.md | 9 +- tests/config.test.cjs | 5 + tests/go-project/.goreleaser.yml | 14 ++ tests/go-project/cmd/sample/main.go | 11 ++ tests/release.test.cjs | 158 ++++++++++++++++++ 19 files changed, 773 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/__test-workflow-release.yml create mode 100644 .github/workflows/build-release.md create mode 100644 .github/workflows/build-release.yml create mode 100644 .github/workflows/release.md create mode 100644 .github/workflows/release.yml create mode 100644 docs/adr/0002-consumer-release-artifacts.md create mode 100644 tests/go-project/.goreleaser.yml create mode 100644 tests/go-project/cmd/sample/main.go create mode 100644 tests/release.test.cjs diff --git a/.github/workflows/__shared-ci.yml b/.github/workflows/__shared-ci.yml index e11f26f..53eb591 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: diff --git a/.github/workflows/__test-workflow-release.yml b/.github/workflows/__test-workflow-release.yml new file mode 100644 index 0000000..f2cee4d --- /dev/null +++ b/.github/workflows/__test-workflow-release.yml @@ -0,0 +1,44 @@ +--- +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" + package: + uses: $/.github/workflows/build-release.yml + permissions: + contents: read + 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/build-release.md b/.github/workflows/build-release.md new file mode 100644 index 0000000..d29c194 --- /dev/null +++ b/.github/workflows/build-release.md @@ -0,0 +1,104 @@ + + +# GitHub Reusable Workflow: Build Go release archives + +
+ Build Go release archives +
+ +--- + + + + +## Overview + +Package Go binaries with the caller's GoReleaser v2 configuration, without publishing. + +Call after the project's required checks. Empty tag builds snapshot archives for CI; +a planned semantic-version tag builds release archives at the current caller commit. +Existing tags must resolve to that commit. Only a local tag is created, using read +permissions. Source tags, releases and registries are never written by this workflow. + +Keep platform targets, archives and checksums in the project's .goreleaser.yml. +artifact-paths selects the exact files handed to release.yml; include the checksums. +Paths are relative to working-directory. Custom paths are trusted caller configuration. +The immutable artifact ID belongs to this run and commit, is bound to the planned +tag, and is retained seven days. A failed build returns no successful artifact ID. +Snapshot artifacts cannot be published through release.yml. + +Use the same working-directory in preparation, validation and publication. See +[release](release.md) for the artifact handoff. Pin callers to a reviewed commit SHA. + +### Permissions + +- **`contents`**: `read` + + + + +## Usage + +```yaml +name: Build Go release archives +on: + push: + branches: + - main +permissions: {} +jobs: + build-release: + uses: hoverkraft-tech/ci-github-go/.github/workflows/build-release.yml@dcc9e10f1938e4496a40edc4e90eb0a6294a8bb2 # 0.0.1 + permissions: + contents: read + with: + # Go project containing the GoReleaser v2 configuration. + # Default: `.` + working-directory: . + + # Go version for packaging; empty uses project detection. + go-version: "" + + # Planned semantic-version tag, optionally prefixed with v. Empty builds snapshots. + tag: "" + + # GoReleaser v2 version constraint. + # Default: `~> v2` + goreleaser-version: ~> v2 + + # Files to retain relative to working-directory, one glob per line. Include release archives and checksums only. + # Default: `dist/*.tar.gz + # dist/*.zip + # dist/checksums.txt + # ` + artifact-paths: | + dist/*.tar.gz + dist/*.zip + dist/checksums.txt +``` + + + + +## Inputs + +### Workflow Call Inputs + +| **Input** | **Description** | **Required** | **Type** | **Default** | +| ------------------------ | -------------------------------------------------------------------------------------------------------------- | ------------ | ---------- | ----------------------------------------------------------------------------------------------------------------------------- | +| **`working-directory`** | Go project containing the GoReleaser v2 configuration. | **false** | **string** | `.` | +| **`go-version`** | Go version for packaging; empty uses project detection. | **false** | **string** | - | +| **`tag`** | Planned semantic-version tag, optionally prefixed with v. Empty builds snapshots. | **false** | **string** | - | +| **`goreleaser-version`** | GoReleaser v2 version constraint. | **false** | **string** | `~> v2` | +| **`artifact-paths`** | Files to retain relative to working-directory, one glob per line. Include release archives and checksums only. | **false** | **string** |
dist/\*.tar.gz
dist/\*.zip
dist/checksums.txt
| + + + + +## Outputs + +| **Output** | **Description** | +| ----------------- | ------------------------------------------------------------------------- | +| **`artifact-id`** | Immutable artifact ID of the packaged archives and checksums in this run. | + + diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..ff9e219 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,118 @@ +# Package Go binaries with the caller's GoReleaser v2 configuration, without publishing. +# +# Call after the project's required checks. Empty tag builds snapshot archives for CI; +# a planned semantic-version tag builds release archives at the current caller commit. +# Existing tags must resolve to that commit. Only a local tag is created, using read +# permissions. Source tags, releases and registries are never written by this workflow. +# +# Keep platform targets, archives and checksums in the project's .goreleaser.yml. +# artifact-paths selects the exact files handed to release.yml; include the checksums. +# Paths are relative to working-directory. Custom paths are trusted caller configuration. +# The immutable artifact ID belongs to this run and commit, is bound to the planned +# tag, and is retained seven days. A failed build returns no successful artifact ID. +# Snapshot artifacts cannot be published through release.yml. +# +# Use the same working-directory in preparation, validation and publication. See +# [release](release.md) for the artifact handoff. Pin callers to a reviewed commit SHA. +--- +name: Build Go release archives +"on": + workflow_call: + inputs: + working-directory: + description: Go project containing the GoReleaser v2 configuration. + type: string + default: . + go-version: + description: Go version for packaging; empty uses project detection. + type: string + default: "" + tag: + description: Planned semantic-version tag, optionally prefixed with v. Empty builds snapshots. + type: string + default: "" + goreleaser-version: + description: GoReleaser v2 version constraint. + type: string + default: "~> v2" + artifact-paths: + description: Files to retain relative to working-directory, one glob per line. Include release archives and checksums only. + type: string + default: | + dist/*.tar.gz + dist/*.zip + dist/checksums.txt + outputs: + artifact-id: + description: Immutable artifact ID of the packaged archives and checksums in this run. + value: ${{ jobs.build.outputs.artifact-id }} +permissions: {} +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: read + outputs: + artifact-id: ${{ job.status == 'success' && steps.upload.outputs.artifact-id || '' }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + fetch-depth: 0 + - 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/.github/workflows/continuous-integration.md b/.github/workflows/continuous-integration.md index f2b93bd..d7ae5eb 100644 --- a/.github/workflows/continuous-integration.md +++ b/.github/workflows/continuous-integration.md @@ -111,7 +111,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 +146,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@dcc9e10f1938e4496a40edc4e90eb0a6294a8bb2 # 0.0.1 permissions: contents: read id-token: write @@ -168,7 +170,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" @@ -197,18 +199,18 @@ 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` | +| **`golangci-lint-version`** | Pinned golangci-lint v2 release used by the lint action. | **false** | **string** | `v2.15.0` | diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9539d4f..a7fa117 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -81,7 +81,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 +119,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: @@ -185,7 +187,7 @@ 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))) { diff --git a/.github/workflows/release.md b/.github/workflows/release.md new file mode 100644 index 0000000..1286543 --- /dev/null +++ b/.github/workflows/release.md @@ -0,0 +1,104 @@ + + +# GitHub Reusable Workflow: Publish Go release + +
+ Publish Go release +
+ +--- + + + + +## Overview + +Publish the exact Go archives retained by build-release.yml after successful validation. + +Plan the tag with ci-github-publish/actions/release/plan, skip unchanged releases, +and pass that tag to build-release.yml after all required CI checks. Then call this +workflow with its artifact-id and the same tag and release-config. Publication +verifies the artifact's run, commit, tag and availability before creating a release. +No checkout, compilation or GoReleaser execution happens during publication. + +Grant actions read, contents write and pull-requests read to the calling job. +Use only trusted release triggers and require successful validation through needs. +Pull request events are rejected. Optional environment protection applies only +to the publication job. No repository bot credentials are needed. + +changelog-summary accepts the complete ci-github-publish JSON configuration; +use the secret for credentials. An empty value disables summarization. +Publication-only reruns reuse the same artifact ID; expired/deleted artifacts fail. +Full reruns produce a new ID. The shared release action owns release creation, +summary failures and asset recovery. Pin callers to a reviewed commit SHA. + +### Permissions + +- **`actions`**: `read` +- **`contents`**: `write` +- **`pull-requests`**: `read` + + + + +## Usage + +```yaml +name: Publish Go release +on: + push: + branches: + - main +permissions: {} +jobs: + release: + uses: hoverkraft-tech/ci-github-go/.github/workflows/release.yml@dcc9e10f1938e4496a40edc4e90eb0a6294a8bb2 # 0.0.1 + permissions: + actions: read + contents: write + pull-requests: read + secrets: + # Optional complete JSON summary configuration including credentials. Overrides the input. + changelog-summary: "" + with: + # Planned semantic-version tag used by build-release.yml. + # This input is required. + tag: "" + + # Immutable build-release.yml artifact ID from this run and commit. The caller must require successful validation. + # This input is required. + artifact-id: "" + + # Project directory matching preparation and packaging. + # Default: `.` + working-directory: . + + # Partial YAML or JSON release configuration forwarded unchanged to ci-github-publish/actions/release/create. Use the same configuration when planning. + release-config: "" + + # Optional complete JSON summary configuration. Use the secret when it contains credentials; a nonempty secret overrides this input. + changelog-summary: "" + + # Optional GitHub environment protecting publication. + environment: "" +``` + + + + +## Inputs + +### Workflow Call Inputs + +| **Input** | **Description** | **Required** | **Type** | **Default** | +| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- | ----------- | +| **`tag`** | Planned semantic-version tag used by build-release.yml. | **true** | **string** | - | +| **`artifact-id`** | Immutable build-release.yml artifact ID from this run and commit. The caller must require successful validation. | **true** | **string** | - | +| **`working-directory`** | Project directory matching preparation and packaging. | **false** | **string** | `.` | +| **`release-config`** | Partial YAML or JSON release configuration forwarded unchanged to ci-github-publish/actions/release/create. Use the same configuration when planning. | **false** | **string** | - | +| **`changelog-summary`** | Optional complete JSON summary configuration. Use the secret when it contains credentials; a nonempty secret overrides this input. | **false** | **string** | - | +| **`environment`** | Optional GitHub environment protecting publication. | **false** | **string** | - | + + + + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..68a133f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,106 @@ +# Publish the exact Go archives retained by build-release.yml after successful validation. +# +# Plan the tag with ci-github-publish/actions/release/plan, skip unchanged releases, +# and pass that tag to build-release.yml after all required CI checks. Then call this +# workflow with its artifact-id and the same tag and release-config. Publication +# verifies the artifact's run, commit, tag and availability before creating a release. +# No checkout, compilation or GoReleaser execution happens during publication. +# +# Grant actions read, contents write and pull-requests read to the calling job. +# Use only trusted release triggers and require successful validation through needs. +# Pull request events are rejected. Optional environment protection applies only +# to the publication job. No repository bot credentials are needed. +# +# changelog-summary accepts the complete ci-github-publish JSON configuration; +# use the secret for credentials. An empty value disables summarization. +# Publication-only reruns reuse the same artifact ID; expired/deleted artifacts fail. +# Full reruns produce a new ID. The shared release action owns release creation, +# summary failures and asset recovery. Pin callers to a reviewed commit SHA. +--- +name: Publish Go release +"on": + workflow_call: + inputs: + tag: + description: Planned semantic-version tag used by build-release.yml. + type: string + required: true + artifact-id: + description: Immutable build-release.yml artifact ID from this run and commit. The caller must require successful validation. + type: string + required: true + working-directory: + description: Project directory matching preparation and packaging. + type: string + default: . + release-config: + description: Partial YAML or JSON release configuration forwarded unchanged to ci-github-publish/actions/release/create. Use the same configuration when planning. + type: string + default: "" + changelog-summary: + description: Optional complete JSON summary configuration. Use the secret when it contains credentials; a nonempty secret overrides this input. + type: string + default: "" + environment: + description: Optional GitHub environment protecting publication. + type: string + default: "" + secrets: + changelog-summary: + description: Optional complete JSON summary configuration including credentials. Overrides the input. + required: false +permissions: {} +concurrency: + group: go-release-${{ github.repository }}-${{ inputs.working-directory }} + cancel-in-progress: false +jobs: + verify: + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + actions: read + steps: + - name: Verify release artifact provenance + id: verify + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + TAG: ${{ inputs.tag }} + ARTIFACT_ID: ${{ inputs.artifact-id }} + with: + # Retry delayed artifact metadata visibility; authentication failures stay fatal. + retries: 4 + retry-exempt-status-codes: 400,401,403,422 + script: | + const tag = process.env.TAG; + const id = Number(process.env.ARTIFACT_ID); + if (!/^v?\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(tag)) { + throw new Error('tag must be a semantic version, optionally prefixed with v.'); + } + if (!/^[1-9]\d*$/.test(process.env.ARTIFACT_ID) || !Number.isSafeInteger(id)) { + throw new Error('artifact-id must be one positive integer.'); + } + if (context.eventName.startsWith('pull_request')) throw new Error('Pull request events cannot publish releases.'); + const { data: artifact } = await github.rest.actions.getArtifact({...context.repo, artifact_id: id}); + if (artifact.expired || artifact.workflow_run?.id !== context.runId || artifact.workflow_run?.head_sha !== context.sha || + !artifact.name.startsWith(`go-release-${tag}-${context.runId}-`)) { + throw new Error('Expected an available release artifact for this run, commit and tag.'); + } + publish: + needs: verify + runs-on: ubuntu-latest + timeout-minutes: 20 + environment: ${{ inputs.environment }} + permissions: + actions: read + contents: write + pull-requests: read + steps: + - name: Publish retained archives and release notes + uses: hoverkraft-tech/ci-github-publish/actions/release/create@bf24f894f60a3def62a8750f3964d05acb052c11 # 3.1.2 + with: + config-overrides: ${{ inputs.release-config }} + release-artifact-id: ${{ inputs.artifact-id }} + tag: ${{ inputs.tag }} + target-ref: ${{ github.sha }} + working-directory: ${{ inputs.working-directory }} + changelog-summary: ${{ secrets.changelog-summary || inputs.changelog-summary }} diff --git a/README.md b/README.md index 88f89b9..c5d9514 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ actions with GitHub reporting require only `contents: read`. ## Documentation - [Workflow reference](.github/workflows/continuous-integration.md) +- [Build release archives](.github/workflows/build-release.md) +- [Publish validated archives](.github/workflows/release.md) - [Contributing](CONTRIBUTING.md) - [Documentation index](docs/README.md) diff --git a/actions/test/README.md b/actions/test/README.md index 2a95a25..d376636 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@dcc9e10f1938e4496a40edc4e90eb0a6294a8bb2 # 0.0.1 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..79cecc8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,3 +4,7 @@ - [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 packaging](../.github/workflows/build-release.md): snapshot and planned binary archives. +- [Release publication](../.github/workflows/release.md): publish validated archives without rebuilding. +- [Release artifact decision](adr/0002-consumer-release-artifacts.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..3daf544 --- /dev/null +++ b/docs/adr/0002-consumer-release-artifacts.md @@ -0,0 +1,30 @@ +# ADR 0002: Separate consumer packaging from publication + +- Status: Accepted +- 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/development/README.md b/docs/development/README.md index c779a66..e7cc50f 100644 --- a/docs/development/README.md +++ b/docs/development/README.md @@ -89,9 +89,12 @@ 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. Public +`build-release.yml` and `release.yml` package and publish consumer binaries through +GoReleaser and the shared release action. Keep each consumer's platform targets and +archive layout in its GoReleaser configuration. See the generated workflow references. +The release workflow contract tests exercise tag collisions and artifact provenance; +its dedicated CI fixture verifies a real GoReleaser archive transfer and checksum. ## Branding diff --git a/tests/config.test.cjs b/tests/config.test.cjs index aecdd55..7786210 100644 --- a/tests/config.test.cjs +++ b/tests/config.test.cjs @@ -115,3 +115,8 @@ 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"); +}); 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..602db6b --- /dev/null +++ b/tests/release.test.cjs @@ -0,0 +1,158 @@ +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("./action-test-helpers.cjs"); + +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/, + ); +}); + +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", step("build-release", "build", "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", + step("build-release", "build", "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)); +}); From 9580ccd582b852af4a7f7a03f683d91e614f529c Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Wed, 25 Nov 2026 22:19:02 +0100 Subject: [PATCH 2/4] docs: point new workflow examples to their implementation commit --- .github/workflows/build-release.md | 2 +- .github/workflows/continuous-integration.md | 2 +- .github/workflows/release.md | 2 +- actions/test/README.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-release.md b/.github/workflows/build-release.md index d29c194..cdad6c0 100644 --- a/.github/workflows/build-release.md +++ b/.github/workflows/build-release.md @@ -48,7 +48,7 @@ on: permissions: {} jobs: build-release: - uses: hoverkraft-tech/ci-github-go/.github/workflows/build-release.yml@dcc9e10f1938e4496a40edc4e90eb0a6294a8bb2 # 0.0.1 + uses: hoverkraft-tech/ci-github-go/.github/workflows/build-release.yml@2db38ba3c9d23770c04b71866551231470cd2994 # feat/reusable-go-release-workflows permissions: contents: read with: diff --git a/.github/workflows/continuous-integration.md b/.github/workflows/continuous-integration.md index d7ae5eb..d7f2716 100644 --- a/.github/workflows/continuous-integration.md +++ b/.github/workflows/continuous-integration.md @@ -146,7 +146,7 @@ on: permissions: {} jobs: continuous-integration: - uses: hoverkraft-tech/ci-github-go/.github/workflows/continuous-integration.yml@dcc9e10f1938e4496a40edc4e90eb0a6294a8bb2 # 0.0.1 + uses: hoverkraft-tech/ci-github-go/.github/workflows/continuous-integration.yml@2db38ba3c9d23770c04b71866551231470cd2994 # feat/reusable-go-release-workflows permissions: contents: read id-token: write diff --git a/.github/workflows/release.md b/.github/workflows/release.md index 1286543..a56637e 100644 --- a/.github/workflows/release.md +++ b/.github/workflows/release.md @@ -52,7 +52,7 @@ on: permissions: {} jobs: release: - uses: hoverkraft-tech/ci-github-go/.github/workflows/release.yml@dcc9e10f1938e4496a40edc4e90eb0a6294a8bb2 # 0.0.1 + uses: hoverkraft-tech/ci-github-go/.github/workflows/release.yml@2db38ba3c9d23770c04b71866551231470cd2994 # feat/reusable-go-release-workflows permissions: actions: read contents: write diff --git a/actions/test/README.md b/actions/test/README.md index d376636..490faba 100644 --- a/actions/test/README.md +++ b/actions/test/README.md @@ -72,7 +72,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-go/actions/test@dcc9e10f1938e4496a40edc4e90eb0a6294a8bb2 # 0.0.1 +- uses: hoverkraft-tech/ci-github-go/actions/test@2db38ba3c9d23770c04b71866551231470cd2994 # feat/reusable-go-release-workflows with: # Go module directory. # Default: `.` From 86f7d46b31948da93b2bcf78478e3180b908a6b6 Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Thu, 26 Nov 2026 08:06:19 +0100 Subject: [PATCH 3/4] feat: align Go preparation and packaging with sibling workflows --- .github/workflows/__shared-ci.yml | 5 + .github/workflows/__test-action-package.yml | 47 +++++ ...__test-workflow-continuous-integration.yml | 1 + .github/workflows/__test-workflow-release.yml | 24 --- .github/workflows/build-release.md | 104 ----------- .github/workflows/build-release.yml | 118 ------------- .github/workflows/continuous-integration.yml | 45 +++++ .github/workflows/prepare-package-release.yml | 96 +++++++++++ .github/workflows/release.yml | 32 ++-- README.md | 3 +- actions/package/action.test.cjs | 97 +++++++++++ actions/package/action.yml | 96 +++++++++++ docs/README.md | 5 +- docs/adr/0002-consumer-release-artifacts.md | 2 +- .../0003-consistent-consumer-release-flow.md | 29 ++++ docs/development/README.md | 17 +- tests/config.test.cjs | 14 ++ tests/release.test.cjs | 162 ++++++++++-------- 18 files changed, 551 insertions(+), 346 deletions(-) create mode 100644 .github/workflows/__test-action-package.yml delete mode 100644 .github/workflows/build-release.md delete mode 100644 .github/workflows/build-release.yml create mode 100644 .github/workflows/prepare-package-release.yml create mode 100644 actions/package/action.test.cjs create mode 100644 actions/package/action.yml create mode 100644 docs/adr/0003-consistent-consumer-release-flow.md diff --git a/.github/workflows/__shared-ci.yml b/.github/workflows/__shared-ci.yml index 53eb591..da4198c 100644 --- a/.github/workflows/__shared-ci.yml +++ b/.github/workflows/__shared-ci.yml @@ -55,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 index f2cee4d..6faebb6 100644 --- a/.github/workflows/__test-workflow-release.yml +++ b/.github/workflows/__test-workflow-release.yml @@ -18,27 +18,3 @@ jobs: arguments: '["tests/release.test.cjs"]' coverage: "" comment: "false" - package: - uses: $/.github/workflows/build-release.yml - permissions: - contents: read - 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/build-release.md b/.github/workflows/build-release.md deleted file mode 100644 index cdad6c0..0000000 --- a/.github/workflows/build-release.md +++ /dev/null @@ -1,104 +0,0 @@ - - -# GitHub Reusable Workflow: Build Go release archives - -
- Build Go release archives -
- ---- - - - - -## Overview - -Package Go binaries with the caller's GoReleaser v2 configuration, without publishing. - -Call after the project's required checks. Empty tag builds snapshot archives for CI; -a planned semantic-version tag builds release archives at the current caller commit. -Existing tags must resolve to that commit. Only a local tag is created, using read -permissions. Source tags, releases and registries are never written by this workflow. - -Keep platform targets, archives and checksums in the project's .goreleaser.yml. -artifact-paths selects the exact files handed to release.yml; include the checksums. -Paths are relative to working-directory. Custom paths are trusted caller configuration. -The immutable artifact ID belongs to this run and commit, is bound to the planned -tag, and is retained seven days. A failed build returns no successful artifact ID. -Snapshot artifacts cannot be published through release.yml. - -Use the same working-directory in preparation, validation and publication. See -[release](release.md) for the artifact handoff. Pin callers to a reviewed commit SHA. - -### Permissions - -- **`contents`**: `read` - - - - -## Usage - -```yaml -name: Build Go release archives -on: - push: - branches: - - main -permissions: {} -jobs: - build-release: - uses: hoverkraft-tech/ci-github-go/.github/workflows/build-release.yml@2db38ba3c9d23770c04b71866551231470cd2994 # feat/reusable-go-release-workflows - permissions: - contents: read - with: - # Go project containing the GoReleaser v2 configuration. - # Default: `.` - working-directory: . - - # Go version for packaging; empty uses project detection. - go-version: "" - - # Planned semantic-version tag, optionally prefixed with v. Empty builds snapshots. - tag: "" - - # GoReleaser v2 version constraint. - # Default: `~> v2` - goreleaser-version: ~> v2 - - # Files to retain relative to working-directory, one glob per line. Include release archives and checksums only. - # Default: `dist/*.tar.gz - # dist/*.zip - # dist/checksums.txt - # ` - artifact-paths: | - dist/*.tar.gz - dist/*.zip - dist/checksums.txt -``` - - - - -## Inputs - -### Workflow Call Inputs - -| **Input** | **Description** | **Required** | **Type** | **Default** | -| ------------------------ | -------------------------------------------------------------------------------------------------------------- | ------------ | ---------- | ----------------------------------------------------------------------------------------------------------------------------- | -| **`working-directory`** | Go project containing the GoReleaser v2 configuration. | **false** | **string** | `.` | -| **`go-version`** | Go version for packaging; empty uses project detection. | **false** | **string** | - | -| **`tag`** | Planned semantic-version tag, optionally prefixed with v. Empty builds snapshots. | **false** | **string** | - | -| **`goreleaser-version`** | GoReleaser v2 version constraint. | **false** | **string** | `~> v2` | -| **`artifact-paths`** | Files to retain relative to working-directory, one glob per line. Include release archives and checksums only. | **false** | **string** |
dist/\*.tar.gz
dist/\*.zip
dist/checksums.txt
| - - - - -## Outputs - -| **Output** | **Description** | -| ----------------- | ------------------------------------------------------------------------- | -| **`artifact-id`** | Immutable artifact ID of the packaged archives and checksums in this run. | - - diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml deleted file mode 100644 index ff9e219..0000000 --- a/.github/workflows/build-release.yml +++ /dev/null @@ -1,118 +0,0 @@ -# Package Go binaries with the caller's GoReleaser v2 configuration, without publishing. -# -# Call after the project's required checks. Empty tag builds snapshot archives for CI; -# a planned semantic-version tag builds release archives at the current caller commit. -# Existing tags must resolve to that commit. Only a local tag is created, using read -# permissions. Source tags, releases and registries are never written by this workflow. -# -# Keep platform targets, archives and checksums in the project's .goreleaser.yml. -# artifact-paths selects the exact files handed to release.yml; include the checksums. -# Paths are relative to working-directory. Custom paths are trusted caller configuration. -# The immutable artifact ID belongs to this run and commit, is bound to the planned -# tag, and is retained seven days. A failed build returns no successful artifact ID. -# Snapshot artifacts cannot be published through release.yml. -# -# Use the same working-directory in preparation, validation and publication. See -# [release](release.md) for the artifact handoff. Pin callers to a reviewed commit SHA. ---- -name: Build Go release archives -"on": - workflow_call: - inputs: - working-directory: - description: Go project containing the GoReleaser v2 configuration. - type: string - default: . - go-version: - description: Go version for packaging; empty uses project detection. - type: string - default: "" - tag: - description: Planned semantic-version tag, optionally prefixed with v. Empty builds snapshots. - type: string - default: "" - goreleaser-version: - description: GoReleaser v2 version constraint. - type: string - default: "~> v2" - artifact-paths: - description: Files to retain relative to working-directory, one glob per line. Include release archives and checksums only. - type: string - default: | - dist/*.tar.gz - dist/*.zip - dist/checksums.txt - outputs: - artifact-id: - description: Immutable artifact ID of the packaged archives and checksums in this run. - value: ${{ jobs.build.outputs.artifact-id }} -permissions: {} -jobs: - build: - runs-on: ubuntu-latest - timeout-minutes: 30 - permissions: - contents: read - outputs: - artifact-id: ${{ job.status == 'success' && steps.upload.outputs.artifact-id || '' }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - fetch-depth: 0 - - 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/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a7fa117..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 @@ -134,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 }} @@ -153,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 @@ -161,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) : ['']; @@ -194,6 +209,11 @@ jobs: 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)); @@ -301,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.yml b/.github/workflows/prepare-package-release.yml new file mode 100644 index 0000000..e21abaf --- /dev/null +++ b/.github/workflows/prepare-package-release.yml @@ -0,0 +1,96 @@ +# Plan a Go binary release before validation, without changing repository state. +# Continue only when status is ready, then pass tag to the release workflow. +# See [the release guide](release.md) for the complete prepare, validate and release journey. +name: Prepare Go Package Release +on: + workflow_call: + inputs: + release-config: + description: Partial YAML or JSON configuration forwarded to ci-github-publish/actions/release/plan. Pass the same configuration to preparation and publication. + type: string + default: "" + force: + description: Plan a release without relevant changes on manual default-branch runs. Ignored on schedules and tag retries. Shared planning preserves higher versions and never overwrites tags. + type: boolean + default: false + outputs: + status: + description: ready, no-changes or released. Only ready should start validation and publication. + value: ${{ jobs.prepare.outputs.status }} + tag: + description: Planned or recovered Go version tag. Available when status is ready; pass unchanged to release.yml. + value: ${{ jobs.prepare.outputs.tag }} +permissions: {} +concurrency: + group: go-release-prepare-${{ github.repository }} + cancel-in-progress: false +jobs: + prepare: + name: Prepare package release + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + pull-requests: read + outputs: + status: ${{ steps.result.outputs.status }} + tag: ${{ steps.result.outputs.tag }} + steps: + - id: event + name: Validate release event + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + with: + script: |- + const defaultRef = 'refs/heads/' + context.payload.repository.default_branch; + const manualTag = context.eventName === 'workflow_dispatch' && context.ref.startsWith('refs/tags/'); + if (!['workflow_dispatch', 'schedule'].includes(context.eventName) || (context.ref !== defaultRef && !manualTag)) { + throw new Error('Release preparation requires a manual or scheduled default-branch run, or a manual tag retry.'); + } + - id: plan + if: "!startsWith(github.ref, 'refs/tags/')" + uses: hoverkraft-tech/ci-github-publish/actions/release/plan@bf24f894f60a3def62a8750f3964d05acb052c11 # 3.1.2 + with: + config-overrides: ${{ inputs.release-config }} + target-ref: ${{ github.sha }} + force: ${{ github.event_name == 'workflow_dispatch' && inputs.force }} + - id: identity + name: Check Go version format + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + TAG: ${{ steps.plan.outputs.tag }} + HAS_CHANGES: ${{ steps.plan.outputs.should-release }} + with: + script: |- + const retry = context.ref.startsWith('refs/tags/'); + const tag = retry ? context.ref.slice('refs/tags/'.length) : process.env.TAG; + if (!/^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(tag)) { + throw new Error('Go release tags must be semantic versions, optionally prefixed with v.'); + } + core.setOutput('has-changes', retry || process.env.HAS_CHANGES === 'true'); + core.setOutput('tag', tag); + - id: verify + if: steps.identity.outputs.has-changes == 'true' + uses: hoverkraft-tech/ci-github-publish/actions/release/verify@bf24f894f60a3def62a8750f3964d05acb052c11 # 3.1.2 + with: + tags: ${{ format('["{0}"]', steps.identity.outputs.tag) }} + require-tags: ${{ startsWith(github.ref, 'refs/tags/') }} + - id: result + name: Report preparation status + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + HAS_CHANGES: ${{ steps.identity.outputs.has-changes }} + TAG: ${{ steps.identity.outputs.tag }} + RELEASES: ${{ steps.verify.outputs.releases }} + with: + script: |- + let status = 'no-changes'; + if (process.env.HAS_CHANGES === 'true') { + const releases = JSON.parse(process.env.RELEASES); + if (releases.length !== 1 || releases[0].tag !== process.env.TAG || typeof releases[0].published !== 'boolean') { + throw new Error('Expected verified publication state for the prepared tag.'); + } + status = releases[0].published ? 'released' : 'ready'; + } + core.setOutput('status', status); + core.setOutput('tag', status === 'ready' ? process.env.TAG : ''); + core.info('Release preparation: ' + status + '.'); diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 68a133f..7f4335a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,32 +1,32 @@ -# Publish the exact Go archives retained by build-release.yml after successful validation. +# Publish the exact Go archives retained by continuous-integration.yml after successful validation. # -# Plan the tag with ci-github-publish/actions/release/plan, skip unchanged releases, -# and pass that tag to build-release.yml after all required CI checks. Then call this -# workflow with its artifact-id and the same tag and release-config. Publication -# verifies the artifact's run, commit, tag and availability before creating a release. -# No checkout, compilation or GoReleaser execution happens during publication. +# Call prepare-package-release.yml first. Continue only when its status is ready. +# Enable packaging in continuous-integration.yml with the prepared tag, then pass +# package-artifact-id and that tag here. Use the same release-config throughout. +# Preparation handles no-change runs and already-published releases. A manual tag +# retry verifies the existing tag before packaging. Source tags are never overwritten. # -# Grant actions read, contents write and pull-requests read to the calling job. -# Use only trusted release triggers and require successful validation through needs. -# Pull request events are rejected. Optional environment protection applies only -# to the publication job. No repository bot credentials are needed. +# Publication verifies the artifact run, commit, tag and availability before creating +# a release. It does not rebuild. Grant actions read, contents write and pull-requests +# read to the calling job, and require successful validation through needs. +# Pull request publication is rejected. Optional environment protection applies to +# publication. No repository bot credentials are needed. # # changelog-summary accepts the complete ci-github-publish JSON configuration; -# use the secret for credentials. An empty value disables summarization. -# Publication-only reruns reuse the same artifact ID; expired/deleted artifacts fail. -# Full reruns produce a new ID. The shared release action owns release creation, -# summary failures and asset recovery. Pin callers to a reviewed commit SHA. +# use the secret for credentials. Empty disables summarization. Publication-only +# reruns reuse the same artifact ID; expired or deleted artifacts fail. A full rerun +# produces a new ID. The shared release action owns release notes and asset recovery. --- name: Publish Go release "on": workflow_call: inputs: tag: - description: Planned semantic-version tag used by build-release.yml. + description: Prepared semantic-version tag used for packaging. type: string required: true artifact-id: - description: Immutable build-release.yml artifact ID from this run and commit. The caller must require successful validation. + description: Immutable package-artifact-id from continuous-integration.yml in this run and commit. The caller must require successful validation. type: string required: true working-directory: diff --git a/README.md b/README.md index c5d9514..b747dbb 100644 --- a/README.md +++ b/README.md @@ -41,11 +41,12 @@ actions with GitHub reporting require only `contents: read`. | [test](actions/test/README.md) | Run tests and retain native reports | | [audit](actions/audit/README.md) | Check dependency vulnerabilities | | [build](actions/build/README.md) | Compile packages or project binaries | +| [package](actions/package/README.md) | Package validated binary archives | ## Documentation - [Workflow reference](.github/workflows/continuous-integration.md) -- [Build release archives](.github/workflows/build-release.md) +- [Prepare package release](.github/workflows/prepare-package-release.md) - [Publish validated archives](.github/workflows/release.md) - [Contributing](CONTRIBUTING.md) - [Documentation index](docs/README.md) 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/docs/README.md b/docs/README.md index 79cecc8..409c998 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,6 +5,7 @@ - [Tooling decision](adr/0001-language-ci.md): scope and trade-offs. - [Workflow reference](../.github/workflows/continuous-integration.md): usage, configuration, inputs and outputs. -- [Release packaging](../.github/workflows/build-release.md): snapshot and planned binary archives. +- [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 artifact decision](adr/0002-consumer-release-artifacts.md): boundaries and trade-offs. +- [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 index 3daf544..7f69b72 100644 --- a/docs/adr/0002-consumer-release-artifacts.md +++ b/docs/adr/0002-consumer-release-artifacts.md @@ -1,6 +1,6 @@ # ADR 0002: Separate consumer packaging from publication -- Status: Accepted +- Status: Superseded by [ADR 0003](0003-consistent-consumer-release-flow.md) - Date: 2026-11-25 ## Context 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 e7cc50f..505542f 100644 --- a/docs/development/README.md +++ b/docs/development/README.md @@ -89,12 +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 internal release automation versions this Actions repository. Public -`build-release.yml` and `release.yml` package and publish consumer binaries through -GoReleaser and the shared release action. Keep each consumer's platform targets and -archive layout in its GoReleaser configuration. See the generated workflow references. -The release workflow contract tests exercise tag collisions and artifact provenance; -its dedicated CI fixture verifies a real GoReleaser archive transfer and checksum. +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 7786210..4eb6519 100644 --- a/tests/config.test.cjs +++ b/tests/config.test.cjs @@ -120,3 +120,17 @@ 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/release.test.cjs b/tests/release.test.cjs index 602db6b..8d125a6 100644 --- a/tests/release.test.cjs +++ b/tests/release.test.cjs @@ -1,10 +1,7 @@ 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("./action-test-helpers.cjs"); function step(workflow, job, id) { return YAML.parse( @@ -69,90 +66,107 @@ test("release rejects mismatched artifacts and untrusted publication contexts", ); }); -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", +function preparation(id, args) { + return new AsyncFunction( + ...args, + step("prepare-package-release", "prepare", id).with.script, ); - const sha = git("rev-parse", "HEAD"); - const tag = (value, commit = sha) => - spawnSync( - "bash", - ["-euo", "pipefail", "-c", step("build-release", "build", "tag").run], - { - cwd: directory, - encoding: "utf8", - timeout: 10000, - env: { - ...process.env, - GIT_CONFIG_GLOBAL: "/dev/null", - RELEASE_TAG: value, - GITHUB_SHA: commit, - }, - }, +} + +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/, ); - 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", - step("build-release", "build", "artifact").with.script, - ); - const outputs = {}; - const run = (files) => - configure( - require, +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; }, }, - context, + ); + 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: { - GITHUB_WORKSPACE: "/workspace", - DIRECTORY: "project", - PATHS: files, + HAS_CHANGES: changes, TAG: "v1.2.3", - GITHUB_RUN_ATTEMPT: "2", + RELEASES: JSON.stringify(releases), + }, + }, + { + setOutput: (key, value) => { + outputs[key] = value; }, + info() {}, }, ); - 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)); + 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/, + ); + } }); From 9968f40606caff42d54df871ffe01dec80409107 Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Thu, 26 Nov 2026 08:10:01 +0100 Subject: [PATCH 4/4] docs: regenerate Go packaging and release references --- .github/workflows/continuous-integration.md | 20 ++++- .github/workflows/prepare-package-release.md | 73 ++++++++++++++++++ .github/workflows/release.md | 38 ++++----- actions/package/README.md | 81 ++++++++++++++++++++ 4 files changed, 189 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/prepare-package-release.md create mode 100644 actions/package/README.md diff --git a/.github/workflows/continuous-integration.md b/.github/workflows/continuous-integration.md index d7f2716..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 @@ -146,7 +152,7 @@ on: permissions: {} jobs: continuous-integration: - uses: hoverkraft-tech/ci-github-go/.github/workflows/continuous-integration.yml@2db38ba3c9d23770c04b71866551231470cd2994 # feat/reusable-go-release-workflows + uses: hoverkraft-tech/ci-github-go/.github/workflows/continuous-integration.yml@86f7d46b31948da93b2bcf78478e3180b908a6b6 # feat/reusable-go-release-workflows permissions: contents: read id-token: write @@ -186,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 @@ -210,6 +220,7 @@ jobs: | **`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` | @@ -221,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/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 + +
+ Prepare Go Package Release +
+ +--- + + + + +## Overview + +Plan a Go binary release before validation, without changing repository state. +Continue only when status is ready, then pass tag to the release workflow. +See [the release guide](release.md) for the complete prepare, validate and release journey. + +### Permissions + +- **`contents`**: `read` +- **`pull-requests`**: `read` + + + + +## Usage + +```yaml +name: Prepare Go Package Release +on: + push: + branches: + - main +permissions: {} +jobs: + prepare-package-release: + uses: hoverkraft-tech/ci-github-go/.github/workflows/prepare-package-release.yml@86f7d46b31948da93b2bcf78478e3180b908a6b6 # feat/reusable-go-release-workflows + permissions: + contents: read + pull-requests: read + with: + # Partial YAML or JSON configuration forwarded to ci-github-publish/actions/release/plan. Pass the same configuration to preparation and publication. + release-config: "" + + # Plan a release without relevant changes on manual default-branch runs. Ignored on schedules and tag retries. Shared planning preserves higher versions and never overwrites tags. + force: false +``` + + + + +## Inputs + +### Workflow Call Inputs + +| **Input** | **Description** | **Required** | **Type** | **Default** | +| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------- | ----------- | +| **`release-config`** | Partial YAML or JSON configuration forwarded to ci-github-publish/actions/release/plan. Pass the same configuration to preparation and publication. | **false** | **string** | - | +| **`force`** | Plan a release without relevant changes on manual default-branch runs. Ignored on schedules and tag retries. Shared planning preserves higher versions and never overwrites tags. | **false** | **boolean** | `false` | + + + + +## Outputs + +| **Output** | **Description** | +| ------------ | --------------------------------------------------------------------------------------------------- | +| **`status`** | ready, no-changes or released. Only ready should start validation and publication. | +| **`tag`** | Planned or recovered Go version tag. Available when status is ready; pass unchanged to release.yml. | + + diff --git a/.github/workflows/release.md b/.github/workflows/release.md index a56637e..269c150 100644 --- a/.github/workflows/release.md +++ b/.github/workflows/release.md @@ -13,24 +13,24 @@ ## Overview -Publish the exact Go archives retained by build-release.yml after successful validation. +Publish the exact Go archives retained by continuous-integration.yml after successful validation. -Plan the tag with ci-github-publish/actions/release/plan, skip unchanged releases, -and pass that tag to build-release.yml after all required CI checks. Then call this -workflow with its artifact-id and the same tag and release-config. Publication -verifies the artifact's run, commit, tag and availability before creating a release. -No checkout, compilation or GoReleaser execution happens during publication. +Call prepare-package-release.yml first. Continue only when its status is ready. +Enable packaging in continuous-integration.yml with the prepared tag, then pass +package-artifact-id and that tag here. Use the same release-config throughout. +Preparation handles no-change runs and already-published releases. A manual tag +retry verifies the existing tag before packaging. Source tags are never overwritten. -Grant actions read, contents write and pull-requests read to the calling job. -Use only trusted release triggers and require successful validation through needs. -Pull request events are rejected. Optional environment protection applies only -to the publication job. No repository bot credentials are needed. +Publication verifies the artifact run, commit, tag and availability before creating +a release. It does not rebuild. Grant actions read, contents write and pull-requests +read to the calling job, and require successful validation through needs. +Pull request publication is rejected. Optional environment protection applies to +publication. No repository bot credentials are needed. changelog-summary accepts the complete ci-github-publish JSON configuration; -use the secret for credentials. An empty value disables summarization. -Publication-only reruns reuse the same artifact ID; expired/deleted artifacts fail. -Full reruns produce a new ID. The shared release action owns release creation, -summary failures and asset recovery. Pin callers to a reviewed commit SHA. +use the secret for credentials. Empty disables summarization. Publication-only +reruns reuse the same artifact ID; expired or deleted artifacts fail. A full rerun +produces a new ID. The shared release action owns release notes and asset recovery. ### Permissions @@ -52,7 +52,7 @@ on: permissions: {} jobs: release: - uses: hoverkraft-tech/ci-github-go/.github/workflows/release.yml@2db38ba3c9d23770c04b71866551231470cd2994 # feat/reusable-go-release-workflows + uses: hoverkraft-tech/ci-github-go/.github/workflows/release.yml@86f7d46b31948da93b2bcf78478e3180b908a6b6 # feat/reusable-go-release-workflows permissions: actions: read contents: write @@ -61,11 +61,11 @@ jobs: # Optional complete JSON summary configuration including credentials. Overrides the input. changelog-summary: "" with: - # Planned semantic-version tag used by build-release.yml. + # Prepared semantic-version tag used for packaging. # This input is required. tag: "" - # Immutable build-release.yml artifact ID from this run and commit. The caller must require successful validation. + # Immutable package-artifact-id from continuous-integration.yml in this run and commit. The caller must require successful validation. # This input is required. artifact-id: "" @@ -92,8 +92,8 @@ jobs: | **Input** | **Description** | **Required** | **Type** | **Default** | | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- | ----------- | -| **`tag`** | Planned semantic-version tag used by build-release.yml. | **true** | **string** | - | -| **`artifact-id`** | Immutable build-release.yml artifact ID from this run and commit. The caller must require successful validation. | **true** | **string** | - | +| **`tag`** | Prepared semantic-version tag used for packaging. | **true** | **string** | - | +| **`artifact-id`** | Immutable package-artifact-id from continuous-integration.yml in this run and commit. The caller must require successful validation. | **true** | **string** | - | | **`working-directory`** | Project directory matching preparation and packaging. | **false** | **string** | `.` | | **`release-config`** | Partial YAML or JSON release configuration forwarded unchanged to ci-github-publish/actions/release/create. Use the same configuration when planning. | **false** | **string** | - | | **`changelog-summary`** | Optional complete JSON summary configuration. Use the secret when it contains credentials; a nonempty secret overrides this input. | **false** | **string** | - | diff --git a/actions/package/README.md b/actions/package/README.md new file mode 100644 index 0000000..6a1e5f3 --- /dev/null +++ b/actions/package/README.md @@ -0,0 +1,81 @@ + + +# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItcGFja2FnZSIgY29sb3I9ImJsdWUiPjxsaW5lIHgxPSIxNi41IiB5MT0iOS40IiB4Mj0iNy41IiB5Mj0iNC4yMSI+PC9saW5lPjxwYXRoIGQ9Ik0yMSAxNlY4YTIgMiAwIDAgMC0xLTEuNzNsLTctNGEyIDIgMCAwIDAtMiAwbC03IDRBMiAyIDAgMCAwIDMgOHY4YTIgMiAwIDAgMCAxIDEuNzNsNyA0YTIgMiAwIDAgMCAyIDBsNy00QTIgMiAwIDAgMCAyMSAxNnoiPjwvcGF0aD48cG9seWxpbmUgcG9pbnRzPSIzLjI3IDYuOTYgMTIgMTIuMDEgMjAuNzMgNi45NiI+PC9wb2x5bGluZT48bGluZSB4MT0iMTIiIHkxPSIyMi4wOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48L3N2Zz4=) GitHub Action: Go - Package + +
+ Go - Package +
+ +--- + + + + +## Overview + +Package GoReleaser archives and checksums without publishing. + +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. + + + + +## Usage + +```yaml +- uses: hoverkraft-tech/ci-github-go/actions/package@86f7d46b31948da93b2bcf78478e3180b908a6b6 # feat/reusable-go-release-workflows + with: + # Go project containing the GoReleaser v2 configuration. + # Default: `.` + working-directory: . + + # Go version for packaging; empty uses project detection. + go-version: "" + + # Planned semantic-version tag, optionally prefixed with v. Empty builds snapshots. + tag: "" + + # GoReleaser v2 version constraint. + # Default: `~> v2` + goreleaser-version: ~> v2 + + # Archive and checksum globs relative to working-directory, one per line. + # Default: `dist/*.tar.gz + # dist/*.zip + # dist/checksums.txt + # ` + artifact-paths: | + dist/*.tar.gz + dist/*.zip + dist/checksums.txt +``` + + + + +## Inputs + +| **Input** | **Description** | **Required** | **Default** | +| ------------------------ | --------------------------------------------------------------------------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | +| **`working-directory`** | Go project containing the GoReleaser v2 configuration. | **false** | `.` | +| **`go-version`** | Go version for packaging; empty uses project detection. | **false** | - | +| **`tag`** | Planned semantic-version tag, optionally prefixed with v. Empty builds snapshots. | **false** | - | +| **`goreleaser-version`** | GoReleaser v2 version constraint. | **false** | `~> v2` | +| **`artifact-paths`** | Archive and checksum globs relative to working-directory, one per line. | **false** |
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. | + +