Skip to content

Build and Release

Build and Release #3

Workflow file for this run

name: Build and Release
on:
workflow_dispatch:
jobs:
build-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from ModuleVersion
id: version
run: |
VERSION=$(grep -rhoP 'ModuleVersion\s*=>\s*"\K[^"]+' --include="*.cs" | head -1)
if [ -z "$VERSION" ]; then
echo "::error::Could not find ModuleVersion in any .cs file"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
cache: true
cache-dependency-path: "**/*.csproj"
- name: Restore and Publish
run: |
dotnet restore AutoUpdater.csproj
dotnet publish AutoUpdater.csproj -c Release -o publish
- name: Create zip artifact
run: |
if [ ! -f publish/AutoUpdater.dll ]; then
echo "::error::publish/AutoUpdater.dll not found after publish"
exit 1
fi
# CSS install layout: archive root contains AutoUpdater/ to be
# extracted into counterstrikesharp/plugins
rm -rf package
mkdir -p package/AutoUpdater
cp -r publish/. package/AutoUpdater/
cd package
zip -r ../AutoUpdater.zip AutoUpdater
cd ..
echo "Created AutoUpdater.zip"
- name: Prepare release artifact
id: zip
run: |
VERSION="${{ steps.version.outputs.version }}"
ZIP_SRC=$(find . -name "AutoUpdater.zip" -not -path "./release-artifacts/*" | head -1)
if [ -z "$ZIP_SRC" ]; then
echo "::error::AutoUpdater.zip not found after build"
exit 1
fi
echo "Found zip: $ZIP_SRC"
mkdir -p release-artifacts
NEW_NAME="AutoUpdater-v${VERSION}.zip"
mv "$ZIP_SRC" "release-artifacts/$NEW_NAME"
echo "artifact=release-artifacts/$NEW_NAME" >> $GITHUB_OUTPUT
echo "Prepared: $NEW_NAME"
- name: Determine release tag
id: tag
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.version.outputs.version }}"
REPO_NAME="${{ github.event.repository.name }}"
BASE_TAG="v${VERSION}"
TAG="$BASE_TAG"
TITLE="${BASE_TAG}"
BUILD_NUM=1
while gh release view "$TAG" &>/dev/null; do
BUILD_NUM=$((BUILD_NUM + 1))
TAG="${BASE_TAG}-${BUILD_NUM}"
TITLE="${REPO_NAME} | ${BASE_TAG}#${BUILD_NUM}"
echo "Tag exists, trying: $TAG"
done
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "title=$TITLE" >> $GITHUB_OUTPUT
echo "Using tag: $TAG"
- name: Get previous tag for changelog link
id: prev_tag
run: |
PREV=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "prev_tag=$PREV" >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.version.outputs.version }}"
TAG="${{ steps.tag.outputs.tag }}"
TITLE="${{ steps.tag.outputs.title }}"
PREV_TAG="${{ steps.prev_tag.outputs.prev_tag }}"
PRERELEASE_FLAG=""
if [[ "$VERSION" == *-* ]]; then
PRERELEASE_FLAG="--prerelease"
fi
NOTES="Release ${TAG}"
if [ -n "$PREV_TAG" ]; then
NOTES="${NOTES}"$'\n\n'"**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${TAG}"
fi
gh release create "$TAG" \
--title "$TITLE" \
--notes "$NOTES" \
$PRERELEASE_FLAG \
"${{ steps.zip.outputs.artifact }}"
echo "Release $TAG created successfully!"