Skip to content

Commit 800a9e6

Browse files
committed
CI: Factorize Github labels checks
1 parent d1914a8 commit 800a9e6

File tree

1 file changed

+37
-52
lines changed

1 file changed

+37
-52
lines changed

.github/workflows/main.yml

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,37 @@ jobs:
6464
run: |
6565
./CI/check-cmake.sh
6666
67+
config:
68+
name: '01 - Configure Build Jobs'
69+
runs-on: [ubuntu-22.04]
70+
env:
71+
IS_PULL_REQUEST: ${{ github.event_name == 'pull_request' }}
72+
outputs:
73+
create_artifacts: ${{ steps.config.outputs.create_artifacts }}
74+
cache_date: ${{ steps.config.outputs.cache_date }}
75+
steps:
76+
- name: 'Configure Build Jobs'
77+
id: config
78+
run: |
79+
if [[ "$IS_PULL_REQUEST" == "true" ]]; then
80+
if test -n "$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -s "${{ github.event.pull_request.url }}" | jq -e '.labels[] | select(.name == "Seeking Testers")')"; then
81+
echo 'create_artifacts=true' >> $GITHUB_OUTPUT
82+
else
83+
echo 'create_artifacts=false' >> $GITHUB_OUTPUT
84+
fi
85+
else
86+
echo 'create_artifacts=true' >> $GITHUB_OUTPUT
87+
fi
88+
echo "cache_date=$(date +"%Y-%m-%d")" >> $GITHUB_OUTPUT
89+
6790
macos_build:
6891
name: '02 - macOS'
6992
runs-on: [macos-12]
7093
strategy:
7194
matrix:
7295
arch: ['x86_64', 'arm64']
7396
if: always()
74-
needs: [clang_check]
97+
needs: [config, clang_check]
7598
env:
7699
MACOSX_DEPLOYMENT_TARGET_X86_64: '10.15'
77100
MACOSX_DEPLOYMENT_TARGET_ARM64: '11.0'
@@ -92,25 +115,14 @@ jobs:
92115
path: 'obs-studio'
93116
fetch-depth: 0
94117

95-
- name: 'Check for Github Labels'
96-
if: github.event_name == 'pull_request'
97-
run: |
98-
if test -n "$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -s "${{ github.event.pull_request.url }}" | jq -e '.labels[] | select(.name == "Seeking Testers")')"; then
99-
echo "SEEKING_TESTERS=1" >> $GITHUB_ENV
100-
else
101-
echo "SEEKING_TESTERS=0" >> $GITHUB_ENV
102-
fi
103-
104-
echo "CACHE_DATE=$(date +"%Y-%m-%d")" >> $GITHUB_ENV
105-
106118
- name: 'Restore ccache from cache'
107119
id: ccache-cache
108120
uses: actions/cache@v3
109121
env:
110122
CACHE_NAME: 'ccache-cache'
111123
with:
112124
path: ${{ github.workspace }}/.ccache
113-
key: ${{ runner.os }}-pr-${{ env.CACHE_NAME }}-${{ matrix.arch }}-${{ env.CACHE_DATE }}
125+
key: ${{ runner.os }}-pr-${{ env.CACHE_NAME }}-${{ matrix.arch }}-${{ needs.config.outputs.cache_date }}
114126

115127
- name: 'Restore Chromium Embedded Framework from cache'
116128
id: cef-cache
@@ -186,14 +198,14 @@ jobs:
186198
run: cmake --build build -t test
187199

