-
Notifications
You must be signed in to change notification settings - Fork 4
173 lines (138 loc) · 5.93 KB
/
build_windows.yaml
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
name: Build Windows
run-name: Windows builds
on:
push:
paths:
- "dockerfiles/**/windows/Dockerfile"
jobs:
changed_dockerfiles:
name: Get changed files
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed_dockerfiles.outputs.all_changed_files }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get changed files
id: changed_dockerfiles
uses: tj-actions/changed-files@v41
with:
json: true
escape_json: false
files: |
**/windows/Dockerfile
- name: Show changed dockerfiles
run: echo '${{ steps.changed_dockerfiles.outputs.all_changed_files }}'
get_nuke_sources:
name: Collect Nuke source files
runs-on: windows-latest
needs: [changed_dockerfiles]
strategy:
matrix:
files: ${{ fromJSON(needs.changed_dockerfiles.outputs.matrix) }}
fail-fast: false
outputs:
filename: ${{ steps.unique_name.outputs.filename}}
unique_name: ${{ steps.unique_name.outputs.unique_name}}
cache_key: ${{ steps.unique_name.outputs.cache_key}}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get cache name output
id: unique_name
shell: pwsh
run: |
echo "filename=${{ matrix.files }}" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
$uniqueName = ('${{ matrix.files }}' -replace '/', '_')
Write-Host "Got unique name '$uniqueName'"
echo "unique_name=$uniqueName" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
$cacheKey = "${uniqueName}_${{ hashFiles('**/scripts/nuke_source_from_dockerfile.ps1') }}"
Write-Host "Got cache key '$cacheKey'"
echo "cache_key=$cacheKey" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Get Nuke source files cache
id: cache_nuke_source
uses: actions/cache@v3
with:
path: C:\temp\nuke_source_files
key: ${{ steps.unique_name.outputs.cache_key }}
- name: Collect Nuke source files
if: steps.cache_nuke_source.outputs.cache-hit != 'true'
timeout-minutes: 30
shell: pwsh
run: |
$sourceFilesPath = "C:\temp\nuke_source_files"
Write-Host "Create temp dir for source files '$sourceFilesPath'"
New-Item -Type Directory -Path $sourceFilesPath | Out-Null
Write-Host "Starting collecting of source files'"
${{ github.workspace }}\scripts\nuke_source_from_dockerfile.ps1 "${{ matrix.files }}" "$sourceFilesPath"
- name: Create artifact tar
run: Compress-Archive -Path C:\temp\nuke_source_files -DestinationPath C:\temp\nuke_source_files.zip
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nuke_source_files_${{ steps.unique_name.outputs.unique_name}}
path: C:\temp\nuke_source_files.zip
build:
name: Build, test and push image
runs-on: windows-latest
needs: [get_nuke_sources]
permissions: write-all
env:
PUSH_LOCATION: "ghcr.io/gillesvink/nukedockerbuild"
strategy:
matrix:
files: ${{ fromJSON(needs.changed_dockerfiles.outputs.matrix) }}
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: nuke_source_files_${{ needs.get_nuke_sources.outputs.unique_name }}
path: C:\temp
- name: Prepare source files
shell: pwsh
run: |
$dockerfileDirectory=[System.IO.Path]::GetDirectoryName("${{ github.workspace }}\${{ needs.get_nuke_sources.outputs.filename }}")
echo "Directory set to $dockerfileDirectory"
Expand-Archive -Path C:\temp\nuke_source_files.zip -DestinationPath $dockerfileDirectory -Force
echo "dockerfile_directory=$dockerfileDirectory" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Build and export
shell: pwsh
run: |
cd ${{ env.dockerfile_directory }}
docker build . --tag nukedockerbuild:latest --build-arg="NUKE_SOURCE_FILES=nuke_source_files"
- name: Test image
shell: pwsh
run: |
mkdir C:\nuke_build_directory
docker run -v C:\nuke_build_directory:C:\nuke_build_directory `
nukedockerbuild:latest `
powershell -Command "cd C:\nuke_install\tests ; `
cmake . -DCMAKE_GENERATOR_PLATFORM=x64 -B C:\nuke_build_directory ; `
cmake --build C:\nuke_build_directory --config Release"
- name: Create artifact of test build
uses: actions/upload-artifact@v4
with:
name: test_build_${{ needs.get_nuke_sources.outputs.unique_name }}
path: C:\nuke_build_directory
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image
if: github.ref == 'refs/heads/main'
shell: pwsh
run: |
$dockerJSON = docker inspect --format '{{json .Config.Labels}}' nukedockerbuild:latest | ConvertFrom-Json
$nukeVersion = $dockerJSON | Select-Object -ExpandProperty "com.nukedockerbuild.nuke_version"
$operatingSystem = $dockerJSON | Select-Object -ExpandProperty "com.nukedockerbuild.operating_system"
$version = $dockerJSON | Select-Object -ExpandProperty "org.opencontainers.version"
$tag="$nukeVersion-$operatingSystem"
docker tag nukedockerbuild:latest ${{ env.PUSH_LOCATION }}:$tag-$version
docker tag nukedockerbuild:latest ${{ env.PUSH_LOCATION }}:$tag-latest
docker rmi nukedockerbuild:latest
docker image push ${{ env.PUSH_LOCATION }}:$tag-$version
docker image push ${{ env.PUSH_LOCATION }}:$tag-latest