|
| 1 | +name: Nightly (Development) Build and Release |
| 2 | +# Controls when the action will run. |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "0 0 * * *" |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: nightly-${{ github.ref_name }} |
| 10 | +# cancel-in-progress: true |
| 11 | + |
| 12 | +env: |
| 13 | + PREV_TAG: nightly-prev |
| 14 | + |
| 15 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 16 | +jobs: |
| 17 | + check-for-changes: |
| 18 | + name: Determine if a new nightly build should be released |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + outputs: |
| 22 | + needs_build: ${{ steps.check_manual_run.outputs.needs_build == 'true' || steps.check_tags.outputs.needs_build == 'true' }} |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Check if workflow was manually triggered |
| 26 | + id: check_manual_run |
| 27 | + run: | |
| 28 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 29 | + echo "Workflow dispatched manually. Continuing..." |
| 30 | + echo "needs_build=true" >> $GITHUB_OUTPUT; |
| 31 | + else |
| 32 | + echo "Workflow triggered by a scheduled run. Continuing..." |
| 33 | + echo "needs_build=false" >> $GITHUB_OUTPUT; |
| 34 | + fi |
| 35 | +
|
| 36 | + - name: Checkout code |
| 37 | + if: ${{ steps.check_manual_run.outputs.needs_build == 'false' }} |
| 38 | + uses: actions/checkout@v3 |
| 39 | + |
| 40 | + - name: fetch tags |
| 41 | + if: ${{ steps.check_manual_run.outputs.needs_build == 'false' }} |
| 42 | + run: git fetch --tags origin |
| 43 | + |
| 44 | + - name: Check if tags point to the same commit or if the workflow was manually triggered |
| 45 | + if: ${{ steps.check_manual_run.outputs.needs_build == 'false' }} |
| 46 | + id: check_tags |
| 47 | + run: | |
| 48 | + curr_sha=$(git rev-parse HEAD) |
| 49 | + prev_sha=$(git rev-parse ${{ env.PREV_TAG }} 2>/dev/null) |
| 50 | +
|
| 51 | + if [[ $? -ne 0 ]]; then |
| 52 | + echo "Tag ${{ env.PREV_TAG }} cannot be resolved. Continuing..." |
| 53 | + echo "needs_build=true" >> $GITHUB_OUTPUT; |
| 54 | + elif [[ "$curr_sha" == "$prev_sha" ]]; then |
| 55 | + echo "No changes since last nightly release. Exiting..." |
| 56 | + echo "needs_build=false" >> $GITHUB_OUTPUT; |
| 57 | + else |
| 58 | + echo "Changes since last nightly release detected. Continuing..." |
| 59 | + echo "needs_build=true" >> $GITHUB_OUTPUT; |
| 60 | + fi |
| 61 | +
|
| 62 | + build-meson-releases: |
| 63 | + name: Linux & macOS Release Builds |
| 64 | + |
| 65 | + needs: check-for-changes |
| 66 | + if: needs.check-for-changes.outputs.needs_build == 'true' |
| 67 | + |
| 68 | + uses: ./.github/workflows/meson.yml |
| 69 | + with: |
| 70 | + upload_artefacts: true |
| 71 | + build_type: "debug" |
| 72 | + debug_level: "release" |
| 73 | + |
| 74 | + build-msbuild-releases: |
| 75 | + name: Windows Release Build |
| 76 | + |
| 77 | + needs: check-for-changes |
| 78 | + if: needs.check-for-changes.outputs.needs_build == 'true' |
| 79 | + |
| 80 | + uses: ./.github/workflows/msbuild.yml |
| 81 | + with: |
| 82 | + upload_artefacts: true |
| 83 | + build_configuration: "Debug Release" |
| 84 | + |
| 85 | + release: |
| 86 | + name: Publish Release |
| 87 | + runs-on: ubuntu-latest |
| 88 | + |
| 89 | + needs: [build-msbuild-releases, build-meson-releases] |
| 90 | + |
| 91 | + steps: |
| 92 | + - name: Checkout code |
| 93 | + uses: actions/checkout@v3 |
| 94 | + |
| 95 | + - name: fetch tags |
| 96 | + run: git fetch --tags origin |
| 97 | + |
| 98 | + - name: Bundle Release Assets |
| 99 | + uses: ./.github/actions/bundle_release |
| 100 | + |
| 101 | + - name: Get Date |
| 102 | + id: get_date |
| 103 | + run: | |
| 104 | + echo "CURRENT_DATE=$(date +'%d-%m-%Y')" >> $GITHUB_OUTPUT |
| 105 | +
|
| 106 | + - name: Check if a nightly release exists |
| 107 | + id: check_nightly |
| 108 | + run: | |
| 109 | + gh release view nightly --repo ${{ github.repository }} |
| 110 | + if [ $? -eq 0 ] ; then |
| 111 | + echo "release_exists=true" >> $GITHUB_OUTPUT; |
| 112 | + else |
| 113 | + echo "release_exists=false" >> $GITHUB_OUTPUT; |
| 114 | + fi |
| 115 | + shell: bash |
| 116 | + continue-on-error: true |
| 117 | + env: |
| 118 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + |
| 120 | + - name: Get commit SHA of the last nightly release |
| 121 | + id: get_commit_sha |
| 122 | + if: steps.check_nightly.outputs.release_exists |
| 123 | + run: | |
| 124 | + prev_sha=$(git rev-parse nightly) |
| 125 | + echo "prev_SHA=$prev_sha" >> $GITHUB_OUTPUT; |
| 126 | +
|
| 127 | + - name: Update tag pointing to the previous nightly release |
| 128 | + if: steps.check_nightly.outputs.release_exists |
| 129 | + run: | |
| 130 | + curl -X PATCH \ |
| 131 | + -H "Authorization: Bearer ${{ secrets.WORKFLOW_TOKEN }}" \ |
| 132 | + -H "Accept: application/vnd.github.v3+json" \ |
| 133 | + https://api.github.com/repos/${{ github.repository }}/git/refs/tags/${{ env.PREV_TAG }} \ |
| 134 | + -d '{ |
| 135 | + "sha": "${{ steps.get_commit_sha.outputs.prev_SHA }}" |
| 136 | + }' |
| 137 | +
|
| 138 | + - name: Delete the existing nightly tag and release |
| 139 | + if: steps.check_nightly.outputs.release_exists |
| 140 | + run: | |
| 141 | + gh release delete nightly -y --cleanup-tag |
| 142 | + env: |
| 143 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 144 | + |
| 145 | + - name: Create a new nightly release |
| 146 | + id: create_release |
| 147 | + run: | |
| 148 | + gh release create nightly \ |
| 149 | + --title "Nightly Development Build (${{ steps.get_date.outputs.CURRENT_DATE }})" \ |
| 150 | + --generate-notes \ |
| 151 | + ${{steps.check_nightly.outputs.release_exists && format('--notes-start-tag {0}', env.PREV_TAG) || ''}} \ |
| 152 | + --prerelease \ |
| 153 | + 'CortexCommand.windows.zip#Cortex Command [Nightly Build] (Windows Release)' \ |
| 154 | + 'CortexCommand.linux.zip#Cortex Command [Nightly Build] (Linux Release)' \ |
| 155 | + 'CortexCommand.macos.zip#Cortex Command [Nightly Build] (macOS Release)' |
| 156 | + env: |
| 157 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments