Build and Release Native AOT #6
This file contains hidden or 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: Build and Release Native AOT | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version tag (e.g., v1.0.0)' | |
| required: true | |
| type: string | |
| env: | |
| PROJECT_PATH: src/Aist.Cli/Aist.Cli.csproj | |
| CLI_NAME: aist | |
| jobs: | |
| build: | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| runtime: linux-x64 | |
| arch: x64 | |
| - os: ubuntu-latest | |
| runtime: linux-arm64 | |
| arch: arm64 | |
| - os: macos-latest | |
| runtime: osx-x64 | |
| arch: x64 | |
| - os: macos-latest | |
| runtime: osx-arm64 | |
| arch: arm64 | |
| - os: windows-latest | |
| runtime: win-x64 | |
| arch: x64 | |
| - os: windows-latest | |
| runtime: win-arm64 | |
| arch: arm64 | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '10.0.x' | |
| - name: Publish Native AOT | |
| shell: bash | |
| run: | | |
| PUBLISH_ARGS="" | |
| if [[ "${{ matrix.runtime }}" == "linux-arm64" ]]; then | |
| # Install specific dependencies for ARM64 cross-linking | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu zlib1g-dev:amd64 | |
| PUBLISH_ARGS="-p:CppCompilerAndLinker=clang -p:ObjCopyName=aarch64-linux-gnu-objcopy" | |
| fi | |
| dotnet publish ${{ env.PROJECT_PATH }} \ | |
| -c Release \ | |
| -r ${{ matrix.runtime }} \ | |
| -p:PublishAot=true \ | |
| -p:PublishSingleFile=true \ | |
| -p:IncludeNativeLibrariesForSelfExtract=true \ | |
| --self-contained \ | |
| -o ./publish/${{ matrix.runtime }} \ | |
| $PUBLISH_ARGS | |
| - name: Prepare artifact (Unix) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| cd ./publish/${{ matrix.runtime }} | |
| # Determine binary name: prioritize CLI_NAME, then any executable file | |
| if [ -x "${{ env.CLI_NAME }}" ]; then | |
| BINARY_NAME="${{ env.CLI_NAME }}" | |
| else | |
| # Portable way to find an executable file in the current directory | |
| BINARY_NAME=$(find . -maxdepth 1 -type f | while read -r f; do [ -x "$f" ] && echo "${f#./}" && break; done) | |
| fi | |
| if [ -z "$BINARY_NAME" ]; then | |
| echo "Error: Native binary not found in $(pwd)" | |
| ls -la | |
| exit 1 | |
| fi | |
| echo "Found binary: $BINARY_NAME" | |
| tar -czf "../../${{ env.CLI_NAME }}-${{ matrix.runtime }}.tar.gz" "$BINARY_NAME" | |
| cd ../.. | |
| echo "ARTIFACT=${{ env.CLI_NAME }}-${{ matrix.runtime }}.tar.gz" >> $GITHUB_ENV | |
| - name: Prepare artifact (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| cd ./publish/${{ matrix.runtime }} | |
| $binary = Get-ChildItem -File | Where-Object { $_.Extension -eq ".exe" } | Select-Object -First 1 | |
| if ($null -eq $binary) { | |
| Write-Error "Error: Native binary (.exe) not found in $(Get-Location)" | |
| ls -R | |
| exit 1 | |
| } | |
| Write-Host "Found binary: $($binary.Name)" | |
| Compress-Archive -Path $binary.Name -DestinationPath ../../${{ env.CLI_NAME }}-${{ matrix.runtime }}.zip | |
| cd ../.. | |
| echo "ARTIFACT=${{ env.CLI_NAME }}-${{ matrix.runtime }}.zip" >> $env:GITHUB_ENV | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.CLI_NAME }}-${{ matrix.runtime }} | |
| path: ${{ env.ARTIFACT }} | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ./artifacts | |
| pattern: ${{ env.CLI_NAME }}-* | |
| merge-multiple: true | |
| - name: Get version | |
| id: get_version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| else | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Version: $VERSION" | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.VERSION }} | |
| name: Release ${{ steps.get_version.outputs.VERSION }} | |
| draft: false | |
| prerelease: ${{ contains(steps.get_version.outputs.VERSION, 'alpha') || contains(steps.get_version.outputs.VERSION, 'beta') || contains(steps.get_version.outputs.VERSION, 'rc') }} | |
| files: ./artifacts/* | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |