Skip to content

Commit 4ce1116

Browse files
committed
Implement nightly releases with tagging
1 parent 4598f16 commit 4ce1116

File tree

1 file changed

+102
-13
lines changed

1 file changed

+102
-13
lines changed

.github/workflows/nightly.yaml

Lines changed: 102 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,57 @@ on:
66
- cron: "0 0 * * *"
77

88
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
1114

1215
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1316
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+
1444
build-meson-releases:
1545
name: Linux & macOS Release Builds
1646

47+
needs: check-for-changes
48+
if: needs.check-for-changes.outputs.needs_build == 'true'
49+
1750
uses: ./.github/workflows/meson.yml
1851
with:
1952
upload_artefacts: true
2053

2154
build-msbuild-releases:
2255
name: Windows Release Build
2356

57+
needs: check-for-changes
58+
if: needs.check-for-changes.outputs.needs_build == 'true'
59+
2460
uses: ./.github/workflows/msbuild.yml
2561
with:
2662
upload_artefacts: true
@@ -35,6 +71,9 @@ jobs:
3571
- name: Checkout code
3672
uses: actions/checkout@v3
3773

74+
- name: fetch tags
75+
run: git fetch --tags origin
76+
3877
- run: mkdir release
3978

4079
- name: Download build artefacts
@@ -68,17 +107,67 @@ jobs:
68107
zip -r -u CortexCommand.linux.zip Data
69108
zip -r -u CortexCommand.macos.zip Data
70109
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
72162
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)'
74172
env:
75173
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

Comments
 (0)