From e544bca9083165c810f8567f5d9abf92c443eed6 Mon Sep 17 00:00:00 2001 From: Nicolas Merget <104347736+nmerget@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:45:26 +0200 Subject: [PATCH] feat: improve pipeline to publish release builds (#170) * feat: improve pipeline to publish release builds * fix: issues with workflows * refactor: publish process * fix: overwrite godot master to 4.1 because the api changed from 4.1->4.2 * fix: issue with wrong version name for release --- .github/workflows/get_version.yml | 14 +++-- .github/workflows/release_builds.yml | 85 ++++++++++++++++++++++++++++ .github/workflows/runner.yml | 60 +++++++++++++++++++- 3 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release_builds.yml diff --git a/.github/workflows/get_version.yml b/.github/workflows/get_version.yml index d90a2bc3..3b22f1ed 100644 --- a/.github/workflows/get_version.yml +++ b/.github/workflows/get_version.yml @@ -3,12 +3,16 @@ name: 🆚 Get godot version on: workflow_call: - # Map the workflow outputs to job outputs outputs: version: description: "Which version we should use based on target branch" value: ${{ jobs.version.outputs.version }} +# We use a godot tag(rc version) as default version for master +# because the api is changing often and this would lead to a lot of struggle +env: + MASTER_VERSION: 4.1 + jobs: version: name: Get godot version @@ -18,13 +22,15 @@ jobs: steps: - name: 🏷 Get and set godot version id: version - # TODO: GH-Action should extract target branch; branches should be named according to godot engine branches run: | - VERSION="4.1" + VERSION="${{ github.event.pull_request.base.ref || github.base_ref || github.event.release.target_commitish }}" + if [[ $VERSION == "master" ]]; then + VERSION="$MASTER_VERSION" + echo "We are overwrite master to latest rc version: $VERSION" + fi echo "version=$VERSION" >> $GITHUB_OUTPUT - name: 🌳 Log Valid Version env: VERSION: ${{ steps.version.outputs.version }} run: echo "$VERSION" - diff --git a/.github/workflows/release_builds.yml b/.github/workflows/release_builds.yml new file mode 100644 index 00000000..95d0016c --- /dev/null +++ b/.github/workflows/release_builds.yml @@ -0,0 +1,85 @@ +name: 🦅 Release Builds +on: + workflow_call: + inputs: + version: + required: true + type: string + +concurrency: + group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-android + cancel-in-progress: true + +permissions: + contents: write + +jobs: + rename: + runs-on: ubuntu-latest + steps: + - name: ⏬ Checkout repo + uses: actions/checkout@v4 + + - name: 📛 Add version to release name + uses: actions/github-script@v6 + with: + result-encoding: json + script: | + const { repo, owner } = context.repo; + const date = new Date(); + const year = date.getFullYear().toString(); + const month = (date.getMonth() + 1).toString().padStart(2,"0"); + const day = (date.getDay() + 1).toString().padStart(2,"0"); + await github.rest.repos.updateRelease({ + owner, + repo, + release_id: context.payload.release.id, + name: '${{ inputs.version }}-' + context.payload.release.name + '-' + year + month + day, + }); + + release: + runs-on: ubuntu-latest + name: ${{ matrix.name }} + strategy: + fail-fast: false + matrix: + name: + - android-template + - ios-template + - linux-editor-mono + - linux-template-minimal + - linux-template-mono + - macos-editor + - macos-template + - web-template + - windows-editor + - windows-template + steps: + - name: ⏬ Checkout repo + uses: actions/checkout@v4 + + - name: ⏬ Download build + uses: actions/download-artifact@v3 + with: + name: ${{ matrix.name }} + path: ${{ matrix.name }} + + - name: 📦 Pack build as zip + run: zip -r ${{ matrix.name }}.zip ${{ matrix.name }} + shell: bash + + - name: ⏫ Upload Release Asset + id: upload-release-asset + uses: actions/github-script@v6 + with: + result-encoding: json + script: | + const FS = require('node:fs') + const { repo, owner } = context.repo; + return await github.rest.repos.uploadReleaseAsset({ + owner, + repo, + release_id: context.payload.release.id, + name: '${{ matrix.name }}.zip', + data: FS.readFileSync('${{ github.workspace }}/${{ matrix.name }}.zip') + }); diff --git a/.github/workflows/runner.yml b/.github/workflows/runner.yml index e76bdf3d..828b6135 100644 --- a/.github/workflows/runner.yml +++ b/.github/workflows/runner.yml @@ -1,5 +1,16 @@ name: 🔗 GHA -on: [push, pull_request] + +# Only run pipeline on open pull_requests and master + versions + releases +# we don't need it on every push and some parameters are not available for push only +on: + pull_request: + push: + branches: + - "master" + - "3.4" + - "4.1" + release: + types: [published] concurrency: group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-runner @@ -58,3 +69,50 @@ jobs: uses: ./.github/workflows/web_builds.yml with: version: ${{ needs.get-version.outputs.version }} + + checks-done: + if: ${{ always() }} + name: ✅ Check builds + runs-on: ubuntu-latest + steps: + - name: 🎉 Checks done + run: | + resultWebBuild="${{ needs.web-build.result }}" + resultWindowsBuild="${{ needs.windows-build.result }}" + resultMacosBuild="${{ needs.macos-build.result }}" + resultLinuxBuild="${{ needs.linux-build.result }}" + resultIosBuild="${{ needs.ios-build.result }}" + resultAndroidBuild="${{ needs.android-build.result }}" + if [[ + $resultWebBuild == "success" && + $resultWindowsBuild == "success" && + $resultMacosBuild == "success" && + $resultLinuxBuild == "success" && + $resultIosBuild == "success" && + $resultAndroidBuild == "success" + ]]; + then + echo "🎉 All builds were successful." + exit 0 + else + echo "😥 Some builds were failing." + exit 1 + fi + needs: + [ + web-build, + windows-build, + macos-build, + linux-build, + ios-build, + android-build + ] + + release: + name: 🦅 Release + if: github.event_name == 'release' && github.event.action == 'published' + needs: [checks-done] + uses: ./.github/workflows/release_builds.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }}