Skip to content

a few minor fixes

a few minor fixes #1

name: Build and Publish (Reusable)

Check failure on line 1 in .github/workflows/build-and-publish.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build-and-publish.yml

Invalid workflow file

(Line: 187, Col: 13): Unrecognized named-value: 'secrets'. Located at position 19 within expression: inputs.publish && secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != ''
on:
workflow_call:
inputs:
publish:
description: "Whether to publish the release and Docker image"
required: true
type: boolean
version:
description: "Version tag for the release (required if publish is true)"
required: false
type: string
registry:
description: "Container registry (docker.io, ghcr.io, etc.)"
required: false
type: string
default: ""
registry_namespace:
description: "Registry namespace/organization"
required: false
type: string
default: ""
image_name:
description: "Image name"
required: false
type: string
default: "temporal"
secrets:
DOCKER_USERNAME:
required: false
DOCKER_PASSWORD:
required: false
jobs:
build:
name: Build and Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
check-latest: true
cache: true
- name: Get build date
id: date
run: echo "date=$(date '+%F-%T')" >> $GITHUB_OUTPUT
- name: Get build unix timestamp
id: timestamp
run: echo "timestamp=$(date '+%s')" >> $GITHUB_OUTPUT
- name: Get git branch
id: branch
run: echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT
- name: Get build platform
id: platform
run: echo "platform=$(go version | cut -d ' ' -f 4)" >> $GITHUB_OUTPUT
- name: Get Go version
id: go
run: echo "go=$(go version | cut -d ' ' -f 3)" >> $GITHUB_OUTPUT
- name: Check if release is latest
if: inputs.publish
id: check_latest_release
uses: actions/github-script@v8
with:
script: |
const releaseTag = '${{ inputs.version }}';
const { data: release } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: releaseTag
});
const isLatest = !release.prerelease && !release.draft;
core.setOutput('is_latest', isLatest);
console.log(`Release: ${release.tag_name}`);
console.log(`Prerelease: ${release.prerelease}, Draft: ${release.draft}`);
console.log(`Should tag as latest: ${isLatest}`);
- name: Run GoReleaser (release)
if: inputs.publish
uses: goreleaser/goreleaser-action@v6.4.0
with:
version: v2.12.7
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_DATE: ${{ steps.date.outputs.date }}
BUILD_TS_UNIX: ${{ steps.timestamp.outputs.timestamp }}
GIT_BRANCH: ${{ steps.branch.outputs.branch }}
BUILD_PLATFORM: ${{ steps.platform.outputs.platform }}
GO_VERSION: ${{ steps.go.outputs.go }}
- name: Run GoReleaser (snapshot)
if: ${{ !inputs.publish }}
uses: goreleaser/goreleaser-action@v6.4.0
with:
version: v2.12.7
args: release --snapshot --clean
env:
BUILD_DATE: ${{ steps.date.outputs.date }}
BUILD_TS_UNIX: ${{ steps.timestamp.outputs.timestamp }}
GIT_BRANCH: ${{ steps.branch.outputs.branch }}
BUILD_PLATFORM: ${{ steps.platform.outputs.platform }}
GO_VERSION: ${{ steps.go.outputs.go }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get build metadata
id: meta
env:
INPUT_VERSION: ${{ inputs.version }}
INPUT_PUBLISH: ${{ inputs.publish }}
INPUT_REGISTRY: ${{ inputs.registry }}
INPUT_REGISTRY_NAMESPACE: ${{ inputs.registry_namespace }}
INPUT_IMAGE_NAME: ${{ inputs.image_name }}
REPO_OWNER: ${{ github.repository_owner }}
uses: actions/github-script@v7
with:
script: |
const inputVersion = process.env.INPUT_VERSION;
const inputPublish = process.env.INPUT_PUBLISH;
const inputRegistry = process.env.INPUT_REGISTRY;
const inputRegistryNamespace = process.env.INPUT_REGISTRY_NAMESPACE;
const inputImageName = process.env.INPUT_IMAGE_NAME;
const repoOwner = process.env.REPO_OWNER;
// Get git information
const { execSync } = require('child_process');
const cliSha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
const imageShaTag = execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
core.setOutput('cli_sha', cliSha);
core.setOutput('image_sha_tag', imageShaTag);
// Determine version
let version;
if (inputPublish === 'true') {
// Get version from input, strip 'v' prefix
version = inputVersion.startsWith('v') ? inputVersion.slice(1) : inputVersion;
} else {
version = 'snapshot';
}
core.setOutput('version', version);
// Determine registry (with auto-detection for temporalio vs forks)
let registry = inputRegistry;
// Set namespace (defaults to repository owner)
const namespace = inputRegistryNamespace || repoOwner;
core.setOutput('image_namespace', namespace);
// Set image name (defaults to 'temporal')
const imageName = inputImageName || 'temporal';
core.setOutput('image_name', imageName);
console.log(`Namespace: ${namespace}, Image: ${imageName}`);
- name: Build Docker image
if: ${{ !inputs.publish }}
run: |
docker buildx bake \
--file docker-bake.hcl \
cli
env:
CLI_SHA: ${{ steps.meta.outputs.cli_sha }}
IMAGE_SHA_TAG: ${{ steps.meta.outputs.image_sha_tag }}
VERSION: ${{ steps.meta.outputs.version }}
TAG_LATEST: false
IMAGE_NAMESPACE: ${{ steps.meta.outputs.image_namespace }}
IMAGE_NAME: ${{ steps.meta.outputs.image_name }}
GITHUB_REPOSITORY: ${{ github.repository }}
- name: Log in to Docker Hub
if: inputs.publish && secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != ''
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
if: ${{ inputs.publish }}
run: |
docker buildx bake \
--file docker-bake.hcl \
--push \
cli
env:
CLI_SHA: ${{ steps.meta.outputs.cli_sha }}
IMAGE_SHA_TAG: ${{ steps.meta.outputs.image_sha_tag }}
VERSION: ${{ steps.meta.outputs.version }}
TAG_LATEST: ${{ steps.check_latest_release.outputs.is_latest == 'true' }}
IMAGE_NAMESPACE: ${{ steps.meta.outputs.image_namespace }}
IMAGE_NAME: ${{ steps.meta.outputs.image_name }}
GITHUB_REPOSITORY: ${{ github.repository }}