From 2a6753f9844a7a62572016e0b4ba747dbd7a7740 Mon Sep 17 00:00:00 2001 From: breadbyte <14045257+breadbyte@users.noreply.github.com> Date: Sun, 22 Mar 2026 15:17:47 +0800 Subject: [PATCH] Update build-and-release.yml --- .github/workflows/build-and-release.yml | 257 ++++++++++++++---------- 1 file changed, 152 insertions(+), 105 deletions(-) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 40a22587..0bd0350c 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -12,96 +12,21 @@ env: compile-flags: "--self-contained=true -c Release -p:UseAppHost=true -p:IncludeNativeLibrariesForSelfExtract=true -p:EnableCompressionInSingleFile=true -p:DebugType=Embedded" jobs: - build: - runs-on: ubuntu-latest - if: ${{ always() && needs.fetch-translations.result != 'failure' && needs.determine-build.result != 'skipped' }} - needs: [determine-build, fetch-translations] - timeout-minutes: 15 - strategy: - matrix: - target: [win-x86, win-x64, win-arm64, linux-x64, linux-arm, linux-arm64, osx-x64, osx-arm64] - + determine-build: + runs-on: ubuntu-slim + if: >- + ${{ + !contains(github.event.head_commit.message, 'skipci') && + !contains(github.event.pull_request.title, 'skipci') + }} steps: - - name: Checkout - uses: actions/checkout@v3 - if: ${{ always() && needs.fetch-translations.result == 'skipped' }} - with: - fetch-depth: 0 - submodules: 'true' - - - name: Get Current Date - run: | - echo date=$(date +'%Y%m%d') >> $GITHUB_ENV - echo date_dashed=$(date -u +'%Y-%m-%d') >> $GITHUB_ENV - - - name: Restore Translations (if available) - uses: actions/cache/restore@v3 - with: - path: ${{ github.workspace }}/* - key: "translation-${{ github.sha }}" - restore-keys: "translation-" - - - name: Setup Environment Variables (early) - run: | - echo project-path=${{ github.workspace }}/${{ env.PROJECT }} >> $GITHUB_ENV - echo file-ext=${{ (startsWith(matrix.target, 'win') && '.exe') || ' ' }} >> $GITHUB_ENV + - name: dummy action + run: "echo 'dummy action that checks if the build is to be skipped, if it is, this action does not run to break the entire build action'" - - name: Setup .NET SDK - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 10.0.x - - - name: Setup Environment Variables - run: | - echo target-out-path=${{ env.project-path }}/bin/Release/${{ env.target-version }}/${{ matrix.target }}/publish/ >> $GITHUB_ENV - echo assembly-info=${{ env.project-path }}/Properties/AssemblyInfo.cs >> $GITHUB_ENV - echo build-version-info=${{ env.date }}-${{ github.run_number }} >> $GITHUB_ENV - echo commit=$(echo ${{ github.sha }} | cut -c 1-7) >> $GITHUB_ENV - - - name: Setup Environment Variables (late) - run: | - echo built-executable-path=${{ env.target-out-path }}${{ env.PROJECT }}${{ env.file-ext }} >> $GITHUB_ENV - - - name: Set Version Info - run: | - echo '' >> ${{ env.assembly-info }} - echo "[assembly: AssemblyConfiguration(\"GitHub build ${{ github.run_number }}, built on ${{ env.date_dashed }} from commit ${{ env.commit }}\")]" >> ${{ env.assembly-info }} - sed -i -e 's|SentryDSN = "";|SentryDSN = "${{ secrets.SENTRY_DSN }}";|g' ${{ env.project-path }}/Program.cs - - - name: Build Target - run: dotnet publish ${{ env.project-path }}.sln -f ${{ env.target-version }} -r ${{ matrix.target }} ${{ env.compile-flags }} - env: - DOTNET_NOLOGO: true - - - name: Rename Binary - run: | - mv ${{ env.built-executable-path }} ${{ env.PROJECT }}-${{ env.build-version-info }}-${{ matrix.target }}${{ (startsWith(matrix.target, 'win') && '.exe') || ' ' }} - - - name: Wait - # We wait before creating a release because we might run into a race condition - # while creating a new tag (as opposed to using the existing tag, if any) since we're running builds in parallel. - run: | - sleep 5s - - - name: Create Release - uses: ncipollo/release-action@v1.14.0 - with: - token: ${{ secrets.GITHUB_TOKEN }} - artifacts: ${{ env.PROJECT }}-${{ env.build-version-info }}-${{ matrix.target }}${{ (startsWith(matrix.target, 'win') && '.exe') || ' ' }} - tag: ${{ format('{0}-{1}', env.date, github.run_number) }} - name: '${{ env.build-version-info }}: ${{ github.event.head_commit.message }}' - generateReleaseNotes: true - artifactErrorsFailBuild: true - allowUpdates: true - makeLatest: true - omitBodyDuringUpdate: true - omitNameDuringUpdate: true - replacesArtifacts: false - fetch-translations: strategy: fail-fast: true - runs-on: ubuntu-latest + runs-on: ubuntu-slim needs: determine-build # Translations will only be fetched in the MCCTeam repository, since it needs crowdin secrets. if: ${{ github.repository == 'MCCTeam/Minecraft-Console-Client' }} @@ -116,13 +41,13 @@ jobs: key: "translation-${{ github.sha }}" lookup-only: true restore-keys: "translation-" - + - name: Checkout - uses: actions/checkout@v3 if: steps.cache-check.outputs.cache-hit != 'true' + uses: actions/checkout@v3 with: - fetch-depth: 0 - submodules: 'true' + fetch-depth: 0 + submodules: 'true' - name: Download translations from crowdin uses: crowdin/github-action@v1.6.0 @@ -148,20 +73,142 @@ jobs: with: path: ${{ github.workspace }}/* key: "translation-${{ github.sha }}" - - determine-build: - runs-on: ubuntu-latest - strategy: - fail-fast: true - if: >- - ${{ - !contains(github.event.head_commit.message, 'skipci') && - !contains(github.event.head_commit.message, '[skipci]') && - !contains(github.event.head_commit.message, 'skipci | ') && - !contains(github.event.pull_request.title, 'skipci') && - !contains(github.event.pull_request.title, '[skipci]') && - !contains(github.event.pull_request.title, 'skipci | ') - }} + + create-tag: + runs-on: ubuntu-slim + timeout-minutes: 5 # Wait 5 minutes in case of network issues/etc + needs: [determine-build] + if: ${{ needs.determine-build.result == 'success' }} steps: - - name: dummy action - run: "echo 'dummy action that checks if the build is to be skipped, if it is, this action does not run to break the entire build action'" + - id: make-tag + run: | + TAG="$(date -u +'%Y%m%d')-${{ github.run_number }}" + echo "tag=$TAG" >> $GITHUB_OUTPUT + echo "TAG=$TAG" >> $GITHUB_ENV + + - name: Create Release Tag + uses: actions/github-script@v7 + with: + script: | + const tag = process.env.TAG; + try { + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/tags/${tag}`, + sha: context.sha + }); + } catch(error) { + if (error.message.includes('already exists')) { + console.log(`Tag ${tag} already exists`); + } else { + throw error; + } + } + outputs: + build-tag: ${{ steps.make-tag.outputs.tag }} + + build: + runs-on: ubuntu-latest + # Check if we're not skipping build, tag is created, and translations successfully fetched (or skipped) + if: ${{ needs.determine-build.result == 'success' && + needs.create-tag.result == 'success' && + (needs.fetch-translations.result == 'success' || needs.fetch-translations.result == 'skipped') + }} + needs: [determine-build, fetch-translations, create-tag] + timeout-minutes: 15 + strategy: + matrix: + target: [win-x86, win-x64, win-arm64, linux-x64, linux-arm, linux-arm64, osx-x64, osx-arm64] + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: 'true' + + - name: Get Current Date + run: | + echo date=$(date +'%Y%m%d') >> $GITHUB_ENV + echo date_dashed=$(date -u +'%Y-%m-%d') >> $GITHUB_ENV + + - name: Restore Translations (if available) + uses: actions/cache/restore@v3 + with: + path: ${{ github.workspace }}/* + key: "translation-${{ github.sha }}" + restore-keys: "translation-" + + - name: Setup Environment Variables (early) + run: | + echo project-path=${{ github.workspace }}/${{ env.PROJECT }} >> $GITHUB_ENV + echo file-ext=${{ (startsWith(matrix.target, 'win') && '.exe') || '' }} >> $GITHUB_ENV + + - name: Setup .NET SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 10.0.x + + - name: Setup Environment Variables + run: | + echo target-out-path=${{ env.project-path }}/bin/Release/${{ env.target-version }}/${{ matrix.target }}/publish/ >> $GITHUB_ENV + echo assembly-info=${{ env.project-path }}/Properties/AssemblyInfo.cs >> $GITHUB_ENV + echo build-version-info=${{ needs.create-tag.outputs.build-tag }} >> $GITHUB_ENV + echo commit=$(echo ${{ github.sha }} | cut -c 1-7) >> $GITHUB_ENV + + - name: Setup Environment Variables (late) + run: | + echo built-executable-path=${{ env.target-out-path }}${{ env.PROJECT }}${{ env.file-ext }} >> $GITHUB_ENV + + - name: Set Version Info and Sentry Project (if applicable) + run: | + echo '' >> ${{ env.assembly-info }} + echo "[assembly: AssemblyConfiguration(\"GitHub build ${{ github.run_number }}, built on ${{ env.date_dashed }} from commit ${{ env.commit }}\")]" >> ${{ env.assembly-info }} + + - name: Inject Sentry DSN + if: ${{ github.repository == 'MCCTeam/Minecraft-Console-Client' }} + run: | + grep -q 'SentryDSN = "";' ${{ env.project-path }}/Program.cs || { echo "SentryDSN pattern not found in Program.cs"; exit 1; } + sed -i -e 's|SentryDSN = "";|SentryDSN = "${{ secrets.SENTRY_DSN }}";|g' ${{ env.project-path }}/Program.cs + + - name: Build Target + run: dotnet publish ${{ env.project-path }}.sln -f ${{ env.target-version }} -r ${{ matrix.target }} ${{ env.compile-flags }} + env: + DOTNET_NOLOGO: true + + - name: Rename Binary + run: | + mv ${{ env.built-executable-path }} ${{ env.PROJECT }}-${{ env.build-version-info }}-${{ matrix.target }}${{ env.file-ext }} + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.PROJECT }}-${{ env.build-version-info }}-${{ matrix.target }} + path: ${{ env.PROJECT }}-${{ env.build-version-info }}-${{ matrix.target }}${{ env.file-ext }} + if-no-files-found: error + + create-release: + runs-on: ubuntu-slim + needs: [create-tag, build] + if: ${{ needs.build.result == 'success' && needs.create-tag.result == 'success' }} + steps: + - name: Download All Artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts/ + + - name: Create Release + uses: ncipollo/release-action@v1.14.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "artifacts/**/*" + tagName: ${{ needs.create-tag.outputs.build-tag }} + name: '${{ needs.create-tag.outputs.build-tag }}: ${{ github.event.head_commit.message }}' + generateReleaseNotes: true + artifactErrorsFailBuild: true + allowUpdates: true + makeLatest: true + omitBodyDuringUpdate: true + omitNameDuringUpdate: true + replacesArtifacts: true