Build and Release #12
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 | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to build (e.g. 1.1.0)' | |
| required: true | |
| type: string | |
| arch: | |
| description: 'Architecture to build for' | |
| required: true | |
| default: 'All' | |
| type: choice | |
| options: | |
| - All | |
| - amd64 | |
| - aarch64 | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| setup: | |
| name: Setup Build Matrix | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Set matrix | |
| id: set-matrix | |
| run: | | |
| if [ "${{ github.event.inputs.arch }}" == "All" ]; then | |
| echo 'matrix=["amd64", "aarch64"]' >> $GITHUB_OUTPUT | |
| else | |
| echo 'matrix=["${{ github.event.inputs.arch }}"]' >> $GITHUB_OUTPUT | |
| fi | |
| notify_workflow: | |
| name: Notify Build Start | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Send Telegram Notification | |
| run: | | |
| curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ | |
| -F chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \ | |
| -F message_thread_id="${{ secrets.TELEGRAM_MESSAGE_THREAD_ID }}" \ | |
| -F text=" | |
| π *Build started for Aesir!* | |
| π¦ *Repository:* [${{ github.repository }}](https://github.com/${{ github.repository }}) | |
| ποΈ *Branch:* \`${{ github.ref_name }}\` | |
| ποΈ *Version:* \`${{ github.event.inputs.version }}\` | |
| π₯οΈ *Architectures:* \`${{ github.event.inputs.arch }}\` | |
| βοΈ *Commit:* [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) | |
| [π View GitHub Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" \ | |
| -F parse_mode="Markdown" | |
| build-and-release: | |
| name: Build and Release | |
| runs-on: ubuntu-latest | |
| needs: notify_workflow | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '10.0.x' | |
| - name: Make build script executable | |
| run: chmod +x build.sh | |
| - name: Build project | |
| run: ./build.sh | |
| - name: Verify build output amd64 | |
| if: github.event.inputs.arch == 'All' || github.event.inputs.arch == 'amd64' | |
| run: | | |
| if [ ! -f "bin/Release/net10.0/publish/linux-x64/Aesir" ]; then | |
| echo "Build output not found for amd64!" | |
| exit 1 | |
| fi | |
| chmod +x bin/Release/net10.0/publish/linux-x64/Aesir | |
| - name: Verify build output arm64 | |
| if: github.event.inputs.arch == 'All' || github.event.inputs.arch == 'aarch64' | |
| run: | | |
| if [ ! -f "bin/Release/net10.0/publish/linux-arm64/Aesir" ]; then | |
| echo "Build output not found for arm64!" | |
| exit 1 | |
| fi | |
| chmod +x bin/Release/net10.0/publish/linux-arm64/Aesir | |
| - name: Extract Latest Changelog | |
| id: changelog | |
| run: | | |
| # Extract the section for the latest release (everything between the first and second '# [') | |
| awk '/^# \[/ {if (p) exit; p=1; next} p' CHANGELOG.md > latest_changelog.txt | |
| echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT | |
| cat latest_changelog.txt >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create Release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh release create v${{ github.event.inputs.version }} \ | |
| --title "Aesir v${{ github.event.inputs.version }}" \ | |
| --notes "${{ steps.changelog.outputs.CHANGELOG }}" \ | |
| --target ${{ github.ref_name }} | |
| - name: Prepare release assets | |
| run: | | |
| if [ -f "bin/Release/net10.0/publish/linux-x64/Aesir" ]; then | |
| cp bin/Release/net10.0/publish/linux-x64/Aesir Aesir-linux-amd64 | |
| fi | |
| if [ -f "bin/Release/net10.0/publish/linux-arm64/Aesir" ]; then | |
| cp bin/Release/net10.0/publish/linux-arm64/Aesir Aesir-linux-aarch64 | |
| fi | |
| - name: Upload release asset amd64 | |
| if: github.event.inputs.arch == 'All' || github.event.inputs.arch == 'amd64' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: gh release upload v${{ github.event.inputs.version }} Aesir-linux-amd64 --clobber | |
| - name: Upload release asset arm64 | |
| if: github.event.inputs.arch == 'All' || github.event.inputs.arch == 'aarch64' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: gh release upload v${{ github.event.inputs.version }} Aesir-linux-aarch64 --clobber | |
| notify_completion: | |
| name: Notify Build Completion | |
| needs: [setup, build-and-release, notify_workflow] | |
| runs-on: ubuntu-latest | |
| if: always() && (needs.build-and-release.result != 'cancelled') | |
| steps: | |
| - name: Determine build results | |
| id: results | |
| run: | | |
| # Check the overall result of the build-and-release job | |
| if [ "${{ needs.build-and-release.result }}" == "success" ]; then | |
| echo "status=β Build & Release completed successfully!" >> $GITHUB_OUTPUT | |
| echo "emoji=π" >> $GITHUB_OUTPUT | |
| else | |
| echo "status=β Build & Release failed!" >> $GITHUB_OUTPUT | |
| echo "emoji=π₯" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Send Telegram Completion Notification | |
| run: | | |
| DATE=$(date +'%Y-%m-%d') | |
| curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ | |
| -F chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \ | |
| -F message_thread_id="${{ secrets.TELEGRAM_MESSAGE_THREAD_ID }}" \ | |
| -F text=" | |
| ${{ steps.results.outputs.emoji }} *Aesir Workflow Finished* | |
| π¦ *Repository:* [${{ github.repository }}](https://github.com/${{ github.repository }}) | |
| π *Date:* $DATE | |
| π·οΈ *Version:* \`v${{ github.event.inputs.version }}\` | |
| π *Status:* ${{ steps.results.outputs.status }} | |
| πΎ *Download releases:* [GitHub Releases](https://github.com/${{ github.repository }}/releases/tag/v${{ github.event.inputs.version }}) | |
| [π View GitHub Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" \ | |
| -F parse_mode="Markdown" |