Skip to content

Update build.yml

Update build.yml #15

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Latest Build
on:
push:
branches: [ "main" ]
tags:
- v*
pull_request:
branches: [ "main" ]
jobs:
build_latest:
runs-on: ubuntu-latest
env:
IMAGE: ghcr.io/pommes/nginx-proxy-metrics
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Build Go
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./.build/main ./cmd
- name: Test Go
run: go test -v ./...
- name: Build and push latest image
run: |
docker login --username pommes --password ${{ secrets.GHCR_IMAGE_REGISTRY_SECRET }} ghcr.io
docker build . --tag ghcr.io/pommes/nginx-proxy-metrics:latest
docker push ${IMAGE}:latest
- name: Release with Tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
FULL_VERSION=$(echo ${GITHUB_REF#refs/tags/v})
MAJOR_MINOR_VERSION=$(echo ${FULL_VERSION} | cut -d. -f1-2)
MAJOR_VERSION=$(echo ${FULL_VERSION} | cut -d. -f1)
docker login --username pommes --password ${{ secrets.GHCR_IMAGE_REGISTRY_SECRET }} ghcr.io
docker build . --tag ${IMAGE}:${FULL_VERSION}
docker push ${IMAGE}:${FULL_VERSION}
docker tag${IMAGE}:${FULL_VERSION} ${IMAGE}:${MAJOR_MINOR_VERSION}
docker push ${IMAGE}:${MAJOR_MINOR_VERSION}
docker tag${IMAGE}:${FULL_VERSION} ${IMAGE}:${MAJOR_VERSION}
docker push ${IMAGE}:${MAJOR_VERSION}