|
6 | 6 | - cron: "0 0 * * *"
|
7 | 7 |
|
8 | 8 | concurrency:
|
9 |
| - group: release-${{ github.ref_name }} |
10 |
| - cancel-in-progress: true |
| 9 | + group: nightly-${{ github.ref_name }} |
| 10 | +# cancel-in-progress: true |
| 11 | + |
| 12 | +env: |
| 13 | + PREV_TAG: nightly-prev |
11 | 14 |
|
12 | 15 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
13 | 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_build.outputs.needs_build }} |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Check if tags point to the same commit or if the workflow was manually triggered |
| 26 | + id: check_build |
| 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 | + curr_sha=$(git rev-parse HEAD) |
| 33 | + prev_sha=$(git rev-parse ${{ env.PREV_TAG }}}}) |
| 34 | +
|
| 35 | + if [[ "$curr_sha" == "$prev_sha" ]]; then |
| 36 | + echo "No changes since last nightly release. Exiting..." |
| 37 | + echo "needs_build=false" >> $GITHUB_OUTPUT; |
| 38 | + else |
| 39 | + echo "Changes since last nightly release detected. Continuing..." |
| 40 | + echo "needs_build=true" >> $GITHUB_OUTPUT; |
| 41 | + fi |
| 42 | + fi |
| 43 | +
|
14 | 44 | build-meson-releases:
|
15 | 45 | name: Linux & macOS Release Builds
|
16 | 46 |
|
| 47 | + needs: check-for-changes |
| 48 | + if: needs.check-for-changes.outputs.needs_build == 'true' |
| 49 | + |
17 | 50 | uses: ./.github/workflows/meson.yml
|
18 | 51 | with:
|
19 | 52 | upload_artefacts: true
|
20 | 53 |
|
21 | 54 | build-msbuild-releases:
|
22 | 55 | name: Windows Release Build
|
23 | 56 |
|
| 57 | + needs: check-for-changes |
| 58 | + if: needs.check-for-changes.outputs.needs_build == 'true' |
| 59 | + |
24 | 60 | uses: ./.github/workflows/msbuild.yml
|
25 | 61 | with:
|
26 | 62 | upload_artefacts: true
|
|
35 | 71 | - name: Checkout code
|
36 | 72 | uses: actions/checkout@v3
|
37 | 73 |
|
| 74 | + - name: fetch tags |
| 75 | + run: git fetch --tags origin |
| 76 | + |
38 | 77 | - run: mkdir release
|
39 | 78 |
|
40 | 79 | - name: Download build artefacts
|
@@ -68,17 +107,67 @@ jobs:
|
68 | 107 | zip -r -u CortexCommand.linux.zip Data
|
69 | 108 | zip -r -u CortexCommand.macos.zip Data
|
70 | 109 |
|
71 |
| - - name: Create Release |
| 110 | + - name: Get Date |
| 111 | + id: get_date |
| 112 | + run: | |
| 113 | + echo "CURRENT_DATE=$(date +'%d-%m-%Y')" >> $GITHUB_OUTPUT |
| 114 | +
|
| 115 | + - name: Check if a nightly release exists |
| 116 | + id: check_nightly |
| 117 | + run: | |
| 118 | + gh release view nightly --repo ${{ github.repository }} |
| 119 | + if [ $? -eq 0 ] ; then |
| 120 | + echo "release_exists=true" >> $GITHUB_OUTPUT; |
| 121 | + else |
| 122 | + echo "release_exists=false" >> $GITHUB_OUTPUT; |
| 123 | + fi |
| 124 | + shell: bash |
| 125 | + continue-on-error: true |
| 126 | + env: |
| 127 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + |
| 129 | + - name: Delete old nightly release if it exists |
| 130 | + if: steps.check_nightly.outputs.release_exists |
| 131 | + run: | |
| 132 | + gh release delete nightly -y |
| 133 | + env: |
| 134 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + |
| 136 | + - name: Get commit SHA |
| 137 | + id: get_commit_sha |
| 138 | + if: steps.check_nightly.outputs.release_exists |
| 139 | + run: | |
| 140 | + prev_sha=$(git rev-parse nightly) |
| 141 | + echo "prev_SHA=$prev_sha" >> $GITHUB_OUTPUT; |
| 142 | +
|
| 143 | + - name: Create previous nightly tag |
| 144 | + if: steps.check_nightly.outputs.release_exists |
| 145 | + run: | |
| 146 | + curl -X POST \ |
| 147 | + -H "Authorization: Bearer ${{ secrets.WORKFLOW_TOKEN }}" \ |
| 148 | + -H "Accept: application/vnd.github.v3+json" \ |
| 149 | + https://api.github.com/repos/${{ github.repository }}/git/refs \ |
| 150 | + -d '{ |
| 151 | + "ref": "refs/tags/${{ env.PREV_TAG }}", |
| 152 | + "sha": "${{ steps.get_commit_sha.outputs.prev_SHA }}" |
| 153 | + }' |
| 154 | +
|
| 155 | + - name: Remove previous nightly tag |
| 156 | + if: steps.check_nightly.outputs.release_exists |
| 157 | + run: | |
| 158 | + git tag -d nightly |
| 159 | + git push origin :refs/tags/nightly |
| 160 | +
|
| 161 | + - name: Create Release if it does not exist |
72 | 162 | id: create_release
|
73 |
| - uses: softprops/action-gh-release@v1 |
| 163 | + run: | |
| 164 | + gh release create nightly \ |
| 165 | + --title "Nightly Development Build (${{ steps.get_date.outputs.CURRENT_DATE }})" \ |
| 166 | + --generate-notes \ |
| 167 | + ${{steps.check_nightly.outputs.release_exists && format('--notes-start-tag {0}', env.PREV_TAG) || ''}} \ |
| 168 | + --prerelease \ |
| 169 | + 'CortexCommand.windows.zip#Cortex Command [Nightly Build] (Windows Release)' \ |
| 170 | + 'CortexCommand.linux.zip#Cortex Command [Nightly Build] (Linux Release)' \ |
| 171 | + 'CortexCommand.macos.zip#Cortex Command [Nightly Build] (macOS Release)' |
74 | 172 | env:
|
75 | 173 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
76 |
| - with: |
77 |
| - files: | |
78 |
| - CortexCommand.windows.zip |
79 |
| - CortexCommand.linux.zip |
80 |
| - CortexCommand.macos.zip |
81 |
| - tag_name: "nightly" |
82 |
| - name: "Nightly Development Build" |
83 |
| - prerelease: true |
84 |
| - fail_on_unmatched_files: true |
|
0 commit comments