188200
- name: 'Create build artifact'
189-
if: ${{ success() && (github.event_name != 'pull_request' || env.SEEKING_TESTERS == '1') }}
201+
if: ${{ success() && fromJSON(needs.config.outputs.create_artifacts) }}
190202
run: |
191203
CI/macos/03_package_obs.sh --codesign --architecture "${{ matrix.arch }}"
192204
ARTIFACT_NAME=$(basename $(/usr/bin/find build -type f -name "obs-studio-*.dmg" -depth 1 | head -1))
193205
echo "FILE_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
194206
195207
- name: 'Upload build Artifact'
196-
if: ${{ success() && (github.event_name != 'pull_request' || env.SEEKING_TESTERS == '1') }}
208+
if: ${{ success() && fromJSON(needs.config.outputs.create_artifacts) }}
197209
uses: actions/upload-artifact@v3
198210
with:
199211
name: 'obs-studio-macos-${{ matrix.arch }}-${{ steps.setup.outputs.commitHash }}'
@@ -206,7 +218,7 @@ jobs:
206218
matrix:
207219
ubuntu: ['ubuntu-20.04', 'ubuntu-22.04']
208220
if: always()
209-
needs: [clang_check]
221+
needs: [config, clang_check]
210222
defaults:
211223
run:
212224
shell: bash
@@ -221,25 +233,14 @@ jobs:
221233
path: 'obs-studio'
222234
fetch-depth: 0
223235

224-
- name: 'Check for Github Labels'
225-
if: github.event_name == 'pull_request'
226-
run: |
227-
if test -n "$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -s "${{ github.event.pull_request.url }}" | jq -e '.labels[] | select(.name == "Seeking Testers")')"; then
228-
echo "SEEKING_TESTERS=1" >> $GITHUB_ENV
229-
else
230-
echo "SEEKING_TESTERS=0" >> $GITHUB_ENV
231-
fi
232-
233-
echo "CACHE_DATE=$(date +"%Y-%m-%d")" >> $GITHUB_ENV
234-
235236
- name: 'Restore ccache from cache'
236237
id: ccache-cache
237238
uses: actions/cache@v3
238239
env:
239240
CACHE_NAME: 'ccache-cache'
240241
with:
241242
path: ${{ github.workspace }}/.ccache
242-
key: ${{ runner.os }}-pr-${{ env.CACHE_NAME }}-${{ matrix.ubuntu }}-${{ env.CACHE_DATE }}
243+
key: ${{ runner.os }}-pr-${{ env.CACHE_NAME }}-${{ matrix.ubuntu }}-${{ needs.config.outputs.cache_date }}
243244

244245
- name: 'Restore Chromium Embedded Framework from cache'
245246
id: cef-cache
@@ -268,22 +269,22 @@ jobs:
268269
run: cmake --build build -t test
269270

270271
- name: 'Create build artifact'
271-
if: ${{ success() && (github.event_name != 'pull_request' || env.SEEKING_TESTERS == '1') }}
272+
if: ${{ success() && fromJSON(needs.config.outputs.create_artifacts) }}
272273
run: |
273274
CI/linux/03_package_obs.sh
274275
ARTIFACT_NAME=$(basename $(/usr/bin/find build -maxdepth 1 -type f -name "obs-studio-*.deb" | sort -rn | head -1))
275276
echo "FILE_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
276277
echo "DEBUG_FILE_NAME=${ARTIFACT_NAME//.deb/-dbgsym.ddeb}" >> $GITHUB_ENV
277278
278279
- name: 'Upload build Artifact'
279-
if: ${{ success() && (github.event_name != 'pull_request' || env.SEEKING_TESTERS == '1') }}
280+
if: ${{ success() && fromJSON(needs.config.outputs.create_artifacts) }}
280281
uses: actions/upload-artifact@v3
281282
with:
282283
name: 'obs-studio-${{ matrix.ubuntu }}-${{ steps.setup.outputs.commitHash }}'
283284
path: '${{ github.workspace }}/obs-studio/build/${{ env.FILE_NAME }}'
284285

285286
- name: 'Upload debug symbol Artifact'
286-
if: ${{ success() && (github.event_name != 'pull_request' || env.SEEKING_TESTERS == '1') }}
287+
if: ${{ success() && fromJSON(needs.config.outputs.create_artifacts) }}
287288
uses: actions/upload-artifact@v3
288289
with:
289290
name: 'obs-studio-${{ matrix.ubuntu }}-${{ steps.setup.outputs.commitHash }}-dbgsym'
@@ -292,7 +293,7 @@ jobs:
292293
windows_build:
293294
name: '02 - Windows'
294295
runs-on: [windows-2022]
295-
needs: [clang_check]
296+
needs: [config, clang_check]
296297
if: always()
297298
strategy:
298299
matrix:
@@ -316,12 +317,6 @@ jobs:
316317
- name: 'Add msbuild to PATH'
317318
uses: microsoft/[email protected]
318319

