rewrite: complete overhaul with a more flexible code base #58
Workflow file for this run
This file contains 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
name: CI | |
on: | |
push: | |
tags: | |
- 'v*' | |
branches: | |
- 'master' | |
pull_request: | |
branches: | |
- 'master' | |
env: | |
GO_VERSION: 1.20.4 | |
GH_REGISTRY: ghcr.io | |
REPOSITORY_NAME: ${{ github.repository }} | |
jobs: | |
test: | |
name: Test | |
strategy: | |
matrix: | |
os: [ ubuntu-latest, macos-latest, windows-latest ] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Install Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Test | |
run: make tests | |
build: | |
name: Build | |
needs: [ test ] | |
strategy: | |
matrix: | |
os: [ ubuntu-latest, macos-latest, windows-latest ] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Install Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Build | |
run: | | |
go build -ldflags "-X main.version=${{ github.ref_name }}" -o main . | |
build-container: | |
name: Build Container | |
needs: [ test ] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
- name: Build Docker Images | |
uses: docker/build-push-action@v3 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
context: . | |
file: ./build/package/Dockerfile | |
builder: ${{ steps.buildx.outputs.name }} | |
build-args: | | |
VERSION=${{ github.ref_name }} | |
pull: true | |
push: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
release-container: | |
name: Release Container | |
needs: [ build, build-container ] | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ env.GH_REGISTRY }}/${{ env.REPOSITORY_NAME }} | |
${{ env.REPOSITORY_NAME }} | |
tags: | | |
type=semver,pattern={{version}},value=${{ github.ref_name }} | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.GH_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push version ${{ github.ref_name }} | |
uses: docker/build-push-action@v3 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
context: . | |
file: ./build/package/Dockerfile | |
build-args: | | |
VERSION=${{ github.ref_name }} | |
builder: ${{ steps.buildx.outputs.name }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
release-binaries: | |
name: Release Binaries | |
needs: [ build, build-container ] | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Create a GitHub release ${{ github.ref_name }} | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ github.ref_name }} | |
name: ${{ github.ref_name }} | |
prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }} | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Run GoReleaser ${{ github.ref_name }} | |
uses: goreleaser/goreleaser-action@v3 | |
with: | |
distribution: goreleaser | |
version: latest | |
args: release --clean | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |