Release #96
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
workflow_dispatch: | |
inputs: | |
new_engine_version: | |
description: 'New engine version. If empty, run number will be used and no commit/tag/release will be created' | |
default: '' | |
required: false | |
should_push_new_nuget_version: | |
description: 'Push new NuGet version' | |
type: boolean | |
default: true | |
required: false | |
should_commit_new_version: | |
description: 'Commit and push version increment. If true, this new commit will be the one tagged (in case Tag version release is also set to true)' | |
type: boolean | |
default: true | |
required: false | |
should_tag_new_version: | |
description: 'Tag version release. If false, no release will be created either' | |
type: boolean | |
default: true | |
required: false | |
should_create_github_release: | |
description: 'Create GitHub Release' | |
type: boolean | |
default: true | |
required: false | |
env: | |
DOTNET_VERSION: 8.0.x | |
DOTNET_CLI_TELEMETRY_OPTOUT: 1 | |
jobs: | |
publish-artifacts: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
runtime-identifier: [win-x64, win-arm64, linux-x64, linux-arm64, linux-arm, linux-musl-x64, osx-x64, osx-arm64] | |
include: | |
- runtime-identifier: win-x64 | |
os: windows-latest | |
- runtime-identifier: win-arm64 | |
os: windows-latest | |
- runtime-identifier: linux-x64 | |
os: ubuntu-latest | |
- runtime-identifier: linux-arm64 | |
os: ubuntu-latest | |
- runtime-identifier: linux-arm | |
os: ubuntu-latest | |
- runtime-identifier: linux-musl-x64 | |
os: ubuntu-latest | |
- runtime-identifier: osx-x64 | |
os: macos-13 | |
- runtime-identifier: osx-arm64 | |
os: macos-latest | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Inject slug/short variables | |
uses: rlespinasse/[email protected] | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ env.DOTNET_VERSION }} | |
- name: Nuget cache | |
uses: actions/cache@v4 | |
with: | |
path: | |
~/.nuget/packages | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-nuget- | |
- name: Set version to ${{ github.event.inputs.new_engine_version }} | |
shell: pwsh | |
run: | | |
$input_path = "Directory.Build.props" | |
$regex = "(?<=<Version>).*(?=</Version>)" | |
(Get-Content $input_path) -Replace $regex, '${{ github.event.inputs.new_engine_version }}' | Out-File $input_path | |
- name: Publish ${{ matrix.runtime-identifier }} version | |
run: dotnet publish src/Lynx.Cli/Lynx.Cli.csproj -c Release --runtime ${{ matrix.runtime-identifier }} --self-contained /p:Optimized=true /p:DeterministicBuild=true -o artifacts/${{ matrix.runtime-identifier }} | |
- name: Upload Lynx-${{ matrix.runtime-identifier }} artifact | |
if: github.event.inputs.new_engine_version != '' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Lynx-${{ github.event.inputs.new_engine_version }}-${{ matrix.runtime-identifier }} | |
path: | | |
artifacts/${{ matrix.runtime-identifier }}/ | |
!artifacts/**/*.pdb | |
if-no-files-found: error | |
- name: Upload Lynx-${{ env.GITHUB_REF_SLUG }}-${{ github.run_number }}-${{ matrix.runtime-identifier }} artifact | |
if: github.event.inputs.new_engine_version == '' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Lynx-${{ env.GITHUB_REF_SLUG }}-${{ github.run_number }}-${{ matrix.runtime-identifier }} | |
path: | | |
artifacts/${{ matrix.runtime-identifier }}/ | |
!artifacts/**/*.pdb | |
if-no-files-found: error | |
- name: Deterministic build | |
if: matrix.runtime-identifier == 'linux-x64' | |
run: dotnet clean -c Release && dotnet build -c Release /p:DeterministicBuild=true | |
- name: Pack NuGet package | |
if: matrix.runtime-identifier == 'linux-x64' | |
run: dotnet pack -c Release --no-build src/Lynx/Lynx.csproj --include-symbols -o artifacts/nuget | |
- name: Upload Lynx-${{ env.GITHUB_REF_SLUG }}-${{ github.run_number }} NuGet package | |
if: matrix.runtime-identifier == 'linux-x64' && github.event.inputs.new_engine_version != '' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Lynx-${{ github.event.inputs.new_engine_version }}-nuget | |
path: | | |
artifacts/nuget/*.nupkg | |
artifacts/nuget/*.snupkg | |
if-no-files-found: error | |
- name: Upload Lynx-${{ env.GITHUB_REF_SLUG }}-${{ github.run_number }} NuGet package | |
if: matrix.runtime-identifier == 'linux-x64' && github.event.inputs.new_engine_version == '' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Lynx-${{ env.GITHUB_REF_SLUG }}-${{ github.run_number }}-nuget | |
path: | | |
artifacts/nuget/*.nupkg | |
artifacts/nuget/*.snupkg | |
if-no-files-found: error | |
release: | |
needs: publish-artifacts | |
if: github.event.inputs.new_engine_version != '' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install hub tool | |
if: github.event.inputs.should_create_github_release == 'true' | |
run: | | |
sudo apt-get update && sudo apt-get install -y hub | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_RELEASE }} | |
- name: Configure git user | |
run: | | |
git config --global user.name 'GitHub Actions' | |
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
- name: Inject slug/short variables | |
uses: rlespinasse/[email protected] | |
- name: Set version to ${{ github.event.inputs.new_engine_version }} | |
shell: pwsh | |
run: | | |
$input_path = "Directory.Build.props" | |
$regex = "(?<=<Version>).*(?=</Version>)" | |
(Get-Content $input_path) -Replace $regex, '${{ github.event.inputs.new_engine_version }}' | Out-File $input_path | |
- name: Commit and push version increment | |
if: github.event.inputs.should_commit_new_version == 'true' | |
continue-on-error: true | |
run: | | |
git switch ${{ env.GITHUB_REF_NAME }} | |
git status | |
git commit -am "π Release v${{ github.event.inputs.new_engine_version }}" | |
git push | |
- name: Create git tag | |
if: github.event.inputs.should_tag_new_version == 'true' | |
run: | | |
git switch ${{ env.GITHUB_REF_NAME }} | |
git status | |
git tag -a v${{ github.event.inputs.new_engine_version }} -m "v${{ github.event.inputs.new_engine_version }}" | |
git push --tags | |
- uses: actions/download-artifact@v4 | |
with: | |
path: artifacts/ | |
- name: Push NuGet package to nuget.org | |
if: github.event.inputs.should_push_new_nuget_version == 'true' | |
run: nuget push 'artifacts/Lynx-${{ github.event.inputs.new_engine_version }}-nuget/*.nupkg' -ApiKey ${{ secrets.NUGET_APIKEY }} -Source https://api.nuget.org/v3/index.json -SkipDuplicate -Verbosity detailed | |
- name: Push NuGet package to GitHub | |
if: github.event.inputs.should_push_new_nuget_version == 'true' | |
run: nuget push 'artifacts/Lynx-${{ github.event.inputs.new_engine_version }}-nuget/*.nupkg' -ApiKey ${{ secrets.GITHUB_TOKEN }} -Source https://nuget.pkg.github.com/lynx-chess/index.json -SkipDuplicate -Verbosity detailed | |
- name: Compress artifacts again | |
if: github.event.inputs.should_create_github_release == 'true' && github.event.inputs.should_tag_new_version == 'true' | |
run: for i in artifacts/*[!-nuget]; do zip -0 -r -q -j "${i%/}.zip" "$i" & done; wait | |
- name: Create GitHub release and upload assets | |
if: github.event.inputs.should_create_github_release == 'true' && github.event.inputs.should_tag_new_version == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
set -x | |
assets=() | |
for asset in artifacts/*.zip; do | |
assets+=("-a" "$asset") | |
done | |
for asset in artifacts/Lynx-${{ github.event.inputs.new_engine_version }}-nuget/*; do | |
assets+=("-a" "$asset") | |
done | |
tag_name="v${{ github.event.inputs.new_engine_version }}" | |
hub release create "${assets[@]}" --draft --message "$tag_name" "$tag_name" |