Build #1
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: Build | |
on: | |
workflow_call: | |
inputs: | |
GO_VERSION: | |
required: true | |
type: string | |
REGISTRY: | |
required: true | |
type: string | |
NAMESPACE: | |
required: true | |
type: string | |
TAG: | |
required: true | |
type: string | |
MAJOR_TAG: | |
required: false | |
type: string | |
MINOR_TAG: | |
required: false | |
type: string | |
PATCH_TAG: | |
required: false | |
type: string | |
PLATFORMS: | |
required: false | |
type: string | |
workflow_dispatch: | |
inputs: | |
GO_VERSION: | |
description: Go version to use | |
required: true | |
type: string | |
default: 1.22.4 | |
REGISTRY: | |
description: Target registry to push images | |
required: true | |
type: string | |
default: ghcr.io | |
NAMESPACE: | |
description: Target namespace to the given registry | |
required: true | |
type: string | |
default: titigmr/external-dns-midaas-webhook | |
PLATFORMS: | |
description: Target platforms for build | |
required: false | |
type: string | |
default: linux/amd64,linux/arm64 | |
jobs: | |
vars: | |
name: Generate variables | |
runs-on: ubuntu-latest | |
outputs: | |
short-sha: ${{ steps.infos.outputs.SHORT_SHA }} | |
platforms-json: ${{ steps.infos.outputs.PLATFORMS_JSON }} | |
steps: | |
- name: Get variables | |
id: infos | |
run: | | |
echo "SHORT_SHA=sha-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
echo "PLATFORMS_JSON=$(echo "$PLATFORMS"| jq -c 'split(",")')" >> $GITHUB_OUTPUT | |
build-binaries: | |
name: Build application | |
runs-on: ubuntu-latest | |
needs: | |
- vars | |
strategy: | |
matrix: | |
platforms: ${{ needs.vars.outputs.platforms-json }} | |
steps: | |
- name: Checks-out repository | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ inputs.GO_VERSION }} | |
- name: Install dependencies | |
run: go mod download | |
- name: Run vet command | |
run: go vet . | |
- name: Run build | |
run: | | |
BUILD_OS=$(echo ${{ matrix.platforms }} | cut -d '/' -f 1) | |
BUILD_ARCH=$(echo ${{ matrix.platforms }} | cut -d '/' -f 2,3) | |
CGO_ENABLED=0 GOOS=${BUILD_OS} GOARCH=${BUILD_ARCH} \ | |
go build -o ./binaries/external-dns-midaas-webhook_${BUILD_OS}-${BUILD_ARCH} . | |
- name: Upload test results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: external-dns-midaas-webhook_${BUILD_OS}-${BUILD_ARCH} | |
path: ./binaries/external-dns-midaas-webhook_${BUILD_OS}-${BUILD_ARCH} | |
build-docker: | |
name: Build application | |
runs-on: ubuntu-latest | |
needs: | |
- vars | |
steps: | |
- name: Checks-out repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Set up QEMU (for multi platform build) | |
uses: docker/setup-qemu-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ inputs.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
logout: true | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ inputs.REGISTRY }}/${{ inputs.NAMESPACE }} | |
tags: | | |
type=raw,value=${{ needs.vars.outputs.short-sha }},enable=${{ inputs.TAG == '' }} | |
type=raw,value=${{ inputs.TAG }},enable=${{ inputs.TAG != '' }} | |
type=raw,value=${{ inputs.MAJOR_TAG }}.${{ inputs.MINOR_TAG }},enable=${{ inputs.MAJOR_TAG != '' && inputs.MINOR_TAG != '' }} | |
type=raw,value=${{ inputs.MAJOR_TAG }},enable=${{ inputs.MAJOR_TAG != '' }} | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
- name: Build and push docker image | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
provenance: false | |
platforms: ${{ inputs.PLATFORMS }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |