Skip to content

Commit

Permalink
Implementing an automatic release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
noctarius committed Jun 20, 2023
1 parent 4c3f174 commit a2bd6a4
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 26 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,3 @@ jobs:
name: unit-run.log
path: unit-run.log
retention-days: 5

docker:
name: docker
needs: [build, test]
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
id-token: write

steps:
- uses: actions/checkout@v3
- name: Docker Build
run: docker build . --file Dockerfile --tag ${{ env.docker-registry }}/${{ env.docker-image-name }}:${{ github.run_number }}

- name: Log into registry ${{ env.docker-registry }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.docker-registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Hub Push
run: docker push ${{ env.docker-registry }}/${{ env.docker-image-name }}:${{ github.run_number }}
75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Release

on:
release:
types: [created]

env:
golang-version: 1.20.2
golangci-lint-version: v1.51.2
docker-registry: ghcr.io
docker-image-name: ${{ github.repository }}

defaults:
run:
shell: bash --noprofile --norc -eo pipefail {0}

jobs:
docker:
name: docker
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
id-token: write

steps:
- uses: actions/checkout@v3
- name: Docker Build
run: docker build . --file Dockerfile --tag ${{ env.docker-registry }}/${{ env.docker-image-name }}:${{ github.ref_name }}

- name: Log into registry ${{ env.docker-registry }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.docker-registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Hub Push
run: docker push ${{ env.docker-registry }}/${{ env.docker-image-name }}:${{ github.ref_name }}

release:
name: release
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
id-token: write

strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64, arm, arm64]
exclude:
- goos: darwin
goarch: arm
- goos: windows
goarch: arm

steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1.38
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: ${{ env.golang-version }}
project_path: "./cmd/timescaledb-event-streamer"
binary_name: "timescaledb-event-streamer"
sha256sum: TRUE
pre_command: export GODEBUG=http2client=0
ldflags: >
-X 'github.com/noctarius/timescaledb-event-streamer/internal/version.Branch=${{ github.ref_name }}' -X 'github.com/noctarius/timescaledb-event-streamer/internal/version.CommitHash=${{ github.sha }}'
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
docker:
docker build .

.PHONY: build-local
build-local:
@echo Building MacOS amd64...
GOOS=darwin GOARCH=amd64 go build -v -ldflags "-X 'github.com/noctarius/timescaledb-event-streamer/internal/version.Branch=${GIT_BRANCH}' -X 'github.com/noctarius/timescaledb-event-streamer/internal/version.CommitHash=${GIT_COMMIT}'" -o dist/macos/amd64/timescaledb-event-streamer ./cmd/timescaledb-event-streamer
@echo Building MacOS arm64...
GOOS=darwin GOARCH=arm64 go build -v -ldflags "-X 'github.com/noctarius/timescaledb-event-streamer/internal/version.Branch=${GIT_BRANCH}' -X 'github.com/noctarius/timescaledb-event-streamer/internal/version.CommitHash=${GIT_COMMIT}'" -o dist/macos/arm64/timescaledb-event-streamer ./cmd/timescaledb-event-streamer
@echo Building Linux amd64...
GOOS=linux GOARCH=amd64 go build -v -ldflags "-X 'github.com/noctarius/timescaledb-event-streamer/internal/version.Branch=${GIT_BRANCH}' -X 'github.com/noctarius/timescaledb-event-streamer/internal/version.CommitHash=${GIT_COMMIT}'" -o dist/linux/amd64/timescaledb-event-streamer ./cmd/timescaledb-event-streamer
@echo "Building Linux arm (32 bit)..."
GOOS=linux GOARCH=arm go build -v -ldflags "-X 'github.com/noctarius/timescaledb-event-streamer/internal/version.Branch=${GIT_BRANCH}' -X 'github.com/noctarius/timescaledb-event-streamer/internal/version.CommitHash=${GIT_COMMIT}'" -o dist/linux/arm32/timescaledb-event-streamer ./cmd/timescaledb-event-streamer
@echo Building Linux arm64...
GOOS=linux GOARCH=arm64 go build -v -ldflags "-X 'github.com/noctarius/timescaledb-event-streamer/internal/version.Branch=${GIT_BRANCH}' -X 'github.com/noctarius/timescaledb-event-streamer/internal/version.CommitHash=${GIT_COMMIT}'" -o dist/linux/arm64/timescaledb-event-streamer ./cmd/timescaledb-event-streamer
@echo Building Windows amd64...
GOOS=windows GOARCH=amd64 go build -v -ldflags "-X 'github.com/noctarius/timescaledb-event-streamer/internal/version.Branch=${GIT_BRANCH}' -X 'github.com/noctarius/timescaledb-event-streamer/internal/version.CommitHash=${GIT_COMMIT}'" -o dist/windows/amd64/timescaledb-event-streamer ./cmd/timescaledb-event-streamer
@echo Building Windows arm64...
GOOS=windows GOARCH=arm64 go build -v -ldflags "-X 'github.com/noctarius/timescaledb-event-streamer/internal/version.Branch=${GIT_BRANCH}' -X 'github.com/noctarius/timescaledb-event-streamer/internal/version.CommitHash=${GIT_COMMIT}'" -o dist/windows/arm64/timescaledb-event-streamer ./cmd/timescaledb-event-streamer

.PHONY: build
build:
go build -v -ldflags "-X 'github.com/noctarius/timescaledb-event-streamer/internal/version.Branch=${GIT_BRANCH}' -X 'github.com/noctarius/timescaledb-event-streamer/internal/version.CommitHash=${GIT_COMMIT}'" -o dist/timescaledb-event-streamer ./cmd/timescaledb-event-streamer
Expand Down

0 comments on commit a2bd6a4

Please sign in to comment.