mirror of
https://github.com/lukaszraczylo/shared-actions.git
synced 2026-06-09 23:03:54 +00:00
69 lines
2.1 KiB
YAML
69 lines
2.1 KiB
YAML
name: "Semantic Version"
|
|
description: "Calculate semantic version using semver-generator (built from source to avoid Docker :latest bootstrap loop)"
|
|
|
|
inputs:
|
|
config-file:
|
|
description: "Path to semver config file"
|
|
required: false
|
|
default: "semver.yaml"
|
|
semver-version:
|
|
description: "Ref of lukaszraczylo/semver-generator to install (branch, tag, or commit SHA)"
|
|
required: false
|
|
default: "main"
|
|
go-version:
|
|
description: "Go version to use when installing semver-generator"
|
|
required: false
|
|
default: ">=1.24"
|
|
|
|
outputs:
|
|
version:
|
|
description: "The calculated version (without v prefix)"
|
|
value: ${{ steps.format.outputs.version }}
|
|
version_tag:
|
|
description: "The version tag (with v prefix)"
|
|
value: ${{ steps.format.outputs.version_tag }}
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version: ${{ inputs.go-version }}
|
|
|
|
- name: Install semver-generator from source
|
|
shell: bash
|
|
env:
|
|
SEMVER_REF: ${{ inputs.semver-version }}
|
|
run: |
|
|
set -euo pipefail
|
|
# GOPROXY=direct avoids stale module-proxy cache when SEMVER_REF
|
|
# points to a commit that was just pushed (e.g. semver-generator
|
|
# bootstrapping its own release).
|
|
GOPROXY=direct GOFLAGS=-mod=mod \
|
|
go install "github.com/lukaszraczylo/semver-generator@${SEMVER_REF}"
|
|
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
|
|
|
|
- name: Calculate version
|
|
id: semver
|
|
shell: bash
|
|
env:
|
|
CONFIG_FILE: ${{ inputs.config-file }}
|
|
run: |
|
|
set -euo pipefail
|
|
OUT=$(semver-generator generate -l -c "${CONFIG_FILE}")
|
|
echo "${OUT}"
|
|
VERSION=$(printf '%s\n' "${OUT}" | sed -e 's|SEMVER ||g' | tr -d '[:space:]')
|
|
echo "semantic_version=${VERSION}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Format version
|
|
id: format
|
|
shell: bash
|
|
env:
|
|
VERSION: ${{ steps.semver.outputs.semantic_version }}
|
|
run: |
|
|
set -euo pipefail
|
|
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
|
echo "version_tag=v${VERSION}" >> "$GITHUB_OUTPUT"
|
|
echo "Version: v${VERSION}"
|