Skip to content

Promote

Promote #3

Workflow file for this run

name: Promote
on:
workflow_dispatch:
pull_request:
types: [closed]
branches:
- main
jobs:
promote:
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- name: Setup Go
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
with:
go-version-file: 'go.mod'
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@0a35821d5c230e903fcfe077583637dea1b27b47 # v9.0.0
with:
version: v2.6.2
- name: Run Go Tests
run: go test -v ./...
- name: Get code version
id: code_version
run: echo "version=$(grep '^VERSION=' Makefile | cut -d'=' -f2)" >> $GITHUB_OUTPUT
- name: Get latest release version
id: latest_release
env:
GH_TOKEN: ${{ github.token }}
run: | #shell
# Fetch latest release tag, remove 'v' prefix if it exists.
# If no release exists, default to 0.0.0 to allow the first version to be published.
LATEST_TAG=$(gh release view --json tagName --jq .tagName 2>/dev/null || echo "v0.0.0")
echo "version=${LATEST_TAG#v}" >> $GITHUB_OUTPUT
# yaml-embedded-languages
- name: Compare versions
run: | #shell
CODE_VERSION="${{ steps.code_version.outputs.version }}"
LATEST_RELEASE_VERSION="${{ steps.latest_release.outputs.version }}"
echo "Code version: $CODE_VERSION"
echo "Latest release version: $LATEST_RELEASE_VERSION"
if [ "$CODE_VERSION" = "$LATEST_RELEASE_VERSION" ]; then
echo "Error: Makefile VERSION in PR is the same as the latest release."
exit 1
fi
# Using sort -V for version comparison
LATEST_VERSION=$(printf "%s\n%s" "$CODE_VERSION" "$LATEST_RELEASE_VERSION" | sort -V | tail -n1)
if [ "$LATEST_VERSION" != "$CODE_VERSION" ]; then
echo "Error: Makefile VERSION in code is not greater than the latest release."
exit 1
fi
echo "Version check passed."
# yaml-embedded-languages
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.code_version.outputs.version }}
name: Release ${{ steps.code_version.outputs.version }}
body: |
Automated release for version ${{ steps.code_version.outputs.version }}
draft: false
prerelease: false