Merge pull request #19 from HvH-gg/fix-cssharputils #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Publish | |
on: | |
push: | |
branches: | |
- master | |
paths-ignore: | |
- 'README.MD' | |
- '.github/workflows/**' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Prepare env | |
shell: bash | |
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Extract version number from README.md | |
id: extract_version | |
run: | | |
VERSION=$(grep -oP '(?<=# \[HvH\.gg\]\(https:\/\/hvh\.gg\) CS2 Essentials \()[0-9]+\.[0-9]+\.[0-9]+' README.MD) | |
if [ -z "$VERSION" ]; then | |
echo "No version number found in README.md. Exiting." | |
exit 1 | |
fi | |
echo "VERSION_NUMBER=$VERSION" >> $GITHUB_ENV | |
- name: Check if version already exists | |
id: check_version | |
run: | | |
if gh release view "${{ env.VERSION_NUMBER }}" > /dev/null 2>&1; then | |
echo "Version ${{ env.VERSION_NUMBER }} already exists. Exiting." | |
exit 0 | |
fi | |
- name: Build runtime ${{ env.VERSION_NUMBER }} | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build -c Release --no-restore /p:Version=${{ env.VERSION_NUMBER }} | |
- name: Copy CSSharpUtils.dll | |
run: | | |
mkdir -p release/addons/counterstrikesharp/plugins/CS2-Essentials | |
CSSharpUtilsDllPath=$(find ~/.nuget/packages/cssharputils/ -name "CSSharpUtils.dll" | head -n 1) | |
if [ -z "$CSSharpUtilsDllPath" ]; then | |
echo "CSSharpUtils.dll not found. Exiting." | |
exit 1 | |
fi | |
cp "$CSSharpUtilsDllPath" release/addons/counterstrikesharp/plugins/CS2-Essentials/ | |
- name: Create necessary directory structure and copy files | |
run: | | |
mkdir -p release/addons/counterstrikesharp/configs/plugins/CS2-Essentials | |
mkdir -p release/addons/counterstrikesharp/plugins/CS2-Essentials | |
mkdir -p release/addons/counterstrikesharp/gamedata | |
cp CS2-Essentials/CS2-Essentials.json.gamedata release/addons/counterstrikesharp/gamedata/CS2-Essentials.json | |
cp CS2-Essentials/CS2-Essentials.json.config.example release/addons/counterstrikesharp/configs/plugins/CS2-Essentials/CS2-Essentials.json | |
cp -r CS2-Essentials/bin/Release/net8.0/* release/addons/counterstrikesharp/plugins/CS2-Essentials/ | |
- name: Create a ZIP file with binaries | |
run: | | |
cd release | |
zip -r ../CS2-Essentials-${{ env.VERSION_NUMBER }}-${{ env.GITHUB_SHA_SHORT }}.zip addons | |
- name: Create GitHub Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ env.VERSION_NUMBER }} | |
release_name: ${{ env.VERSION_NUMBER }} | |
draft: false | |
prerelease: false | |
body: | | |
## Changes | |
- Auto-generated release | |
${{ github.event.head_commit.message }} | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./CS2-Essentials-${{ env.VERSION_NUMBER }}-${{ env.GITHUB_SHA_SHORT }}.zip | |
asset_name: CS2-Essentials-${{ env.VERSION_NUMBER }}-${{ env.GITHUB_SHA_SHORT }}.zip | |
asset_content_type: application/zip |