diff --git a/.github/actions/artifact-name/action.yml b/.github/actions/artifact-name/action.yml new file mode 100644 index 0000000000..788f7b81d6 --- /dev/null +++ b/.github/actions/artifact-name/action.yml @@ -0,0 +1,28 @@ +name: Artifact filename +description: Generate a branch or pull request artifact filename +inputs: + prefix: + description: Filename prefix + required: true + extension: + description: Filename extension + required: true +outputs: + name: + description: Generated artifact filename + value: ${{ steps.filename.outputs.name }} +runs: + using: composite + steps: + - id: filename + uses: actions/github-script@v9 + env: + REF_NAME: ${{ github.ref_name }} + ARTIFACT_PREFIX: ${{ inputs.prefix }} + ARTIFACT_EXTENSION: ${{ inputs.extension }} + with: + script: | + const suffix = context.eventName === 'pull_request' + ? `pr-${context.payload.pull_request.number}` + : process.env.REF_NAME.replace(/[^A-Za-z0-9._-]/g, '-'); + core.setOutput('name', `${process.env.ARTIFACT_PREFIX}-${suffix}.${process.env.ARTIFACT_EXTENSION}`); \ No newline at end of file diff --git a/.github/workflows/build-blakserv-linux-x64.yml b/.github/workflows/build-blakserv-linux-x64.yml new file mode 100644 index 0000000000..c812cbb1a3 --- /dev/null +++ b/.github/workflows/build-blakserv-linux-x64.yml @@ -0,0 +1,81 @@ +name: Build Blakserv Linux x64 + +on: + push: + branches: + - develop + - master + pull_request: + branches: + - develop + - master + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-24.04 + timeout-minutes: 30 + outputs: + artifact_name: ${{ steps.artifact_name.outputs.name }} + steps: + - name: Check out source + uses: actions/checkout@v4 + + - name: Set artifact filename + id: artifact_name + uses: ./.github/actions/artifact-name + with: + prefix: blakserv-linux-x64 + extension: tar.gz + + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends -y g++ make flex bison libjansson-dev libpq-dev + + - name: Build Blakserv and runtime data + run: make -f makefile.linux Bserver Bresource Bkod + + - name: Package server runtime + env: + ARTIFACT_NAME: ${{ steps.artifact_name.outputs.name }} + run: | + server_dir=dist/blakserv-linux-x64 + install -d "$server_dir/loadkod" "$server_dir/memmap" "$server_dir/rooms" \ + "$server_dir/rsc" "$server_dir/channel" "$server_dir/savegame" + test -s run/server/loadkod/system.bof + test -s run/server/rsc/rsc0000.rsb + install -m 0755 blakserv/debug/blakserv "$server_dir/blakserv" + install -m 0755 run/server/blakadmin.sh "$server_dir/blakadmin.sh" + sed -i 's/\r$//' "$server_dir/blakadmin.sh" + install -m 0644 run/server/packages.txt run/server/blakston.khd \ + run/server/protocol.khd run/server/kodbase.txt "$server_dir/" + cp -a run/server/loadkod/. "$server_dir/loadkod/" + cp -a run/server/memmap/. "$server_dir/memmap/" + cp -a run/server/rooms/. "$server_dir/rooms/" + cp -a run/server/rsc/. "$server_dir/rsc/" + tar -C "$server_dir" --exclude=.gitignore -czf "$ARTIFACT_NAME" . + + - name: Upload Linux x64 artifact + uses: actions/upload-artifact@v7 + with: + path: ${{ steps.artifact_name.outputs.name }} + archive: false + if-no-files-found: error + retention-days: ${{ github.event_name == 'pull_request' && 5 || 90 }} + + cleanup-old-branch-artifacts: + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' + needs: build + permissions: + actions: write + uses: ./.github/workflows/cleanup-old-branch-artifacts.yml + with: + artifact-name: ${{ needs.build.outputs.artifact_name }} \ No newline at end of file diff --git a/.github/workflows/build-blakserv-windows-x64.yml b/.github/workflows/build-blakserv-windows-x64.yml new file mode 100644 index 0000000000..6c4650af7f --- /dev/null +++ b/.github/workflows/build-blakserv-windows-x64.yml @@ -0,0 +1,127 @@ +name: Build Blakserv Windows x64 + +on: + push: + branches: + - develop + - master + pull_request: + branches: + - develop + - master + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + build: + runs-on: windows-2022 + timeout-minutes: 30 + outputs: + artifact_name: ${{ steps.artifact_name.outputs.name }} + steps: + - name: Check out source + uses: actions/checkout@v4 + + - name: Set artifact filename + id: artifact_name + uses: ./.github/actions/artifact-name + with: + prefix: blakserv-windows-x64 + extension: zip + + - name: Set up MSBuild + uses: microsoft/setup-msbuild@v2 + + - name: Set up MSVC developer environment + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + + - name: Build Blakserv and server KOD data + shell: pwsh + run: | + msbuild Meridian59.sln '/t:Server\blakserv;Server\blakod' /m:2 /nologo /p:Configuration=Release /p:Platform=x64 /p:BuildServerResources=false + + - name: Package server runtime + shell: pwsh + env: + ARTIFACT_NAME: ${{ steps.artifact_name.outputs.name }} + run: | + $serverDir = "dist\blakserv-windows-x64" + $serverDirs = @("loadkod", "memmap", "rooms", "rsc", "channel", "savegame") + foreach ($directory in $serverDirs) { + New-Item -ItemType Directory -Force -Path (Join-Path $serverDir $directory) | Out-Null + } + + foreach ($file in @("run\server\loadkod\system.bof", "run\server\rsc\rsc0000.rsb")) { + if (-not (Test-Path $file -PathType Leaf) -or (Get-Item $file).Length -eq 0) { + throw "Missing or empty generated server data: $file" + } + } + $serverFiles = @("blakadmin.sh", "packages.txt", "blakston.khd", "protocol.khd", "kodbase.txt") + foreach ($file in $serverFiles) { + Copy-Item (Join-Path "run\server" $file) $serverDir + } + foreach ($directory in @("loadkod", "memmap", "rsc")) { + $source = Join-Path "run\server" $directory + $destination = Join-Path $serverDir $directory + Copy-Item "$source\*" $destination -Recurse -Force + } + Copy-Item "blakserv\x64\Release\blakserv.exe" $serverDir + Copy-Item "blakserv\x64\Release\blakserv.map" $serverDir + Copy-Item "blakserv\x64\Release\blakserv.pdb" $serverDir + + Copy-Item "resource\rooms\*.roo" (Join-Path $serverDir "rooms") + + $runtimeDlls = @( + "libpq.dll", + "libcrypto-3-x64.dll", + "libintl-9.dll", + "libssl-3-x64.dll", + "libiconv-2.dll", + "libwinpthread-1.dll" + ) + foreach ($dll in $runtimeDlls) { + $source = Join-Path "bin" $dll + if (-not (Test-Path $source)) { + throw "Missing runtime dependency: $source" + } + Copy-Item $source $serverDir + } + + Get-ChildItem $serverDir -Filter ".gitignore" -File -Recurse -Force | Remove-Item -Force + Compress-Archive -Path "$serverDir\*" -DestinationPath $env:ARTIFACT_NAME -Force + Add-Type -AssemblyName System.IO.Compression.FileSystem + $archive = [System.IO.Compression.ZipFile]::Open((Join-Path (Get-Location) $env:ARTIFACT_NAME), [System.IO.Compression.ZipArchiveMode]::Update) + try { + foreach ($directory in $serverDirs) { + if (-not $archive.GetEntry("$directory/")) { + [void]$archive.CreateEntry("$directory/") + } + } + } finally { + $archive.Dispose() + } + + - name: Upload Windows x64 artifact + uses: actions/upload-artifact@v7 + with: + path: ${{ steps.artifact_name.outputs.name }} + archive: false + if-no-files-found: error + retention-days: ${{ github.event_name == 'pull_request' && 5 || 90 }} + + cleanup-old-branch-artifacts: + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' + needs: build + permissions: + actions: write + uses: ./.github/workflows/cleanup-old-branch-artifacts.yml + with: + artifact-name: ${{ needs.build.outputs.artifact_name }} \ No newline at end of file diff --git a/.github/workflows/cleanup-old-branch-artifacts.yml b/.github/workflows/cleanup-old-branch-artifacts.yml new file mode 100644 index 0000000000..59fc28369b --- /dev/null +++ b/.github/workflows/cleanup-old-branch-artifacts.yml @@ -0,0 +1,51 @@ +name: Cleanup old branch artifacts + +on: + workflow_call: + inputs: + artifact-name: + description: Name of the artifact to keep for the current branch + required: true + type: string + +permissions: + actions: write + +jobs: + cleanup: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - name: Keep only the latest branch artifact + uses: actions/github-script@v9 + env: + ARTIFACT_NAME: ${{ inputs.artifact-name }} + with: + script: | + const branch = context.ref.replace(/^refs\/heads\//, ""); + const repositoryId = context.payload.repository.id; + const currentRunId = Number(context.runId); + const artifacts = await github.paginate( + github.rest.actions.listArtifactsForRepo, + { + owner: context.repo.owner, + repo: context.repo.repo, + name: process.env.ARTIFACT_NAME, + per_page: 100, + }, + (response) => response.data.artifacts, + ); + + const staleArtifacts = artifacts.filter((artifact) => + artifact.workflow_run?.head_branch === branch && + artifact.workflow_run?.head_repository_id === repositoryId && + artifact.workflow_run?.id !== currentRunId + ); + + for (const artifact of staleArtifacts) { + await github.rest.actions.deleteArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: artifact.id, + }); + } \ No newline at end of file diff --git a/blakserv/blakserv.vcxproj b/blakserv/blakserv.vcxproj index 8bc4064008..68c3d90579 100644 --- a/blakserv/blakserv.vcxproj +++ b/blakserv/blakserv.vcxproj @@ -548,7 +548,7 @@ call "$(ProjectDir)copy_postgres_runtime.bat" "$(SolutionDir)bin" "$(SolutionDir {f61a1cc1-dc47-4407-bfe0-a2221e5eecca} - + {15142a8c-248c-402a-90bf-c4b5c14cd8dc} false true diff --git a/kod/blakod.vcxproj b/kod/blakod.vcxproj index d347d31306..4758601c4d 100644 --- a/kod/blakod.vcxproj +++ b/kod/blakod.vcxproj @@ -48,10 +48,10 @@ $(ProjectDir) blakdiff - nmake all + nmake all || exit /b 1 rmdir /S /Q $(ProjectDir)\vsbuildfolder >nul 2>&1 - nmake clean all + nmake clean all || exit /b 1 rmdir /S /Q $(ProjectDir)\vsbuildfolder >nul 2>&1 nmake clean $(ProjectDir) @@ -59,10 +59,10 @@ rmdir /S /Q $(ProjectDir)\vsbuildfolder >nul 2>&1 $(ProjectDir) blakdiff - nmake all + nmake all || exit /b 1 rmdir /S /Q $(ProjectDir)\vsbuildfolder >nul 2>&1 - nmake clean all + nmake clean all || exit /b 1 rmdir /S /Q $(ProjectDir)\vsbuildfolder >nul 2>&1 nmake clean $(ProjectDir) diff --git a/kod/makefile b/kod/makefile index 030b8da7fa..9eb4dc9591 100644 --- a/kod/makefile +++ b/kod/makefile @@ -24,7 +24,7 @@ all : @echo Copying .rsc files, creating server and client .rsb files @-$(RM) $(BLAKSERVRUNDIR)\rsc\*.rsb >nul 2>&1 @-$(RM) $(CLIENTRUNDIR)\resource\*.rsb >nul 2>&1 - -@$(RSCMERGE) $(BLAKSERVRUNDIR)\rsc\rsc0000.rsb $(BLAKSERVRUNDIR)\rsc + @$(RSCMERGE) $(BLAKSERVRUNDIR)\rsc\rsc0000.rsb $(BLAKSERVRUNDIR)\rsc -@$(CP) $(BLAKSERVRUNDIR)\rsc\rsc0000.rsb $(CLIENTRUNDIR)\resource\ 2>&1 clean : diff --git a/makefile.linux b/makefile.linux index b194ddc615..157a8a158a 100644 --- a/makefile.linux +++ b/makefile.linux @@ -6,37 +6,27 @@ TOPDIR=. include common.mak.linux # make ignores targets if they match directory names +.PHONY: all Bserver Bcompiler Bkod Butil Bresource clean + all: Bserver Bresource Bkod Butil Bserver: - @echo Making $(COMMAND) in $(BLAKSERVDIR); \ - cd $(BLAKSERVDIR); \ - $(MAKE) -f makefile.linux $(COMMAND); \ - cd .. + $(MAKE) -C $(BLAKSERVDIR) -f makefile.linux $(COMMAND) Bcompiler: - @echo Making $(COMMAND) in $(BLAKCOMPDIR); \ - cd $(BLAKCOMPDIR); \ - $(MAKE) -f makefile.linux $(COMMAND); \ - cd .. + $(MAKE) -C $(BLAKCOMPDIR) -f makefile.linux $(COMMAND) Bkod: Bcompiler Butil - @echo Making $(COMMAND) in $(KODDIR); \ - cd $(KODDIR); \ - $(MAKE) -f makefile.linux $(COMMAND); \ - cd .. + $(MAKE) -C $(KODDIR) -f makefile.linux $(COMMAND) Butil: - @echo Making $(COMMAND) in $(UTILDIR); \ - cd $(UTILDIR); \ - $(MAKE) -f makefile.linux $(COMMAND); \ - cd .. + $(MAKE) -C $(UTILDIR) -f makefile.linux $(COMMAND) # Copy room files to server run directory (equivalent of Windows Bresource) Bresource: @echo Copying room files to server @mkdir -p $(BLAKSERVRUNDIR)/rooms - -@$(CP) $(RESOURCEDIR)/rooms/*.roo $(BLAKSERVRUNDIR)/rooms/ 2>/dev/null + $(CP) $(RESOURCEDIR)/rooms/*.roo $(BLAKSERVRUNDIR)/rooms/ clean: env COMMAND='clean' $(MAKE) -sf makefile.linux