|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - ".github/workflows/release.yml" |
| 7 | + - "CMakeLists.txt" |
| 8 | + - "cmake/**" |
| 9 | + - "package.json" |
| 10 | + - "package-lock.json" |
| 11 | + - "src/**" |
| 12 | + - "third-party/**" |
| 13 | + push: |
| 14 | + tags: |
| 15 | + - "v*" |
| 16 | + workflow_dispatch: |
| 17 | + inputs: |
| 18 | + release_tag: |
| 19 | + description: "Release tag to publish, for example v0.4.9" |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + draft: |
| 23 | + description: "Create the GitHub Release as a draft" |
| 24 | + required: true |
| 25 | + default: true |
| 26 | + type: boolean |
| 27 | + prerelease: |
| 28 | + description: "Mark the GitHub Release as a pre-release" |
| 29 | + required: true |
| 30 | + default: false |
| 31 | + type: boolean |
| 32 | + create_release: |
| 33 | + description: "Create or update the GitHub Release after building" |
| 34 | + required: true |
| 35 | + default: true |
| 36 | + type: boolean |
| 37 | + |
| 38 | +permissions: |
| 39 | + contents: write |
| 40 | + |
| 41 | +concurrency: |
| 42 | + group: release-${{ github.ref }} |
| 43 | + cancel-in-progress: false |
| 44 | + |
| 45 | +env: |
| 46 | + BUILD_TYPE: Release |
| 47 | + |
| 48 | +jobs: |
| 49 | + windows: |
| 50 | + name: Windows installer |
| 51 | + runs-on: windows-latest |
| 52 | + |
| 53 | + steps: |
| 54 | + - name: Checkout |
| 55 | + uses: actions/checkout@v4 |
| 56 | + with: |
| 57 | + fetch-depth: 0 |
| 58 | + submodules: recursive |
| 59 | + |
| 60 | + - name: Resolve build metadata |
| 61 | + id: metadata |
| 62 | + shell: pwsh |
| 63 | + env: |
| 64 | + INPUT_RELEASE_TAG: ${{ inputs.release_tag }} |
| 65 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 66 | + run: | |
| 67 | + if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') { |
| 68 | + $releaseTag = $env:INPUT_RELEASE_TAG |
| 69 | + $packageVersion = $releaseTag |
| 70 | + $artifactSuffix = $releaseTag |
| 71 | + } elseif ($env:GITHUB_REF_TYPE -eq 'tag') { |
| 72 | + $releaseTag = $env:GITHUB_REF_NAME |
| 73 | + $packageVersion = $releaseTag |
| 74 | + $artifactSuffix = $releaseTag |
| 75 | + } else { |
| 76 | + $releaseTag = "pr-$env:PR_NUMBER" |
| 77 | + $packageVersion = "v0.0.$env:GITHUB_RUN_NUMBER" |
| 78 | + $artifactSuffix = $releaseTag |
| 79 | + } |
| 80 | +
|
| 81 | + $artifactSuffix = $artifactSuffix -replace '[^A-Za-z0-9._-]', '-' |
| 82 | +
|
| 83 | + "release_tag=$releaseTag" >> $env:GITHUB_OUTPUT |
| 84 | + "package_version=$packageVersion" >> $env:GITHUB_OUTPUT |
| 85 | + "artifact_suffix=$artifactSuffix" >> $env:GITHUB_OUTPUT |
| 86 | + "RELEASE_TAG=$releaseTag" >> $env:GITHUB_ENV |
| 87 | + "PACKAGE_VERSION=$packageVersion" >> $env:GITHUB_ENV |
| 88 | + "ARTIFACT_SUFFIX=$artifactSuffix" >> $env:GITHUB_ENV |
| 89 | +
|
| 90 | + - name: Set up Node.js |
| 91 | + uses: actions/setup-node@v4 |
| 92 | + with: |
| 93 | + node-version: "lts/*" |
| 94 | + |
| 95 | + - name: Set up MSYS2 |
| 96 | + uses: msys2/setup-msys2@v2 |
| 97 | + with: |
| 98 | + msystem: UCRT64 |
| 99 | + path-type: inherit |
| 100 | + update: true |
| 101 | + install: >- |
| 102 | + git |
| 103 | + mingw-w64-ucrt-x86_64-boost |
| 104 | + mingw-w64-ucrt-x86_64-cmake |
| 105 | + mingw-w64-ucrt-x86_64-cppwinrt |
| 106 | + mingw-w64-ucrt-x86_64-curl-winssl |
| 107 | + mingw-w64-ucrt-x86_64-MinHook |
| 108 | + mingw-w64-ucrt-x86_64-miniupnpc |
| 109 | + mingw-w64-ucrt-x86_64-ninja |
| 110 | + mingw-w64-ucrt-x86_64-nsis |
| 111 | + mingw-w64-ucrt-x86_64-onevpl |
| 112 | + mingw-w64-ucrt-x86_64-openssl |
| 113 | + mingw-w64-ucrt-x86_64-opus |
| 114 | + mingw-w64-ucrt-x86_64-pkgconf |
| 115 | + mingw-w64-ucrt-x86_64-toolchain |
| 116 | + mingw-w64-ucrt-x86_64-nlohmann_json |
| 117 | +
|
| 118 | + - name: Verify toolchain |
| 119 | + shell: msys2 {0} |
| 120 | + run: | |
| 121 | + cmake --version |
| 122 | + ninja --version |
| 123 | + npm --version |
| 124 | +
|
| 125 | + - name: Configure |
| 126 | + shell: msys2 {0} |
| 127 | + env: |
| 128 | + BRANCH: ${{ github.ref_name }} |
| 129 | + BUILD_VERSION: ${{ steps.metadata.outputs.package_version }} |
| 130 | + CLONE_URL: ${{ github.server_url }}/${{ github.repository }} |
| 131 | + COMMIT: ${{ github.sha }} |
| 132 | + TAG: ${{ steps.metadata.outputs.release_tag }} |
| 133 | + run: | |
| 134 | + cmake -B build -G Ninja -S . -DCMAKE_BUILD_TYPE=${BUILD_TYPE} |
| 135 | +
|
| 136 | + - name: Build |
| 137 | + shell: msys2 {0} |
| 138 | + run: | |
| 139 | + cmake --build build --config ${BUILD_TYPE} |
| 140 | +
|
| 141 | + - name: Package installer |
| 142 | + shell: msys2 {0} |
| 143 | + run: | |
| 144 | + cpack -G NSIS --config ./build/CPackConfig.cmake |
| 145 | +
|
| 146 | + - name: Collect installer |
| 147 | + id: collect |
| 148 | + shell: pwsh |
| 149 | + run: | |
| 150 | + $version = $env:ARTIFACT_SUFFIX -replace '^v', '' |
| 151 | + New-Item -ItemType Directory -Force -Path dist | Out-Null |
| 152 | +
|
| 153 | + $installer = Get-ChildItem -Path build -Recurse -Filter '*.exe' | |
| 154 | + Where-Object { $_.FullName -match 'cpack_artifacts|_CPack_Packages' } | |
| 155 | + Sort-Object LastWriteTime -Descending | |
| 156 | + Select-Object -First 1 |
| 157 | +
|
| 158 | + if (-not $installer) { |
| 159 | + throw 'No NSIS installer was produced by CPack.' |
| 160 | + } |
| 161 | +
|
| 162 | + $assetPath = "dist/Apollo-$version.exe" |
| 163 | + Copy-Item -LiteralPath $installer.FullName -Destination $assetPath -Force |
| 164 | + "asset_path=$assetPath" >> $env:GITHUB_OUTPUT |
| 165 | +
|
| 166 | + - name: Upload installer artifact |
| 167 | + uses: actions/upload-artifact@v4 |
| 168 | + with: |
| 169 | + name: Apollo-${{ steps.metadata.outputs.artifact_suffix }}-windows-installer |
| 170 | + path: ${{ steps.collect.outputs.asset_path }} |
| 171 | + if-no-files-found: error |
| 172 | + |
| 173 | + - name: Create GitHub Release |
| 174 | + if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.create_release) |
| 175 | + shell: pwsh |
| 176 | + env: |
| 177 | + GH_TOKEN: ${{ github.token }} |
| 178 | + RELEASE_TAG: ${{ steps.metadata.outputs.release_tag }} |
| 179 | + DRAFT: ${{ github.event_name == 'workflow_dispatch' && inputs.draft || false }} |
| 180 | + PRERELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.prerelease || contains(steps.metadata.outputs.release_tag, '-') }} |
| 181 | + ASSET_PATH: ${{ steps.collect.outputs.asset_path }} |
| 182 | + run: | |
| 183 | + gh release view $env:RELEASE_TAG --repo $env:GITHUB_REPOSITORY *> $null |
| 184 | + $releaseExists = $LASTEXITCODE -eq 0 |
| 185 | +
|
| 186 | + if ($releaseExists) { |
| 187 | + $editArgs = @( |
| 188 | + 'release', 'edit', $env:RELEASE_TAG, |
| 189 | + '--repo', $env:GITHUB_REPOSITORY, |
| 190 | + '--title', $env:RELEASE_TAG, |
| 191 | + "--draft=$($env:DRAFT.ToLowerInvariant())", |
| 192 | + "--prerelease=$($env:PRERELEASE.ToLowerInvariant())" |
| 193 | + ) |
| 194 | +
|
| 195 | + gh @editArgs |
| 196 | + gh release upload $env:RELEASE_TAG $env:ASSET_PATH --repo $env:GITHUB_REPOSITORY --clobber |
| 197 | + } else { |
| 198 | + $createArgs = @( |
| 199 | + 'release', 'create', $env:RELEASE_TAG, |
| 200 | + $env:ASSET_PATH, |
| 201 | + '--repo', $env:GITHUB_REPOSITORY, |
| 202 | + '--title', $env:RELEASE_TAG, |
| 203 | + '--target', $env:GITHUB_SHA, |
| 204 | + '--generate-notes' |
| 205 | + ) |
| 206 | +
|
| 207 | + if ($env:DRAFT -eq 'true') { |
| 208 | + $createArgs += '--draft' |
| 209 | + } |
| 210 | +
|
| 211 | + if ($env:PRERELEASE -eq 'true') { |
| 212 | + $createArgs += '--prerelease' |
| 213 | + } |
| 214 | +
|
| 215 | + gh @createArgs |
| 216 | + } |
0 commit comments