name: Release on: push: branches: - master - develop workflow_dispatch: {} permissions: contents: write jobs: build-and-release: runs-on: ubuntu-latest if: ${{ contains(github.event.head_commit.message, 'Release v') }} steps: - name: Checkout uses: actions/checkout@v4 - name: Extract version from commit message id: vars shell: bash run: | msg='${{ github.event.head_commit.message }}' # Expected format: "Release v4.0.14" -> version "4.0.14" ver=$(printf "%s" "$msg" | sed -nE 's/.*Release v([0-9]+\.[0-9]+\.[0-9]+).*/\1/p') if [ -z "$ver" ]; then echo "No version found in commit message: $msg" exit 1 fi echo "version=$ver" >> "$GITHUB_OUTPUT" echo "tag=v$ver" >> "$GITHUB_OUTPUT" - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: '9.0.x' - name: Build artifacts (win-x64) shell: bash env: RID: win-x64 run: | ver='${{ steps.vars.outputs.version }}' dotnet publish ./SPTarkov.Server/SPTarkov.Server.csproj -c Release -r "$RID" --self-contained false \ -p:SptVersion="$ver" -p:SptCommit="${{ github.sha }}" -p:SptBuildTime="$(date +%s)" -p:SptBuildType="RELEASE" \ /p:DebugType=None - name: Build artifacts (linux-x64) shell: bash env: RID: linux-x64 run: | ver='${{ steps.vars.outputs.version }}' dotnet publish ./SPTarkov.Server/SPTarkov.Server.csproj -c Release -r "$RID" --self-contained false \ -p:SptVersion="$ver" -p:SptCommit="${{ github.sha }}" -p:SptBuildTime="$(date +%s)" -p:SptBuildType="RELEASE" \ /p:DebugType=None - name: Build artifacts (osx-arm64) shell: bash env: RID: osx-arm64 run: | ver='${{ steps.vars.outputs.version }}' dotnet publish ./SPTarkov.Server/SPTarkov.Server.csproj -c Release -r "$RID" --self-contained false \ -p:SptVersion="$ver" -p:SptCommit="${{ github.sha }}" -p:SptBuildTime="$(date +%s)" -p:SptBuildType="RELEASE" \ /p:DebugType=None # STEP 1: Create the GitHub Release FIRST so we have an upload_id - name: Create GitHub Release id: create_release shell: bash env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAG: ${{ steps.vars.outputs.tag }} VERSION: ${{ steps.vars.outputs.version }} run: | payload=$(jq -n --arg tag "$TAG" --arg name "Release $VERSION" '{tag_name:$tag,name:$name,body:"Automated build",draft:false,prerelease:false}') res=$(curl -sS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" "https://api.github.com/repos/${{ github.repository }}/releases" -d "$payload") upload_id=$(echo "$res" | jq -r '.id') if [ "$upload_id" == "null" ] || [ -z "$upload_id" ]; then echo "Failed to create release. Response: $res" exit 1 fi echo "upload_id=$upload_id" >> "$GITHUB_OUTPUT" echo "Release created with ID: $upload_id" # STEP 2: Package and Upload Assets SECOND - name: Package + upload artifacts shell: bash env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} UPLOAD_ID: ${{ steps.create_release.outputs.upload_id }} REPO: ${{ github.repository }} run: | mkdir -p out for rid in win-x64 linux-x64 osx-arm64; do pubdir="./SPTarkov.Server/bin/Release/net9.0/$rid/publish" if [ ! -d "$pubdir" ]; then echo "Missing publish dir: $pubdir" exit 1 fi zipname="SPT-${rid}-${{ steps.vars.outputs.version }}.zip" fullpath="out/${zipname}" (cd "$pubdir" && zip -r "../../${fullpath}" .) if [ $? -ne 0 ]; then echo "Failed to create zip for $rid" exit 1 fi echo "Uploading ${fullpath}..." curl -sS -X POST \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "Accept: application/vnd.github+json" \ -H "Content-Type: application/zip" \ "https://uploads.github.com/repos/${REPO}/releases/${UPLOAD_ID}/assets?name=${zipname}" \ --data-binary "@${fullpath}" if [ $? -ne 0 ]; then echo "Failed to upload asset for $rid" exit 1 fi done echo "All artifacts uploaded successfully."