Skip to content

Commit 42bc2c2

Browse files
committed
bug: Finish set_executable_ownership_in_ci
Finishing how the tar files are created in github CI to fix permissions/ownership when extracting as root user. [#158]
2 parents dd79eb1 + 25f9fc3 commit 42bc2c2

File tree

1 file changed

+51
-11
lines changed

1 file changed

+51
-11
lines changed

.github/workflows/meson.yml

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: CI for meson build
44
on:
55
push:
66
branches: [ develop, master, release/*, feature/*, hotfix/* ]
7-
tags: [ v* ]
7+
tags: [ v*, test-ci* ]
88
pull_request:
99
branches: [ develop ]
1010

@@ -223,7 +223,35 @@ jobs:
223223
if: startsWith(matrix.config.name, 'Windows Clang')
224224
run: |
225225
$headers = @{ Authorization = 'Bearer ${{ secrets.GITHUB_TOKEN }}' }
226-
echo "LLVM_RELID=$((Invoke-WebRequest -Headers $headers 'https://api.github.com/repos/llvm/llvm-project/releases/latest').Content | ConvertFrom-Json | Select-Object -ExpandProperty id)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
226+
$latestRelease = Invoke-WebRequest -Headers $headers 'https://api.github.com/repos/llvm/llvm-project/releases/latest'
227+
$releaseData = $latestRelease.Content | ConvertFrom-Json
228+
$assets = $releaseData.assets | Where-Object { $_.name -like "*win64.exe" }
229+
230+
if ($assets) {
231+
$downloadUrl = $assets.browser_download_url
232+
echo "LLVM_RELID=$($releaseData.id)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
233+
echo "LLVM_DOWNLOAD_URL=$downloadUrl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
234+
} else {
235+
Write-Host "No current Windows build available for the latest release. Searching for previous releases..."
236+
$releases = Invoke-WebRequest -Headers $headers 'https://api.github.com/repos/llvm/llvm-project/releases'
237+
$found = $false
238+
239+
foreach ($release in $releases.Content | ConvertFrom-Json) {
240+
$assets = $release.assets | Where-Object { $_.name -like "*win64.exe" }
241+
if ($assets) {
242+
$downloadUrl = $assets.browser_download_url
243+
echo "LLVM_RELID=$($release.id)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
244+
echo "LLVM_DOWNLOAD_URL=$downloadUrl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
245+
$found = $true
246+
break
247+
}
248+
}
249+
250+
if (-not $found) {
251+
Write-Host "No Windows build available for any recent releases."
252+
exit 0
253+
}
254+
}
227255
228256
- name: Restore LLVM from cache
229257
if: startsWith(matrix.config.name, 'Windows Clang')
@@ -260,14 +288,6 @@ jobs:
260288
meson setup build -Dprefix=/ -Dmandir=/man -Dbindir=/ ${{ matrix.config.meson_opts }} --buildtype=release
261289
meson install -C build
262290
263-
- name: Packing release
264-
env:
265-
ARCHIVE_EXT: ${{ matrix.config.release_extension }}
266-
run: |
267-
cd build
268-
${{ matrix.config.archive_command }} "${DESTDIR}${ARCHIVE_EXT}" $DESTDIR
269-
shell: bash
270-
271291
# add `GOBIN` to the `PATH` otherwise nfpm in next step can't be found
272292
- uses: actions/setup-go@v5
273293
if: ${{ matrix.config.create_package }}
@@ -290,6 +310,26 @@ jobs:
290310
nfpm package -f ../../nfpm.yaml -p rpm -t ..
291311
shell: bash
292312

313+
- name: Set ownership of executables to root:root
314+
if: ${{ matrix.config.os != 'windows-latest' }}
315+
run: sudo chown -R root:root build
316+
317+
- name: Packing release
318+
env:
319+
ARCHIVE_EXT: ${{ matrix.config.release_extension }}
320+
run: |
321+
cd build
322+
if [[ "${{ matrix.config.os }}" != "windows-latest" ]]; then
323+
sudo ${{ matrix.config.archive_command }} "${DESTDIR}${ARCHIVE_EXT}" $DESTDIR
324+
else
325+
${{ matrix.config.archive_command }} "${DESTDIR}${ARCHIVE_EXT}" $DESTDIR
326+
fi
327+
shell: bash
328+
329+
- name: Set ownership of tar archive to root:root
330+
if: ${{ matrix.config.os != 'windows-latest' }}
331+
run: sudo chown root:root build/"${DESTDIR}${ARCHIVE_EXT}"
332+
293333
- name: Generate Hashes
294334
if: ${{ matrix.config.publish_release }}
295335
shell: bash
@@ -314,7 +354,7 @@ jobs:
314354
build/*.rpm
315355
316356
- name: Publish release
317-
if: ${{ startsWith(github.ref, 'refs/tags/v') && matrix.config.publish_release }}
357+
if: ${{ (startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/tags/test-ci')) && matrix.config.publish_release }}
318358
uses: softprops/action-gh-release@v2
319359
with:
320360
files: |

0 commit comments

Comments
 (0)