Skip to content

Commit c343b50

Browse files
authored
Merge pull request #9 from cortex-command-community/nightly-releases
ci: implement a nightly build script
2 parents e5a1afa + 9269f11 commit c343b50

File tree

2 files changed

+179
-1
lines changed

2 files changed

+179
-1
lines changed

.github/workflows/msbuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ jobs:
8484
uses: actions/upload-artifact@v3
8585
with:
8686
name: ${{ steps.executable_name.outputs.EXECUTABLE_NAME }}
87-
path: D:/a/Cortex-Command-Community-Project/Cortex-Command-Community-Project/${{ steps.executable_name.outputs.EXECUTABLE_NAME }}
87+
path: ${{ steps.executable_name.outputs.EXECUTABLE_NAME }}
8888
if-no-files-found: error

.github/workflows/nightly.yaml

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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_build.outputs.needs_build }}
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v3
27+
28+
- name: fetch tags
29+
run: git fetch --tags origin
30+
31+
- name: Check if tags point to the same commit or if the workflow was manually triggered
32+
id: check_build
33+
run: |
34+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
35+
echo "Workflow dispatched manually. Continuing..."
36+
echo "needs_build=true" >> $GITHUB_OUTPUT;
37+
else
38+
curr_sha=$(git rev-parse HEAD)
39+
prev_sha=$(git rev-parse ${{ env.PREV_TAG }})
40+
41+
if [[ "$curr_sha" == "$prev_sha" ]]; then
42+
echo "No changes since last nightly release. Exiting..."
43+
echo "needs_build=false" >> $GITHUB_OUTPUT;
44+
else
45+
echo "Changes since last nightly release detected. Continuing..."
46+
echo "needs_build=true" >> $GITHUB_OUTPUT;
47+
fi
48+
fi
49+
50+
build-meson-releases:
51+
name: Linux & macOS Release Builds
52+
53+
needs: check-for-changes
54+
if: needs.check-for-changes.outputs.needs_build == 'true'
55+
56+
uses: ./.github/workflows/meson.yml
57+
with:
58+
upload_artefacts: true
59+
60+
build-msbuild-releases:
61+
name: Windows Release Build
62+
63+
needs: check-for-changes
64+
if: needs.check-for-changes.outputs.needs_build == 'true'
65+
66+
uses: ./.github/workflows/msbuild.yml
67+
with:
68+
upload_artefacts: true
69+
70+
release:
71+
name: Publish Release
72+
runs-on: ubuntu-latest
73+
74+
needs: [build-msbuild-releases, build-meson-releases]
75+
76+
steps:
77+
- name: Checkout code
78+
uses: actions/checkout@v3
79+
80+
- name: fetch tags
81+
run: git fetch --tags origin
82+
83+
- run: mkdir release
84+
85+
- name: Download build artefacts
86+
uses: actions/download-artifact@v3
87+
with:
88+
path: release
89+
90+
- run: ls -R release
91+
92+
- name: Compress Windows Release
93+
run: |
94+
zip -j CortexCommand.windows.zip \
95+
"release/Cortex Command.exe" \
96+
external/lib/win/{fmod,SDL2}.dll
97+
98+
- name: Compress Linux Release
99+
run: |
100+
zip -j CortexCommand.linux.zip \
101+
"release/CortexCommand (Linux)/CortexCommand.AppImage" \
102+
external/lib/linux/x86_64/libfmod.so*
103+
104+
- name: Compress OSX Release
105+
run: |
106+
zip -j CortexCommand.macos.zip \
107+
"release/CortexCommand (macOS)/CortexCommand" \
108+
external/lib/macos/libfmod.dylib
109+
110+
- name: Package Data files
111+
run: |
112+
zip -r -u CortexCommand.windows.zip Data
113+
zip -r -u CortexCommand.linux.zip Data
114+
zip -r -u CortexCommand.macos.zip Data
115+
116+
- name: Get Date
117+
id: get_date
118+
run: |
119+
echo "CURRENT_DATE=$(date +'%d-%m-%Y')" >> $GITHUB_OUTPUT
120+
121+
- name: Check if a nightly release exists
122+
id: check_nightly
123+
run: |
124+
gh release view nightly --repo ${{ github.repository }}
125+
if [ $? -eq 0 ] ; then
126+
echo "release_exists=true" >> $GITHUB_OUTPUT;
127+
else
128+
echo "release_exists=false" >> $GITHUB_OUTPUT;
129+
fi
130+
shell: bash
131+
continue-on-error: true
132+
env:
133+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134+
135+
- name: Delete old nightly release if it exists
136+
if: steps.check_nightly.outputs.release_exists
137+
run: |
138+
gh release delete nightly -y
139+
env:
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141+
142+
- name: Get commit SHA
143+
id: get_commit_sha
144+
if: steps.check_nightly.outputs.release_exists
145+
run: |
146+
prev_sha=$(git rev-parse nightly)
147+
echo "prev_SHA=$prev_sha" >> $GITHUB_OUTPUT;
148+
149+
- name: Update tag pointing to the previous nightly release
150+
if: steps.check_nightly.outputs.release_exists
151+
run: |
152+
curl -X PATCH \
153+
-H "Authorization: Bearer ${{ secrets.WORKFLOW_TOKEN }}" \
154+
-H "Accept: application/vnd.github.v3+json" \
155+
https://api.github.com/repos/${{ github.repository }}/git/refs/tags/${{ env.PREV_TAG }} \
156+
-d '{
157+
"sha": "${{ steps.get_commit_sha.outputs.prev_SHA }}"
158+
}'
159+
160+
- name: Remove current nightly tag before release
161+
if: steps.check_nightly.outputs.release_exists
162+
run: |
163+
git tag -d nightly
164+
git push origin :refs/tags/nightly
165+
166+
- name: Create Release if it does not exist
167+
id: create_release
168+
run: |
169+
gh release create nightly \
170+
--title "Nightly Development Build (${{ steps.get_date.outputs.CURRENT_DATE }})" \
171+
--generate-notes \
172+
${{steps.check_nightly.outputs.release_exists && format('--notes-start-tag {0}', env.PREV_TAG) || ''}} \
173+
--prerelease \
174+
'CortexCommand.windows.zip#Cortex Command [Nightly Build] (Windows Release)' \
175+
'CortexCommand.linux.zip#Cortex Command [Nightly Build] (Linux Release)' \
176+
'CortexCommand.macos.zip#Cortex Command [Nightly Build] (macOS Release)'
177+
env:
178+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)