Skip to content

chore(deps): update github actions #36

chore(deps): update github actions

chore(deps): update github actions #36

name: Shared Go Build

Check failure on line 1 in .github/workflows/shared-go-build.yaml

View workflow run for this annotation

GitHub Actions / .github/workflows/shared-go-build.yaml

Invalid workflow file

(Line: 51, Col: 17): Unrecognized named-value: 'inputs'. Located at position 1 within expression: inputs.push == true && 'write' || 'read', (Line: 51, Col: 17): Unexpected value '${{ inputs.push == true && 'write' || 'read' }}'
on:
workflow_call:
inputs:
runs-on:
description: "The runner to use for the job (must be a Linux or macOS runner; this workflow requires make)"
required: false
default: "ubuntu-latest"
type: string
working-directory:
description: "Working directory for the job"
required: false
default: "."
type: string
build-target:
description: "The make target to run for the build (e.g. build, build-all, docker-build)"
required: false
default: "build"
type: string
docker-build:
description: "Build and optionally push a Docker image after the Go build"
required: false
default: false
type: boolean
image-name:
description: "Full GHCR image name, e.g. ghcr.io/cloudoperators/myapp (must start with ghcr.io/ when push is true)"
required: false
default: ""
type: string
platforms:
description: "Comma-separated list of target platforms for the Docker image"
required: false
default: "linux/amd64,linux/arm64"
type: string
push:
description: "Push the built Docker image to the registry"
required: false
default: false
type: boolean
secrets:
registry-token:
description: "Token used to authenticate to the container registry when pushing"
required: false
jobs:
build:
runs-on: ${{ inputs.runs-on }}
permissions:
contents: read
packages: ${{ inputs.push == true && 'write' || 'read' }}
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- name: Checkout repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
- name: Validate inputs
env:
PUSH: ${{ inputs.push }}
DOCKER_BUILD: ${{ inputs.docker-build }}
run: |
case "$RUNNER_OS" in
Linux|macOS) ;;
*) echo "ERROR: this workflow requires a Linux or macOS runner (needs make); got: $RUNNER_OS"; exit 1 ;;
esac
if [ "$PUSH" = "true" ] && [ "$DOCKER_BUILD" != "true" ]; then
echo "ERROR: push=true requires docker-build=true"
exit 1
fi
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
with:
go-version-file: ${{ format('{0}/go.mod', inputs.working-directory) }}
cache: true
cache-dependency-path: ${{ format('{0}/go.sum', inputs.working-directory) }}
- name: Build
env:
BUILD_TARGET: ${{ inputs.build-target }}
run: make "$BUILD_TARGET"
- name: Validate docker-build inputs
if: inputs.docker-build == true
env:
IMAGE_NAME: ${{ inputs.image-name }}
PUSH: ${{ inputs.push }}
run: |
if [ "$RUNNER_OS" != "Linux" ]; then
echo "ERROR: docker-build requires a Linux runner; got: $RUNNER_OS"
exit 1
fi
if [ -z "$IMAGE_NAME" ]; then
echo "ERROR: image-name is required when docker-build is true"
exit 1
fi
case "$IMAGE_NAME" in
ghcr.io/*) ;;
*)
if [ "$PUSH" = "true" ]; then
echo "ERROR: image-name must start with 'ghcr.io/' when push is true (got: '$IMAGE_NAME')"
exit 1
fi
;;
esac
- name: Set up QEMU
if: inputs.docker-build == true
uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4
- name: Set up Docker Buildx
if: inputs.docker-build == true
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- name: Log in to container registry
if: inputs.docker-build == true && inputs.push == true
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.registry-token != '' && secrets.registry-token || secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
if: inputs.docker-build == true
id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
with:
images: ${{ inputs.image-name }}
- name: Build and push Docker image
if: inputs.docker-build == true
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
with:
context: ${{ inputs.working-directory }}
platforms: ${{ inputs.platforms }}
push: ${{ inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}