-
Notifications
You must be signed in to change notification settings - Fork 0
179 lines (176 loc) · 6.54 KB
/
create-nightly-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Nightly Develop Build
on:
workflow_dispatch:
schedule:
- cron: 0 0 * * *
env:
DEBUG: false
REF_CHECKOUT_BRANCH: develop
RELEASE_NAME: Recent nightly build
APPLICATION_PUBLISH_FOLDER: ./publish
WINDOWS_ARTIFACT_NAME: IL_2_Career_Toolset_windows_x64
WINDOWS_NUGET_ARTIFACT_NAME: IL_2_Career_Toolset_Nuget_windows_x64
RELEASE_ARTIFACT_FOLDER: artifacts
GH_TOKEN: ${{ github.token }}
jobs:
check-for-changes:
runs-on: ubuntu-latest
name: Check for changes in last 24 hours
outputs:
should-run: ${{ steps.should-run.outputs.should-run }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.REF_CHECKOUT_BRANCH }}
- name: get latest commit and check it
id: should-run
continue-on-error: true
if: ${{ env.DEBUG == 'true' }} || ${{ github.event_name == 'schedule' }}
# Based on https://stackoverflow.com/questions/63014786/how-to-schedule-a-github-actions-nightly-build-but-run-it-only-when-there-where
# @Note: Check the comments on the solution!
run: |
latest=$(git log -n 1 --pretty=format:"%H")
# For debug testing remove ${{ env.REF_CHECKOUT_BRANCH }}
sha=$(git rev-list ${{ env.REF_CHECKOUT_BRANCH }} --after="24 hours" $latest)
echo $sha
echo Do the check now
if test -z $sha
then
echo "Check failed"
echo "should-run=false" >> $GITHUB_OUTPUT
else
echo "Check successful"
echo "should-run=true" >> $GITHUB_OUTPUT
fi
check-build:
name: Check and Test build
# Based on https://stackoverflow.com/questions/59882715/use-environment-variable-in-github-action-if
if: needs.check-for-changes.outputs.should-run == 'true'
needs: [check-for-changes]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.REF_CHECKOUT_BRANCH }}
lfs: true
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
create-windows-build:
name: Publish Windows build
if: needs.check-for-changes.outputs.should-run == 'true'
needs: ["check-build"]
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.REF_CHECKOUT_BRANCH }}
lfs: true
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Publish Application
run: dotnet publish .\src\IL2CareerToolset\IL2CareerToolset.csproj -r win-x64 -c Release -o ${{ env.APPLICATION_PUBLISH_FOLDER }} --self-contained true -p:Version=0.0.0 -p:PublishSingleFile=true
- name: Cleanup published build
run: rm ${{ env.APPLICATION_PUBLISH_FOLDER }}\*.pdb
- name: Show content for debug
if: ${{ env.DEBUG == 'true' }}
run: ls
- name: Show content to publish
if: ${{ env.DEBUG == 'true' }}
run: |
cd ./publish
ls
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ env.WINDOWS_ARTIFACT_NAME }}
path: ${{ env.APPLICATION_PUBLISH_FOLDER }}
if-no-files-found: error
create-windows-nuget-tool-build:
name: Build nuget tool
needs: ["check-build"]
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.REF_CHECKOUT_BRANCH }}
lfs: true
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Pack application
run: dotnet pack -p:PackageOutputPath=publish -p:Version=0.0.0
- name: Move nuget to output
run: |
mkdir ${{ env.APPLICATION_PUBLISH_FOLDER }}
mv .\src\IL2CareerToolset\publish\*.nupkg ${{ env.APPLICATION_PUBLISH_FOLDER }}
mv .\src\IL2CareerModel\publish\*.nupkg ${{ env.APPLICATION_PUBLISH_FOLDER }}
- name: Show content for debug
if: ${{ env.DEBUG == 'true' }}
run: ls
- name: Show content which was packed
if: ${{ env.DEBUG == 'true' }}
run: |
cd ./publish
ls
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ env.WINDOWS_NUGET_ARTIFACT_NAME }}
path: ${{ env.APPLICATION_PUBLISH_FOLDER }}
if-no-files-found: error
create-release:
name: Create GitHub Release
if: needs.check-for-changes.outputs.should-run == 'true'
needs: ["create-windows-build", "create-windows-nuget-tool-build"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.REF_CHECKOUT_BRANCH }}
lfs: true
- name: Download artifacts
uses: actions/download-artifact@v2
with:
path: ${{ env.RELEASE_ARTIFACT_FOLDER }}
- name: Zip Windows build
run: |
cd ./$RELEASE_ARTIFACT_FOLDER/$WINDOWS_ARTIFACT_NAME
zip -r $WINDOWS_ARTIFACT_NAME.zip ./*
mv $WINDOWS_ARTIFACT_NAME.zip ../
rm -rf ./../$WINDOWS_ARTIFACT_NAME
- name: Move nuget tool
run: |
mv ./$RELEASE_ARTIFACT_FOLDER/$WINDOWS_NUGET_ARTIFACT_NAME/IL2CareerToolset*.nupkg ./$RELEASE_ARTIFACT_FOLDER
rm -rf ./$RELEASE_ARTIFACT_FOLDER/$WINDOWS_NUGET_ARTIFACT_NAME/
- name: display artifacts folder content
if: ${{ env.DEBUG == 'true' }}
run: ls -la $RELEASE_ARTIFACT_FOLDER
- name: Create release and upload artifacts (DEBUG)
if: ${{ env.DEBUG == 'true' }}
run: |
gh release create Develop-${{ GITHUB.RUN_NUMBER }} \
--title "${{ env.RELEASE_NAME }} [${{ GITHUB.RUN_NUMBER }}]" --target ${{ env.REF_CHECKOUT_BRANCH }} \
--generate-notes --prerelease ${parameters} --notes "Recent version of the develop branch, ready for testing" \
-d ${{ env.RELEASE_ARTIFACT_FOLDER }}/*.*
- name: Create release and upload artifacts
if: ${{ env.DEBUG == 'false' }}
run: |
gh release create Develop-${{ GITHUB.RUN_NUMBER }} \
--title "${{ env.RELEASE_NAME }} [${{ GITHUB.RUN_NUMBER }}]" --target ${{ env.REF_CHECKOUT_BRANCH }} \
--generate-notes --prerelease ${parameters} --notes "Recent version of the develop branch, ready for testing" \
${{ env.RELEASE_ARTIFACT_FOLDER }}/*.* --discussion-category "Releases"