Skip to content

Commit 85d1c16

Browse files
authored
Merge pull request #1582 from OutpostUniverse/refactorGitHubActionsWorkflow
Refactor GitHub Actions workflow
2 parents 728aae3 + ab01f01 commit 85d1c16

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

.github/workflows/build.yml

+24-12
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,31 @@ jobs:
3838
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
3939
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
4040
41+
- name: Set SHA env vars
42+
shell: bash
43+
run: |
44+
vcpkgSha="${{ hashFiles('vcpkg.json') }}"
45+
nas2dSha="$(git submodule status -- nas2d-core/ | awk '{print $1}')"
46+
ophdSha="${{ github.sha }}"
47+
48+
config="${{ runner.os }}-${{ matrix.platform }}"
49+
cacheKeyPrefixOphd="buildCache-${config}-"
50+
51+
cacheKeyVcpkg="vcpkgCache-${config}-${vcpkgSha}"
52+
cacheKeyNas2d="nas2dCache-${config}-${nas2dSha}"
53+
cacheKeyOphd="${cacheKeyPrefixOphd}-${ophdSha}"
54+
55+
echo "cacheKeyVcpkg=${cacheKeyVcpkg}" >> $GITHUB_ENV
56+
echo "cacheKeyNas2d=${cacheKeyNas2d}" >> $GITHUB_ENV
57+
echo "cacheKeyOphd=${cacheKeyOphd}" >> $GITHUB_ENV
58+
echo "cacheKeyPrefixOphd=${cacheKeyPrefixOphd}" >> $GITHUB_ENV
59+
4160
- name: Restore vcpkg dependency cache
4261
uses: actions/cache/restore@v4
4362
id: cacheRestoreVcpkg
4463
with:
4564
path: vcpkg_installed
46-
key: vcpkgCache-${{ runner.os }}-${{ matrix.platform }}-${{ hashFiles('vcpkg.json') }}
65+
key: ${{ env.cacheKeyVcpkg }}
4766

4867
- name: Pre-install vcpkg dependencies - OPHD
4968
env:
@@ -72,9 +91,6 @@ jobs:
7291
- name: Set NAS2D modification time
7392
shell: bash
7493
run: |
75-
nas2dSha=$(git submodule status -- nas2d-core/ | awk '{print $1}')
76-
echo "nas2dSha=${nas2dSha}" >> $GITHUB_ENV
77-
7894
# Set last modification times to that of last build's committer time
7995
# The committer time should pre-date any cached output modification time
8096
commitTime=$(git -C nas2d-core/ log -1 --format="%cI")
@@ -87,11 +103,9 @@ jobs:
87103
if: steps.cacheRestoreVcpkg.outputs.cache-hit == 'true'
88104
with:
89105
path: nas2d-core/.build/
90-
key: nas2dCache-${{ runner.os }}-${{ matrix.platform }}-${{ env.nas2dSha }}
106+
key: ${{ env.cacheKeyNas2d }}
91107

92108
- name: Build NAS2D
93-
# Add additional options to the MSBuild command line here (like platform or verbosity level).
94-
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
95109
run: |
96110
msbuild . /maxCpuCount /warnAsError /property:RunCodeAnalysis=true /target:NAS2D
97111
@@ -108,8 +122,8 @@ jobs:
108122
if: github.ref != format('refs/heads/{0}', github.event.repository.default_branch) && steps.cacheRestoreNas2d.outputs.cache-hit == 'true'
109123
with:
110124
path: .build
111-
key: buildCache-${{ runner.os }}-${{ matrix.platform }}-${{ github.sha }}
112-
restore-keys: buildCache-${{ runner.os }}-${{ matrix.platform }}-
125+
key: ${{ env.cacheKeyOphd }}
126+
restore-keys: ${{ env.cacheKeyPrefixOphd }}
113127

114128
- name: Set modification times
115129
if: ${{ hashFiles('.build/lastBuildSha.txt') != '' }}
@@ -141,8 +155,6 @@ jobs:
141155
echo "${{ github.sha }}" > .build/lastBuildSha.txt
142156
143157
- name: Build OPHD
144-
# Add additional options to the MSBuild command line here (like platform or verbosity level).
145-
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
146158
run: |
147159
msbuild . /maxCpuCount /warnAsError /property:RunCodeAnalysis=true
148160
@@ -151,7 +163,7 @@ jobs:
151163
if: steps.cacheRestoreOphd.outcome == 'skipped' || steps.cacheRestoreOphd.outputs.cache-hit != 'true'
152164
with:
153165
path: .build
154-
key: buildCache-${{ runner.os }}-${{ matrix.platform }}-${{ github.sha }}
166+
key: ${{ env.cacheKeyOphd }}
155167

156168
- name: Run libOPHD unit tests
157169
run: .build/${{env.Configuration}}_${{env.Platform}}_testLibOPHD/testLibOPHD.exe

0 commit comments

Comments
 (0)