319-
- name: 'Check for Github Labels'
320-
if: github.event_name == 'pull_request'
321-
run: |
322-
$LabelFound = try { (Invoke-RestMethod -Authentication 'Bearer' -Token (ConvertTo-SecureString '${{ secrets.GITHUB_TOKEN }}' -AsPlainText) -Uri "${{ github.event.pull_request.url }}" -UseBasicParsing).labels.name.contains("Seeking Testers") } catch { $false }
323-
Write-Output "SEEKING_TESTERS=$(if( $LabelFound -eq $true ) { 1 } else { 0 })" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
324-
325320
- name: 'Restore VLC dependency from cache'
326321
id: vlc-cache
327322
uses: actions/cache@v3
@@ -356,14 +351,14 @@ jobs:
356351
run: CI/windows/02_build_obs.ps1 -BuildArch ${{ matrix.arch }}
357352

358353
- name: 'Create build artifact'
359-
if: ${{ success() && (github.event_name != 'pull_request' || env.SEEKING_TESTERS == '1') }}
354+
if: ${{ success() && fromJSON(needs.config.outputs.create_artifacts) }}
360355
run: |
361356
CI/windows/03_package_obs.ps1 -BuildArch ${{ matrix.arch }} -Package
362357
$ArtifactName = Get-ChildItem -filter "obs-studio-*-windows-${{ matrix.arch }}.zip" -File
363358
Write-Output "FILE_NAME=${ArtifactName}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
364359
365360
- name: 'Upload build artifact'
366-
if: ${{ success() && (github.event_name != 'pull_request' || env.SEEKING_TESTERS == '1') }}
361+
if: ${{ success() && fromJSON(needs.config.outputs.create_artifacts) }}
367362
uses: actions/upload-artifact@v3
368363
with:
369364
name: 'obs-studio-windows-${{ matrix.arch }}-${{ steps.setup.outputs.commitHash }}'
@@ -372,24 +367,14 @@ jobs:
372367
linux_package:
373368
name: '02 - Flatpak'
374369
runs-on: [ubuntu-latest]
375-
needs: [clang_check]
376-
if: always()
370+
needs: [config, clang_check]
377371
defaults:
378372
run:
379373
shell: bash
380374
container:
381375
image: bilelmoussaoui/flatpak-github-actions:kde-6.4
382376
options: --privileged
383377
steps:
384-
- name: 'Check for Github Labels'
385-
if: github.event_name == 'pull_request'
386-
run: |
387-
if ! /usr/bin/command -v "jq" >/dev/null 2>&1; then sudo dnf install -y -q jq; fi
388-
if test -n "$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -s "${{ github.event.pull_request.url }}" | jq -e '.labels[] | select(.name == "Seeking Testers")')"; then
389-
echo "SEEKING_TESTERS=1" >> $GITHUB_ENV
390-
else
391-
echo "SEEKING_TESTERS=0" >> $GITHUB_ENV
392-
fi
393378

394379
- name: 'Checkout'
395380
uses: actions/checkout@v3
@@ -407,7 +392,7 @@ jobs:
407392
- name: Build Flatpak Manifest
408393
uses: flatpak/flatpak-github-actions/flatpak-builder@v5
409394
with:
410-
build-bundle: ${{ github.event_name != 'pull_request' || env.SEEKING_TESTERS == '1' }}
395+
build-bundle: ${{ fromJSON(needs.config.outputs.create_artifacts) }}
411396
bundle: obs-studio-flatpak-${{ env.OBS_GIT_HASH }}.flatpak
412397
manifest-path: CI/flatpak/com.obsproject.Studio.json
413398
cache-key: flatpak-builder-${{ hashFiles('CI/flatpak/com.obsproject.Studio.json') }}

0 commit comments

Comments
 (0)