Files
workflows/.gitea/workflows/go-binary.yaml

103 lines
2.9 KiB
YAML

# This is a shared workflow that will build a go binary by executing
# the following steps:
#
# - checkout the code
# - download the go modules
# - run go vet
# - run the unit tests and generate a coverage report
# - build the binary
# - upload the binary as an artifact
#
# A number of input params are used to customize the build.
name: Build a go binary
on:
workflow_call:
inputs:
package-name:
description: "Name of the package/binary that will be built"
required: true
type: string
builder-image:
description: "Container image to use for the build"
required: false
type: string
default: gitea.ampenberger.com/campenbe/img-builder:3.22-1.24
version:
description: "Version string to embed in the binary"
required: false
type: string
default: development
git_user:
description: "Git user to use for checkout and the container registry"
required: false
type: string
default: campenbe
secrets:
# Password to log into the container registry
PASSWORD:
required: true
# Token to access the git repository
GIT_TOKEN:
required: true
env:
PACKAGE_NAME: ${{ inputs.package-name }}
ARTIFACT_UPLOAD: ${{ env.ACT_EXEC == 'true' && 'actions/upload-artifact@v2' || 'actions/upload-artifact@v3' }}
ARTIFACT_DOWNLOAD: ${{ env.ACT_EXEC == 'true' && 'actions/download-artifact@v2' || 'actions/download-artifact@v3' }}
VERSION: ${{ inputs.version }}
jobs:
go:
runs-on: ubuntu-latest
container:
image: ${{inputs.builder-image}}
credentials:
username: ${{inputs.git_user}}
password: ${{secrets.PASSWORD}}
steps:
- name: Install tools
run : |
apk add vips-dev
gitea_addr.sh
env | sort
- name: Fix git access
run: |
git config --global url."https://git:${{secrets.GIT_TOKEN}}@gitea.ampenberger.com/${{inputs.git_user}}/.insteadOf" git://git.ampenberger.com/
- uses: actions/checkout@v4
with:
submodules: false
- name: Download modules
run: |
git config --global url."https://git:${{secrets.GIT_TOKEN}}@gitea.ampenberger.com/${{inputs.git_user}}/.insteadOf" ssh://git.ampenberger.com/
go mod download -x
- name: vet the code
run: mage -v vet
- name: unit tests and coverage
run: mage -v coverReport
- name: coverage artifact
uses: "${{env.ARTIFACT_UPLOAD}}"
with:
name: coverage
path: build/coverage.html
- name: build the binary
run: |
[ -d build ] || mkdir build
go build -v -o build/${PACKAGE_NAME} -ldflags "-X main.Version=${VERSION:-development}" .
echo "Built binary: ${PACKAGE_NAME}"
- name: Upload artifact
uses: "${{env.ARTIFACT_UPLOAD}}"
with:
name: ${{env.PACKAGE_NAME}}
path: build/