-
-
Notifications
You must be signed in to change notification settings - Fork 9
ci: publish tagged releases with release-please and GoReleaser #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| name: goreleaser | ||
|
|
||
| # Builds the release artifacts for an existing tag and pushes the container | ||
| # image. Called by release-pipeline.yml right after release-please cuts a tag, | ||
| # and available on its own to rebuild a tag whose image push failed. | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| tag: | ||
| description: "Tag to build and publish the image for" | ||
| required: true | ||
| type: string | ||
| workflow_dispatch: | ||
| inputs: | ||
| tag: | ||
| description: "Existing tag to (re)build and publish the image for, e.g. v0.1.0" | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: write | ||
| packages: write | ||
|
|
||
| jobs: | ||
| goreleaser: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout tag | ||
| uses: actions/checkout@v7 | ||
| with: | ||
| ref: ${{ inputs.tag }} | ||
| # GoReleaser derives the version from the tag, so a shallow checkout | ||
| # without tags would make it fall back to a snapshot version. | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v7 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v4 | ||
|
|
||
| - name: Log in to ghcr.io | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Run GoReleaser | ||
| uses: goreleaser/goreleaser-action@v7 | ||
| with: | ||
| distribution: goreleaser | ||
| version: "~> v2.18" | ||
| args: release --config .goreleaser.release.yml --clean | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| # release-please creates the release as a draft so it only becomes visible | ||
| # once the image it describes is actually pullable. | ||
| - name: Publish release | ||
| uses: actions/github-script@v9 | ||
| env: | ||
| TAG: ${{ inputs.tag }} | ||
| with: | ||
| script: | | ||
| const { owner, repo } = context.repo; | ||
| const tag = process.env.TAG; | ||
|
|
||
| // getReleaseByTag does not return drafts, so list and match. | ||
| const releases = await github.paginate( | ||
| github.rest.repos.listReleases, | ||
| { owner, repo, per_page: 100 } | ||
| ); | ||
| const release = releases.find(r => r.tag_name === tag); | ||
| if (!release) { | ||
| throw new Error(`No release found for tag ${tag}`); | ||
| } | ||
|
|
||
| await github.rest.repos.updateRelease({ | ||
| owner, | ||
| repo, | ||
| release_id: release.id, | ||
| draft: false, | ||
| }); | ||
|
|
||
| console.log(`Published ${tag}: ${release.html_url}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| name: release-pipeline | ||
|
|
||
| # On every push to main, release-please keeps a release PR up to date from the | ||
| # conventional-commit history. Merging that PR is what cuts a release: it tags | ||
| # the commit, drafts the release notes, and hands the tag to goreleaser, which | ||
| # builds and pushes the versioned image before the release goes public. | ||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| packages: write | ||
|
|
||
| jobs: | ||
| release-please: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| release_created: ${{ steps.release.outputs.release_created }} | ||
| tag_name: ${{ steps.release.outputs.tag_name }} | ||
| steps: | ||
| - name: release | ||
| id: release | ||
| uses: googleapis/release-please-action@v5 | ||
| with: | ||
| # A PAT rather than GITHUB_TOKEN: pushes and PRs made with | ||
| # GITHUB_TOKEN do not trigger workflows, so the release PR would | ||
| # never run the tests it is meant to gate on. | ||
| token: ${{ secrets.RELEASE_PLEASE_TOKEN }} | ||
| config-file: release-please-config.json | ||
| manifest-file: .release-please-manifest.json | ||
|
|
||
| # Nothing gets published without the tests passing. docker-publish.yml used to | ||
| # provide this gate; the release pipeline took over its job. | ||
| test: | ||
| needs: release-please | ||
| if: ${{ needs.release-please.outputs.release_created == 'true' }} | ||
| uses: ./.github/workflows/test.yml | ||
|
|
||
| # No `secrets: inherit`: the called workflow needs nothing beyond | ||
| # GITHUB_TOKEN, which reusable workflows always get, and inheriting would | ||
| # hand it RELEASE_PLEASE_TOKEN for no reason. | ||
| # | ||
| # If this job fails, the tag and the draft release already exist, so a later | ||
| # push to main will not retry it — release-please only reports | ||
| # release_created once. Re-run the goreleaser workflow directly instead; it | ||
| # takes the tag as a workflow_dispatch input for exactly this case. | ||
| goreleaser: | ||
| needs: [release-please, test] | ||
| if: ${{ needs.release-please.outputs.release_created == 'true' }} | ||
| uses: ./.github/workflows/goreleaser.yml | ||
| with: | ||
| tag: ${{ needs.release-please.outputs.tag_name }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,6 @@ | |
| doormouse | ||
| go-wol-proxy | ||
| *.migrated.toml | ||
|
|
||
| # goreleaser output | ||
| dist/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| version: 2 | ||
|
|
||
| project_name: doormouse | ||
|
|
||
| before: | ||
| hooks: | ||
| - go mod download | ||
|
|
||
| builds: | ||
| - id: doormouse | ||
| main: . | ||
| binary: doormouse | ||
| env: | ||
| - CGO_ENABLED=0 | ||
| flags: | ||
| - -trimpath | ||
| ldflags: | ||
| - -s -w | ||
| # doormouse is a Linux daemon that has to sit in the target's broadcast | ||
| # domain, and the container image is the only release channel, so there is | ||
| # nothing to gain from darwin/windows builds. | ||
| goos: [linux] | ||
| goarch: [amd64, arm64] | ||
|
|
||
| # The container image is the only published artifact, so goreleaser neither | ||
| # builds archives nor touches the GitHub release. release-please owns the | ||
| # release and its notes; the workflow undrafts it once the image is pushed. | ||
| archives: | ||
| - formats: [binary] | ||
|
|
||
| release: | ||
| disable: true | ||
|
|
||
| changelog: | ||
| disable: true | ||
|
|
||
| dockers_v2: | ||
| - id: image | ||
| dockerfile: Dockerfile.release | ||
| ids: [doormouse] | ||
| images: | ||
| - ghcr.io/darksworm/doormouse | ||
| # Rolling tags let a compose file track a major or minor line and still get | ||
| # patch updates. :latest stays for the quick start in the README. | ||
| tags: | ||
| - "{{ .Version }}" | ||
| - "{{ .Major }}.{{ .Minor }}" | ||
| - "{{ .Major }}" | ||
| - latest | ||
| platforms: | ||
| - linux/amd64 | ||
| - linux/arm64 | ||
| labels: | ||
| org.opencontainers.image.created: "{{ .Date }}" | ||
| org.opencontainers.image.title: "{{ .ProjectName }}" | ||
| org.opencontainers.image.description: "A reverse proxy that wakes your servers when someone knocks" | ||
| org.opencontainers.image.revision: "{{ .FullCommit }}" | ||
| org.opencontainers.image.version: "{{ .Version }}" | ||
| org.opencontainers.image.licenses: "GPL-3.0-or-later" | ||
| org.opencontainers.image.source: "https://github.com/darksworm/doormouse" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| ".": "0.0.0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Runtime image for released versions. Unlike the top-level Dockerfile, which | ||
| # compiles from source for local builds, this one only packages the binary | ||
| # GoReleaser has already cross-compiled — so there is no RUN step and no | ||
| # emulation cost when building the arm64 image on an amd64 runner. | ||
| FROM alpine:3.22 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # GoReleaser dockers_v2 places each platform's binary under $TARGETPLATFORM/ | ||
| ARG TARGETPLATFORM | ||
| COPY ${TARGETPLATFORM}/doormouse /app/doormouse | ||
|
|
||
| # Same contract as the source-built image: the default port, and a config | ||
| # mounted at /app/config.toml. TCP routes listen on their own ports; with | ||
| # network_mode: host they are reachable directly, otherwise publish each one. | ||
| EXPOSE 8080 | ||
|
|
||
| ENTRYPOINT ["/app/doormouse", "/app/config.toml"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.