From 12cd40ff93afc28e976b97ed2a68b752e3c1952f Mon Sep 17 00:00:00 2001 From: Piotr Macha Date: Sat, 18 May 2024 21:11:41 +0200 Subject: [PATCH] CI: Improve build pipeline --- .github/workflows/build.yml | 73 +++++++++++++++++ .github/workflows/cmake-build.yml | 46 ----------- .github/workflows/cmake-release.yml | 108 ------------------------- .github/workflows/on-push.yml | 32 ++++++++ .github/workflows/release.yml | 120 ++++++++++++++++++++++++++++ CMakeLists.txt | 13 +-- CMakePresets.json | 84 ++++++++++--------- set-version.ps1 | 14 ++++ 8 files changed, 293 insertions(+), 197 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/cmake-build.yml delete mode 100644 .github/workflows/cmake-release.yml create mode 100644 .github/workflows/on-push.yml create mode 100644 .github/workflows/release.yml create mode 100644 set-version.ps1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1123c86 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,73 @@ +name: Build CMake Project + +on: + workflow_call: + inputs: + cmake-preset: + required: true + type: string + upload-artifact-dll: + required: false + type: string + default: false + upload-artifact-dll-pdb: + required: false + type: string + default: false + upload-artifact-vdf: + required: false + type: string + default: false + msvc-toolkit: + required: false + type: string + default: 14.39 + project-version: + required: false + type: string + default: false + +jobs: + build: + name: MSVC on VS 2022 + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: TheMrMilchmann/setup-msvc-dev@v3 + with: + arch: x86 + toolset: ${{ inputs.msvc-toolkit }} + export-path-to-vcvarsall: VCVARSALL + - name: CMake Setup + uses: lukka/get-cmake@latest + - name: Set proejct version + if: ${{ inputs.project-version != 'false' }} + run: ./set-project-version.sh ${{ inputs.project-version }} + - name: CMake Configure + run: cmake --preset ${{ inputs.cmake-preset }} + - name: Ninja Build + run: ninja -C out/build/${{ inputs.cmake-preset }} -j 20 + - name: CMake Install + run: cmake --install out/build/${{ inputs.cmake-preset }} --prefix out/install/${{ inputs.cmake-preset }} + - name: Archive DLL + if: ${{ inputs.upload-artifact-dll != 'false' }} + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.upload-artifact-dll }} + path: out/install/${{ inputs.cmake-preset }}/bin/*.dll + - name: Archive DLL PDB + uses: actions/upload-artifact@v4 + if: ${{ inputs.upload-artifact-dll-pdb != 'false' }} + with: + name: ${{ inputs.upload-artifact-dll-pdb }} + path: | + out/build/${{ inputs.cmake-preset }}/*.dll + out/build/${{ inputs.cmake-preset }}/*.pdb + - name: Archive VDF + uses: actions/upload-artifact@v4 + if: ${{ inputs.upload-artifact-vdf != 'false' }} + with: + name: ${{ inputs.upload-artifact-vdf }} + path: out/install/${{ inputs.cmake-preset }}/*.vdf \ No newline at end of file diff --git a/.github/workflows/cmake-build.yml b/.github/workflows/cmake-build.yml deleted file mode 100644 index 22b6cc2..0000000 --- a/.github/workflows/cmake-build.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: CMake Build -on: - push: - branches: ["main", "dev"] - paths-ignore: - - 'README.md' - - 'docs/**' -permissions: write-all -jobs: - build: - name: Build Visual Studio 2022 - runs-on: windows-2022 - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - uses: TheMrMilchmann/setup-msvc-dev@v2 - with: - arch: x86 - toolset: 14.39 - export-path-to-vcvarsall: VCVARSALL - - name: CMake Setup - uses: lukka/get-cmake@latest - - name: CMake Configure - run: 'cmake --preset x86-release' - - name: Ninja Build - run: ninja -C out/build/x86-release -j 20 - - name: CMake Install - run: cmake --install out/build/x86-release --prefix out/install/x86-release - - name: Archive DLL - uses: actions/upload-artifact@v4 - with: - name: dll-release - path: out/install/x86-release/bin/*.dll - - name: Archive DLL PDB - uses: actions/upload-artifact@v4 - with: - name: dll-pdb-release - path: | - out/install/x86-release/bin/*.dll - out/build/x86-release/*.pdb - - name: Archive VDF - uses: actions/upload-artifact@v4 - with: - name: vdf-release - path: out/install/x86-release/*.vdf \ No newline at end of file diff --git a/.github/workflows/cmake-release.yml b/.github/workflows/cmake-release.yml deleted file mode 100644 index 0d8b541..0000000 --- a/.github/workflows/cmake-release.yml +++ /dev/null @@ -1,108 +0,0 @@ -name: CMake Build -on: - push: - tags: - - 'v*' -permissions: write-all -jobs: - build: - name: Build Visual Studio 2022 - runs-on: windows-2022 - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - uses: TheMrMilchmann/setup-msvc-dev@v2 - with: - arch: x86 - toolset: 14.39 - export-path-to-vcvarsall: VCVARSALL - - name: CMake Setup - uses: lukka/get-cmake@latest - - name: CMake Configure - run: 'cmake --preset x86-release' - - name: Ninja Build - run: ninja -C out/build/x86-release -j 20 - - name: CMake Install - run: cmake --install out/build/x86-release --prefix out/install/x86-release - - name: Archive DLL - uses: actions/upload-artifact@v4 - with: - name: dll-release - path: out/install/x86-release/bin/*.dll - - name: Archive DLL PDB - uses: actions/upload-artifact@v4 - with: - name: dll-pdb-release - path: | - out/install/x86-release/bin/*.dll - out/build/x86-release/*.pdb - - name: Archive VDF - uses: actions/upload-artifact@v4 - with: - name: vdf-release - path: out/install/x86-release/*.vdf - release: - name: Release tag - runs-on: windows-2022 - needs: - - build - steps: - - name: Download DLL - uses: actions/download-artifact@v4 - with: - name: dll-release - path: out/install/x86-release/bin/ - - name: Download DLL PDB - uses: actions/download-artifact@v4 - with: - name: dll-pdb-release - path: out/build/x86-release/ - - name: Download VDF - uses: actions/download-artifact@v4 - with: - name: vdf-release - path: out/install/x86-release/ - - name: Zip dll-release - run: Compress-Archive out/install/x86-release/bin/* dll-release.zip - - name: Copy PDB - run: Copy-Item out/build/x86-release/*.pdb out/install/x86-release/bin/ - - name: Zip dll-pdb-release - run: Compress-Archive out/install/x86-release/bin/* dll-pdb-release.zip - - name: Create Release - id: create_release - uses: actions/create-release@latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag_name: ${{ github.ref_name }} - release_name: ${{ github.ref_name }} - draft: false - prerelease: false - - name: Upload Release ZIP - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dll-release.zip - asset_name: zBassMusic.zip - asset_content_type: application/zip - - name: Upload Release ZIP with PDB - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dll-pdb-release.zip - asset_name: zBassMusic-PDB.zip - asset_content_type: application/zip - - name: Upload Release VDF - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: out/install/x86-release/zBassMusic.vdf - asset_name: zBassMusic.vdf - asset_content_type: application/octet-stream \ No newline at end of file diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml new file mode 100644 index 0000000..ec933e5 --- /dev/null +++ b/.github/workflows/on-push.yml @@ -0,0 +1,32 @@ +name: On Push +permissions: write-all + +on: + push: + branches: [ "main", "dev", "gh_actions" ] + paths-ignore: + - 'README.md' + - 'docs/**' + +jobs: + build-debug: + uses: ./.github/workflows/build.yml + with: + cmake-preset: x86-debug + upload-artifact-dll: debug-dll + upload-artifact-dll-pdb: debug-dll-pdb + upload-artifact-vdf: debug-vdf + + build-release: + uses: ./.github/workflows/build.yml + with: + cmake-preset: x86-release + upload-artifact-dll: release-dll + upload-artifact-vdf: release-vdf + + build-release-pdb: + uses: ./.github/workflows/build.yml + with: + cmake-preset: x86-release-pdb + upload-artifact-dll-pdb: release-dll-pdb + upload-artifact-vdf: release-vdf-pdb \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3a32167 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,120 @@ +name: Release +permissions: write-all + +on: + push: + tags: + - 'v*' + +jobs: + build-release: + uses: ./.github/workflows/build.yml + with: + cmake-preset: x86-release + upload-artifact-dll: release-dll + upload-artifact-vdf: release-vdf + project-version: ${{ github.ref_name }} + + build-release-pdb: + uses: ./.github/workflows/build.yml + with: + cmake-preset: x86-release-pdb + upload-artifact-dll: release-dll-pdb + upload-artifact-vdf: release-vdf-pdb + project-version: ${{ github.ref_name }}-pdb + + publish: + name: Publish new release + runs-on: windows-2022 + needs: + - build-release + - build-release-pdb + steps: + - name: Download Release DLL + uses: actions/download-artifact@v4 + with: + name: release-dll + path: out/install/x86-release/bin/ + - name: Download Release VDF + uses: actions/download-artifact@v4 + with: + name: release-vdf + path: out/install/x86-release/ + - name: Download Release DLL PDB + uses: actions/download-artifact@v4 + with: + name: release-dll-pdb + path: out/build/x86-release-pdb/ + - name: Download Release DLL VDF + uses: actions/download-artifact@v4 + with: + name: release-vdf-pdb + path: out/install/x86-release-pdb/ + - name: Pack Release DLL + run: Compress-Archive out/install/x86-release/bin/* release-dll.zip + - name: Pack Release DLL PDB + run: Compress-Archive out/build/x86-release-pdb/* release-dll-pdb.zip + - name: Create release + uses: actions/github-script@v6.3.3 + env: + RELEASE_TAG: ${{ github.ref_name }} + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + script: | + if (!process.env.RELEASE_TAG) { + core.setFailed("The environment variable RELEASE_TAG is not defined.") + return; + } + + try { + const response = await github.rest.repos.createRelease({ + draft: process.env.RELEASE_TAG.match(/^\d+\.\d+\.\d+-[a-z0-9-]+$/i) !== null, + generate_release_notes: true, + name: process.env.RELEASE_TAG, + owner: context.repo.owner, + prerelease: process.env.RELEASE_TAG.match(/^\d+\.\d+\.\d+-[a-z0-9-]+$/i) !== null, + repo: context.repo.repo, + tag_name: process.env.RELEASE_TAG, + }); + + core.exportVariable('RELEASE_ID', response.data.id); + core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url); + } catch (error) { + core.setFailed(error.message); + } + - name: Upload Release DLL + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.RELEASE_UPLOAD_URL }} + asset_path: release-dll.zip + asset_name: zBassMusic-${{ github.ref_name }}.zip + asset_content_type: application/zip + - name: Upload Release VDF + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.RELEASE_UPLOAD_URL }} + asset_path: out/install/x86-release/zBassMusic.vdf + asset_name: zBassMusic-${{ github.ref_name }}.vdf + asset_content_type: application/octet-stream + - name: Upload Release DLL PDB + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.RELEASE_UPLOAD_URL }} + asset_path: release-dll-pdb.zip + asset_name: zBassMusic-${{ github.ref_name }}-pdb.zip + asset_content_type: application/zip + - name: Upload Release VDF PDB + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.RELEASE_UPLOAD_URL }} + asset_path: out/install/x86-release-pdb/zBassMusic.vdf + asset_name: zBassMusic-${{ github.ref_name }}-pdb.vdf + asset_content_type: application/octet-stream \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 83f661b..2a943fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,21 @@ cmake_minimum_required(VERSION 3.25) -project(zBassMusic VERSION "0.1.2") +set(PROJECT_VERSION "0.1.2") +project(zBassMusic VERSION ${PROJECT_VERSION}) option(BUILD_VDF "Build .VDF file with plugin" ON) -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") -set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") - set(UNION_API_DIR "${CMAKE_SOURCE_DIR}/dependencies/union-api") set(GOTHIC_API_DIR "${CMAKE_SOURCE_DIR}/dependencies/gothic-api") set(BASS_DIR "${CMAKE_SOURCE_DIR}/dependencies/bass") set(VDF_DIR "${CMAKE_SOURCE_DIR}/vdf") set(GOTHIC_USERAPI_DIR "${CMAKE_SOURCE_DIR}/gothic-userapi") +set(CMAKE_CXX_STANDARD 23) +if(${CMAKE_BUILD_RELEASE_PDB}) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") +endif() + include(cmake/union-api.cmake) include(cmake/gothic-api.cmake) include(cmake/bass.cmake) diff --git a/CMakePresets.json b/CMakePresets.json index 47d782c..cba6575 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,41 +1,49 @@ { "version": 3, - "configurePresets": [ - { - "name": "windows-base", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/out/build/${presetName}", - "installDir": "${sourceDir}/out/install/${presetName}", - "cacheVariables": { - "CMAKE_C_COMPILER": "cl.exe", - "CMAKE_CXX_COMPILER": "cl.exe" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - }, - { - "name": "x86-debug", - "displayName": "x86 Debug", - "inherits": "windows-base", - "architecture": { - "value": "x86", - "strategy": "external" - }, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "x86-release", - "displayName": "x86 Release", - "inherits": "x86-debug", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - } - ] + "configurePresets": [ + { + "name": "windows-base", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl.exe", + "CMAKE_CXX_COMPILER": "cl.exe" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "x86-debug", + "displayName": "x86 Debug", + "inherits": "windows-base", + "architecture": { + "value": "x86", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x86-release", + "displayName": "x86 Release", + "inherits": "x86-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "x86-release-pdb", + "displayName": "x86 Release (Debug Symbols)", + "inherits": "x86-release", + "cacheVariables": { + "CMAKE_BUILD_RELEASE_PDB": "yes" + } + } + ] } diff --git a/set-version.ps1 b/set-version.ps1 new file mode 100644 index 0000000..0c060ab --- /dev/null +++ b/set-version.ps1 @@ -0,0 +1,14 @@ +$version = $args[0] + +if (-not ($version -match 'v?(\d+\.\d+\.\d+)(-[a-z0-9-]+[^-])?')) { + Write-Host "Version must follow format: 1.2.3 or v1.2.3 or 1.2.3-alpha" + Write-Host "Usage: set-version.ps1 [version]" + return +} + +$version = $version -replace '^v', '' +Write-Host "Setting version to $version" + +Copy-Item CMakeLists.txt CMakeLists.txt.bak +$cmake = (Get-Content -Path ./CMakeLists.txt) -replace 'set\(PROJECT_VERSION "[^"]*"\)', "set(PROJECT_VERSION ""$version"")" +$cmake | Set-Content -Path ./CMakeLists.txt \ No newline at end of file