Merge pull request #5 from csdev/go-1.21 #21
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: docker | |
on: | |
pull_request: | |
push: | |
branches: | |
- 'master' | |
tags: | |
- 'v*' | |
workflow_dispatch: | |
# prevent concurrent workflow runs | |
# - for pull requests, we only want to build the latest commit | |
# - for master and tags, we need to run all builds, since containers must be pushed | |
concurrency: | |
group: docker-${{ github.ref }} | |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
env: | |
IMAGE_NAME: csang/ezghsa | |
jobs: | |
docker: | |
timeout-minutes: 20 | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v3 | |
- | |
name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.IMAGE_NAME }} | |
tags: | | |
type=ref,event=branch | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- | |
name: Build dev image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./build/dev/Dockerfile | |
load: true | |
tags: ${{ env.IMAGE_NAME }}-dev:gha | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- | |
name: Test dev image | |
run: > | |
docker run --rm "$IMAGE_NAME"-dev:gha \ | |
/bin/sh -c 'go test -coverprofile=c.out "./..." && go tool cover -func=c.out' | |
- | |
name: Login to Docker Hub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Build and push prod image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./build/prod/Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
release: | |
needs: docker | |
if: startsWith(github.ref, 'refs/tags/v') | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # for releases api | |
packages: read | |
strategy: | |
matrix: | |
platform: | |
- linux/amd64 | |
- linux/arm64 | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v3 | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Deploy standalone binaries | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
tag="${GITHUB_REF#'refs/tags/v'}-$(tr / - <<<"${{ matrix.platform }}")" | |
cid="$(docker create --platform="${{ matrix.platform }}" "$IMAGE_NAME":"${GITHUB_REF#'refs/tags/v'}")" | |
docker cp "${cid}:/opt/go/bin/ezghsa" "ezghsa-${tag}" | |
docker rm "$cid" | |
gh release upload "${GITHUB_REF#'refs/tags/'}" "ezghsa-${tag}" | |
shell: bash |