Skip to content

v0.x: a generated GitLab project releases with its assets attached

A generated project on GitLab CI used to have colophon create its release when the release MR merged, then have goreleaser attach the binaries on the tag pipeline. For the length of the build, every release existed with nothing on it, and a failed build left it that way. Now goreleaser uploads first, and colophon creates the release on the tag pipeline once every link it makes resolves (spec 0219,

149). go-tool-base releases this way itself.

What changes

  • .gitlab-ci.yml: the colophon include gains assets: true and an asset_base.
  • .goreleaser.yaml: the release block is disable: true. mode: keep-existing, use_existing_draft, replace_existing_artifacts and make_latest go. GitLab treats the newest release as latest, so nothing replaces make_latest.
  • On the forge channel: a new uploads: entry puts every archive, checksums.txt and, with signing on, checksums.txt.sig in the project's generic package registry, under the tool's name and version. asset_base names the same directory:
# .goreleaser.yaml
uploads:
  - name: gitlab-generic
    target: "{{ .Env.CI_API_V4_URL }}/projects/{{ .Env.CI_PROJECT_ID }}/packages/generic/<tool>/{{ .Version }}/{{ .ArtifactName }}"
    custom_artifact_name: true
    method: PUT
    mode: archive
    checksum: true
    signature: true
    custom_headers:
      JOB-TOKEN: "{{ .Env.CI_JOB_TOKEN }}"

# .gitlab-ci.yml, on the colophon include
inputs:
  assets: true
  asset_base: "$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/generic/<tool>/$COLOPHON_VERSION"

custom_artifact_name: true matters. The target already names the file, and without it goreleaser appends the name a second time, so every link colophon checks would 404.

A Homebrew cask gains a url.template naming the same upload, because goreleaser cannot derive one with its release step off. - On the static channel: nothing new is uploaded, because blobs: already puts every artefact in the store. asset_base is your base URL followed by /$CI_COMMIT_TAG. - GitHub, Gitea, Codeberg and Bitbucket projects are unchanged. On GitHub, colophon cannot yet attach files to a release (colophon#63).

Migrating an existing project

gtb regenerate project applies all of this. A .goreleaser.yaml or .gitlab-ci.yml you have not edited is rewritten. One you have edited goes through the usual conflict handling: you are asked, or --overwrite decides. If you keep your own file, make the changes above by hand.

The two files move together. Taking the new .goreleaser.yaml and keeping an older .gitlab-ci.yml turns goreleaser's release step off while colophon still creates the release at merge, so the release is created with nothing on it, on a green pipeline. Keeping the new .gitlab-ci.yml with an older .goreleaser.yaml fails the other way: colophon refuses a release whose links do not resolve. Accept both or neither, and if you keep one, edit it to match the other. When a regenerate keeps one of the two on the old flow and rewrites the other, its summary warns and names the kept file and the change it needs.

On the forge channel the project's package registry must be enabled (Settings > General > Visibility, project features, permissions). It is on by default, and the job token can write to the project's own registry with nothing more. On the static channel the store credentials you already have are enough.

If you add an artefact

colophon links every artefact goreleaser lists of a type a release carries, and it refuses to publish a release with a link that does not resolve. On the forge channel, an sboms: block or nfpms: packages therefore need the uploads: entry extended to upload them too, or the next release fails. On the static channel, blobs: uploads everything, so nothing more is needed.