Skip to content

Release

Release #1

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.1.0)"
required: true
type: string
dry_run:
description: "Preview without making changes"
required: false
type: boolean
default: false
jobs:
release:
if: github.repository == 'EndstoneMC/cpp-example-plugin'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Validate version
run: |
VERSION="${{ inputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid version format: $VERSION (expected X.Y.Z)"
exit 1
fi
if git tag -l "v$VERSION" | grep -q .; then
echo "::error::Tag v$VERSION already exists"
exit 1
fi
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Extract unreleased changelog
run: |
BODY=$(sed -n '/^## \[Unreleased\]/,/^## \[/{/^## \[/d; p}' CHANGELOG.md)
BODY=$(echo "$BODY" | sed '/./,$!d' | sed -e :a -e '/^\n*$/{$d;N;ba}')
if [ -z "$BODY" ]; then
echo "::error::Unreleased section in CHANGELOG.md is empty"
exit 1
fi
echo "$BODY" > /tmp/release_body.md
echo "Extracted changelog:"
echo "$BODY"
- name: Preview
if: inputs.dry_run
run: |
DATE=$(date -u +%Y-%m-%d)
echo "=== Dry Run ==="
echo "Version: $VERSION"
echo "Tag: v$VERSION"
echo "Date: $DATE"
echo ""
echo "=== Release Body ==="
cat /tmp/release_body.md
- name: Update CHANGELOG.md
if: ${{ !inputs.dry_run }}
run: |
DATE=$(date -u +%Y-%m-%d)
sed -i "s/^## \[Unreleased\]/## [Unreleased]\n\n## [$VERSION] - $DATE/" CHANGELOG.md
- name: Commit and tag
if: ${{ !inputs.dry_run }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "Release $VERSION"
git tag "v$VERSION"
- name: Push
if: ${{ !inputs.dry_run }}
run: |
git push origin main
git push origin "v$VERSION"
- name: Create GitHub release
if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ github.token }}
run: |
PREV_TAG=$(git tag --sort=-v:refname | sed -n '2p')
if [ -n "$PREV_TAG" ]; then
printf '\n**Full Changelog**: https://github.com/%s/compare/%s...v%s\n' \
"${{ github.repository }}" "$PREV_TAG" "$VERSION" >> /tmp/release_body.md
fi
gh release create "v$VERSION" \
--title "v$VERSION" \
--notes-file /tmp/release_body.md
build_windows:
if: ${{ !inputs.dry_run }}
needs: [ release ]
runs-on: windows-2022
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: v${{ inputs.version }}
- name: Set up MSVC
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86_64
- name: Set up CMake and Ninja
uses: lukka/get-cmake@latest
- name: Build with CMake
run: |
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build
- name: Attach to release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload "v${{ inputs.version }}" build/endstone_*.dll build/endstone_*.pdb
build_linux:
if: ${{ !inputs.dry_run }}
needs: [ release ]
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: v${{ inputs.version }}
- name: Set up Clang 18
env:
LLVM_VERSION: 18
run: |
sudo apt-get update -y -q
sudo apt-get install -y -q lsb-release wget software-properties-common gnupg
sudo wget https://apt.llvm.org/llvm.sh
sudo chmod +x llvm.sh
sudo ./llvm.sh ${LLVM_VERSION}
sudo apt-get install -y -q libc++-${LLVM_VERSION}-dev libc++abi-${LLVM_VERSION}-dev
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${LLVM_VERSION} 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-${LLVM_VERSION} 100
- name: Set up CMake and Ninja
uses: lukka/get-cmake@latest
- name: Build with CMake
run: |
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build
- name: Attach to release
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "v${{ inputs.version }}" build/endstone_*.so