Skip to content

Commit

Permalink
ci: Add goreleaser workflow (#2040)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #2039 

## Description

This PR adds a Goreleaser workflow to automate the publication of
releases on Github and DockerHub.

Note that the release header and the milestone name should be updated
manually for every release.
  • Loading branch information
fredcarle authored Nov 15, 2023
1 parent 11e1efb commit b6f7a10
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 134 deletions.
51 changes: 0 additions & 51 deletions .github/workflows/pull-docker-image.yml

This file was deleted.

83 changes: 0 additions & 83 deletions .github/workflows/push-docker-image-to-registries.yml

This file was deleted.

71 changes: 71 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2023 Democratized Data Foundation
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.

name: Release workflow

on:
workflow_dispatch:
inputs:
tag:
description: 'New tag name'
required: true

permissions:
contents: write
packages: write
issues: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout code into the directory
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Go environment explicitly
uses: actions/setup-go@v3
with:
go-version: "1.20"
check-latest: true

- name: Apply tag
run: git tag ${{ github.event.inputs.tag }}

- name: Build modules
run: make deps:modules

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser-pro
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
109 changes: 109 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
version: 1

dist: ./build

before:
hooks:
- go mod tidy
- make deps:playground

after:
hooks:
- cmd: docker pull {{ .Env.GITHUB_REPOSITORY }}:latest
- cmd: docker run --rm {{ .Env.GITHUB_REPOSITORY }}:latest

builds:
- id: "defradb"
main: ./cmd/defradb
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
# A build with the playground included.
- id: "defradb_playground"
main: ./cmd/defradb
flags:
- -tags=playground
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

archives:
- id: defradb_playground
builds:
- defradb_playground
format: binary
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: '{{ .Binary }}_playground_{{ .Version }}_{{ .Os }}_{{- if eq .Arch "amd64" }}x86_64{{- else }}{{ .Arch }}{{ end }}{{- if .Arm }}v{{ .Arm }}{{ end }}'
- id: defradb
builds:
- defradb
format: binary
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{- if eq .Arch "amd64" }}x86_64{{- else }}{{ .Arch }}{{ end }}{{- if .Arm }}v{{ .Arm }}{{ end }}'

release:
target_commitish: '{{ .Commit }}'
header: |
DefraDB v{{ .Major }}.{{ .Minor }} is a major pre-production release. Until the stable version 1.0 is reached, the SemVer minor patch number will denote notable releases, which will give the project freedom to experiment and explore potentially breaking changes.
To get a full outline of the changes, we invite you to review the official changelog below. This release does include a Breaking Change to existing v{{ .Major }}.{{ .Minor }}.x databases. If you need help migrating an existing deployment, reach out at [email protected] or join our Discord at https://discord.source.network/.
name_template: "v{{ .Version }} Release"

changelog:
sort: asc
abbrev: -1
groups:
- title: Features
regexp: '^feat:.*'
order: 0
- title: Fix
regexp: '^fix:.*'
order: 1
- title: Tooling
regexp: '^tools:.*'
order: 2
- title: Documentation
regexp: '^docs:.*'
order: 3
- title: Refactoring
regexp: '^refactor:.*'
order: 4
- title: Testing
regexp: '^test:.*'
order: 5

source:
enabled: true

milestones:
- close: true
fail_on_error: false
name_template: "DefraDB v{{ .Major }}.{{ .Minor }}"

dockers:
- ids:
- "defradb_playground"
image_templates:
- "{{ .Env.GITHUB_REPOSITORY }}:latest"
- "{{ .Env.GITHUB_REPOSITORY }}:{{ .Version }}"
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:{{ .Version }}"
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.description=DefraDB is a Peer-to-Peer Edge Database."
- "--label=org.opencontainers.image.created={{ .Date }}"
- "--label=org.opencontainers.image.name={{ .ProjectName }}"
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- "--label=org.opencontainers.image.source={{ .GitURL }}"
- "--platform=linux/amd64"
dockerfile: ./tools/goreleaser.containerfile

17 changes: 17 additions & 0 deletions tools/goreleaser.containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# syntax=docker/dockerfile:1

# An image to run defradb.

# Stage: RUN
FROM debian:bookworm-slim
COPY defradb /defradb

# Documents which ports are normally used.
# To publish the ports: `docker run -p 9181:9181` ...
EXPOSE 9161
EXPOSE 9171
EXPOSE 9181

# Default command provided for convenience.
# e.g. docker run -p 9181:9181 source/defradb start --url 0.0.0.0:9181
ENTRYPOINT [ "/defradb" ]

0 comments on commit b6f7a10

Please sign in to comment.