diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f937e36 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,92 @@ +name: Build CMake Project +on: + workflow_call: + secrets: + SSH_KEY: + required: false + description: SSH private key for pushing version changes + inputs: + cmake-preset: + required: true + type: string + upload-artifact-dll: + 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 + push-version-commit: + required: false + type: boolean + default: false + push-version-branch: + required: false + type: string + default: main +jobs: + build: + name: MSVC / Windows 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 + - uses: actions/checkout@v4 + with: + submodules: recursive + persist-credentials: false + - name: Set project version + if: ${{ inputs.project-version != 'false' }} + run: powershell ./set-version.ps1 ${{ inputs.project-version }} + - name: Setup token for branch rules bypass + uses: webfactory/ssh-agent@v0.9.0 + if: ${{ inputs.push-version-commit == true }} + with: + ssh-private-key: ${{ secrets.SSH_KEY }} + - name: Commit version change + if: ${{ inputs.push-version-commit == true }} + run: | + New-Item -ItemType Directory -Force -Path ~/.ssh + ssh-keyscan github.com >> ~/.ssh/known_hosts + git config --global user.name "Nekobot" + git config --global user.email "nekobot-service.noreply@silveroreteam.pl" + git remote set-url origin git@github.com:Silver-Ore-Team/zMultilogue.git + git fetch --all + git checkout ${{ inputs.push-version-branch }} + $changes = $(git status -s) + if ($changes) { + git add CMakeLists.txt + git commit -m "[skip ci] set project version to ${{ inputs.project-version }}" + git push origin ${{ inputs.push-version-branch }} + } else { + echo "No changes to commit" + } + - 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 \ 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..e480b5f --- /dev/null +++ b/.github/workflows/on-push.yml @@ -0,0 +1,24 @@ +name: On Push +permissions: write-all +on: + pull_request: + branches: [ "main", "dev" ] + push: + branches: [ "main", "dev", "gh_actions", "ci" ] + paths-ignore: + - 'README.md' + - 'docs/**' +jobs: +# build-debug: +# name: Build Debug +# uses: ./.github/workflows/build.yml +# with: +# cmake-preset: x86-debug +# upload-artifact-dll: debug-dll +# upload-artifact-vdf: debug-vdf + build-release: + name: Build Release + uses: ./.github/workflows/build.yml + with: + cmake-preset: x86-release + upload-artifact-dll: release-dll \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..79214bd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +name: Release +permissions: write-all +on: + push: + tags: + - 'v*' +jobs: + build-release: + name: Build Release + uses: ./.github/workflows/build.yml + secrets: + SSH_KEY: ${{ secrets.NEKOBOCIK_SSH_KEY }} + with: + cmake-preset: x86-release + upload-artifact-dll: release-dll + upload-artifact-vdf: release-vdf + project-version: ${{ github.ref_name }} + push-version-commit: true + publish: + name: Publish Release + runs-on: windows-2022 + needs: + - build-release + steps: + - name: Download Release DLL + uses: actions/download-artifact@v4 + with: + name: release-dll + path: out/install/x86-release/bin/ + - name: Prepare Release Files + id: prepare-release + shell: powershell + env: + GITHUB_REF: ${{ github.ref_name }} + run: | + $tag = $env:GITHUB_REF -replace '^refs/tags/', '' + Compress-Archive out/install/x86-release/bin/* zMultilogue-${tag}.zip + $prerelease = if (-not ($tag -match '^v?(\d+\.\d+\.\d+)$')) { 'true' } else { 'false' } + echo "prerelease=${prerelease}" >> $env:GITHUB_OUTPUT + - name: Release + uses: softprops/action-gh-release@v2 + with: + token: ${{ github.token }} + generate_release_notes: true + fail_on_unmatched_files: true + draft: true + prerelease: ${{ steps.prepare-release.outputs.prerelease }} + files: | + zMultilogue-*.zip \ No newline at end of file diff --git a/set-version.ps1 b/set-version.ps1 new file mode 100644 index 0000000..a02eb6f --- /dev/null +++ b/set-version.ps1 @@ -0,0 +1,33 @@ +$version = $args[0] + +if ($version -match 'rollback') { + if (Test-Path ./CMakeLists.txt.bak -PathType Leaf) { + Remove-Item CMakeLists.txt -Force + Move-Item CMakeLists.txt.bak CMakeLists.txt + Write-Host "CMakeLists.txt.bak does not exist. Cannot rollback." + } else { + Write-Host "CMakeLists.txt.bak does not exist. Cannot rollback." + exit 2 + } + exit 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]" + exit 1 +} + +if (Test-Path ./CMakeLists.txt.bak -PathType Leaf) { + Write-Host "CMakeLists.txt.bak exists. Delete this file to set new version." + exit 3 +} + +$version = $version -replace '^v', '' +$cmakeVersion = $version -replace '-[a-z0-9]+$', '' +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 = (Get-Content -Path ./CMakeLists.txt) -replace 'set\(PROJECT_VERSION_CMAKE "[^"]*"\)', "set(PROJECT_VERSION_CMAKE ""$cmakeVersion"")" +$cmake | Set-Content -Path ./CMakeLists.txt \ No newline at end of file