Skip to content

Commit

Permalink
update ci with jpillora/go-template
Browse files Browse the repository at this point in the history
  • Loading branch information
jpillora committed Aug 5, 2024
1 parent daba077 commit 6592085
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 18 deletions.
16 changes: 16 additions & 0 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# build stage
FROM golang:alpine AS build
RUN apk update && apk add git
ADD . /src
WORKDIR /src
ENV CGO_ENABLED 0
RUN go build \
-trimpath \
-ldflags "-s -w -X main.version=$(git describe --abbrev=0 --tags)" \
-o /tmp/bin
# run stage
FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /app
COPY --from=build /tmp/bin /app/bin
ENTRYPOINT ["/app/bin"]
12 changes: 9 additions & 3 deletions .github/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ builds:
- windows
- openbsd
goarch:
- 386
- '386'
- amd64
- arm
- arm64
goarm:
- 6
- 7
- '6'
- '7'
nfpms:
- maintainer: "https://github.com/{{ .Env.GITHUB_USER }}"
formats:
- deb
- rpm
- apk
archives:
- format: gz
files:
Expand Down
86 changes: 71 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ name: CI
on:
pull_request: {}
push: {}
workflow_dispatch:
inputs: {}
permissions: write-all
jobs:
ci:
name: CI
runs-on: ubuntu-latest
# ================
# BUILD AND TEST JOB
# ================
test:
name: Build & Test
strategy:
matrix:
# optionally test/build across multiple platforms/Go-versions
go-version: ['1.22'] # '1.16', '1.17', '1.18,
platform: [ubuntu-latest] # , macos-latest, windows-latest
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -16,19 +23,68 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: ${{ matrix.go-version }}
check-latest: true
cache: true
- name: Build
run: go build -v -o /dev/null .
- name: Test
run: go test -v ./...
- name: Run GoReleaser
if: startsWith(github.ref, 'refs/tags/v')
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --rm-dist --config .github/goreleaser.yml
# ================
# RELEASE BINARIES (on push "v*" tag)
# ================
release_binaries:
name: Release Binaries
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: goreleaser
uses: docker://goreleaser/goreleaser:latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USER: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: release --config .github/goreleaser.yml
# ================
# RELEASE DOCKER IMAGES (on push "v*" tag)
# ================
release_docker:
name: Release Docker Images
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push
uses: docker/build-push-action@v3
with:
file: .github/Dockerfile
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/386,linux/arm/v7,linux/arm/v6
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit 6592085

Please sign in to comment.