Skip to content

Commit 041c32f

Browse files
authored
Merge pull request #726 from CommunityToolkit/ci/scheduled/tag-triggers
Use tag-based trigger for scheduled release build
2 parents 7005cc7 + 5e8239a commit 041c32f

2 files changed

Lines changed: 32 additions & 62 deletions

File tree

.github/workflows/build.yml

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,13 @@ on:
99
# Triggers the workflow on push or pull request events but only for the main branch
1010
push:
1111
branches: [ main ]
12+
tags: [ 'release/weekly/*' ]
1213
pull_request:
1314
branches: [ main ]
1415

1516
# Allows you to run this workflow manually from the Actions tab
1617
workflow_dispatch:
1718
merge_group:
18-
19-
# Allow this workflow to be called as a reusable workflow
20-
workflow_call:
21-
inputs:
22-
commit_range_start:
23-
description: 'The start commit of the range to check for incremental builds.'
24-
type: string
25-
required: false
26-
commit_range_end:
27-
description: 'The end commit of the range to check for incremental builds.'
28-
type: string
29-
required: false
30-
is_scheduled:
31-
description: 'A boolean value that indicates whether this is a scheduled run.'
32-
type: boolean
33-
required: false
3419

3520
env:
3621
DOTNET_VERSION: ${{ '9.0.x' }}
@@ -59,7 +44,7 @@ jobs:
5944
uses: actions/checkout@v4
6045
with:
6146
submodules: recursive
62-
ref: ${{ inputs.commit_range_end || github.sha }}
47+
ref: ${{ github.sha }}
6348
fetch-depth: 0
6449
fetch-tags: true
6550

@@ -100,13 +85,23 @@ jobs:
10085
uses: actions/checkout@v4
10186
with:
10287
submodules: recursive
103-
ref: ${{ inputs.commit_range_end || github.sha }}
88+
ref: ${{ github.sha }}
10489
fetch-depth: 0
10590
fetch-tags: true
91+
92+
- name: Determine scheduled release commit range
93+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
94+
id: range
95+
shell: pwsh
96+
run: |
97+
# Previous weekly tag (2nd newest); fallback to main's HEAD
98+
$prevTag = git tag --list 'release/weekly/*' --sort=-creatordate | Select-Object -Skip 1 -First 1
99+
$tagSha = [string]::IsNullOrWhiteSpace($prevTag) ? (git rev-parse 'origin/main').Trim() : (git rev-list -n 1 $prevTag).Trim()
100+
"PREV_TAG_COMMIT=$tagSha" >> $env:GITHUB_ENV
106101
107102
- name: Get changed components
108103
run: |
109-
$changedComponents = $(./tooling/Get-Changed-Components.ps1 ${{ inputs.commit_range_start || github.event.before }} ${{ inputs.commit_range_end || github.event.after }})
104+
$changedComponents = $(./tooling/Get-Changed-Components.ps1 ${{ env.PREV_TAG_COMMIT || github.event.before }} ${{ github.sha || github.event.after }})
110105
$buildableChangedComponents = $(./tooling/MultiTarget/Filter-Supported-Components.ps1 -Components $changedComponents -MultiTargets ${{ matrix.multitarget }} -WinUIMajorVersion ${{ matrix.winui }})
111106
echo "CHANGED_COMPONENTS_LIST=$(($buildableChangedComponents | ForEach-Object { "$_" }) -join ',')" >> $env:GITHUB_ENV
112107
echo "HAS_BUILDABLE_COMPONENTS=$($buildableChangedComponents.Count -gt 0)" >> $env:GITHUB_ENV
@@ -266,7 +261,7 @@ jobs:
266261
uses: actions/checkout@v4
267262
with:
268263
submodules: recursive
269-
ref: ${{ inputs.commit_range_end || github.sha }}
264+
ref: ${{ github.sha }}
270265
fetch-depth: 0
271266
fetch-tags: true
272267

@@ -292,10 +287,20 @@ jobs:
292287
uses: microsoft/setup-msbuild@v2
293288
with:
294289
vs-version: '[17.9,)'
295-
# Get changed components
290+
291+
- name: Determine scheduled release commit range
292+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
293+
id: range
294+
shell: pwsh
295+
run: |
296+
# Previous weekly tag (2nd newest); fallback to main's HEAD
297+
$prevTag = git tag --list 'release/weekly/*' --sort=-creatordate | Select-Object -Skip 1 -First 1
298+
$tagSha = [string]::IsNullOrWhiteSpace($prevTag) ? (git rev-parse 'origin/main').Trim() : (git rev-list -n 1 $prevTag).Trim()
299+
"PREV_TAG_COMMIT=$tagSha" >> $env:GITHUB_ENV
300+
296301
- name: Get changed components
297302
run: |
298-
$changedComponents = $(./tooling/Get-Changed-Components.ps1 ${{ inputs.commit_range_start || github.event.before }} ${{ inputs.commit_range_end || github.event.after }})
303+
$changedComponents = $(./tooling/Get-Changed-Components.ps1 ${{ env.PREV_TAG_COMMIT || github.event.before }} ${{ github.event.after || github.sha }})
299304
$buildableChangedComponents = $(./tooling/MultiTarget/Filter-Supported-Components.ps1 -Components $changedComponents -MultiTargets "all" -WinUIMajorVersion ${{ matrix.winui }})
300305
echo "CHANGED_COMPONENTS_LIST=$(($buildableChangedComponents | ForEach-Object { "$_" }) -join ',')" >> $env:GITHUB_ENV
301306
echo "HAS_BUILDABLE_COMPONENTS=$($buildableChangedComponents.Count -gt 0)" >> $env:GITHUB_ENV
@@ -354,7 +359,7 @@ jobs:
354359

355360
sign:
356361
needs: [package]
357-
if: ${{ startsWith(github.ref, 'refs/heads/rel/') || inputs.is_scheduled }}
362+
if: ${{ startsWith(github.ref, 'refs/heads/rel/') || startsWith(github.ref, 'refs/tags/') }}
358363
runs-on: windows-latest
359364
permissions:
360365
id-token: write # Required for requesting the JWT
@@ -411,15 +416,15 @@ jobs:
411416
412417
- name: Upload Signed Packages as Artifacts (for release)
413418
uses: actions/upload-artifact@v4
414-
if: ${{ startsWith(github.ref, 'refs/heads/rel/') || inputs.is_scheduled }}
419+
if: ${{ startsWith(github.ref, 'refs/heads/rel/') || startsWith(github.ref, 'refs/tags/') }}
415420
with:
416421
name: signed-nuget-packages-${{ matrix.winui }}
417422
if-no-files-found: error
418423
path: |
419424
${{ github.workspace }}/packages/**/*.nupkg
420425
421426
release:
422-
if: ${{ startsWith(github.ref, 'refs/heads/rel/') || inputs.is_scheduled }}
427+
if: ${{ startsWith(github.ref, 'refs/heads/rel/') || startsWith(github.ref, 'refs/tags/') }}
423428
needs: [sign]
424429
environment: nuget-release-gate # This gates this job until manually approved
425430
runs-on: ubuntu-latest
@@ -469,7 +474,7 @@ jobs:
469474
uses: actions/checkout@v4
470475
with:
471476
submodules: recursive
472-
ref: ${{ inputs.commit_range_end || github.sha }}
477+
ref: ${{ github.sha }}
473478
fetch-depth: 0
474479
fetch-tags: true
475480

.github/workflows/scheduled-releases.yml

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ jobs:
1313
runs-on: ubuntu-latest
1414
permissions:
1515
contents: write
16-
outputs:
17-
commit_range_start: ${{ steps.range.outputs.commit_range_start }}
18-
commit_range_end: ${{ steps.range.outputs.commit_range_end }}
1916

2017
steps:
2118
- name: Checkout repository
@@ -37,36 +34,4 @@ jobs:
3734
TAG="release/weekly/$(date +%y%m%d)"
3835
git tag -a "$TAG" -m "Release $TAG"
3936
git push origin "$TAG"
40-
echo "TAG=$TAG" >> $GITHUB_OUTPUT
41-
42-
- name: Determine commit range
43-
id: range
44-
run: |
45-
# New tag we just created
46-
NEW_TAG=${{ steps.create-tag.outputs.TAG }}
47-
48-
# Find the previous tag (sorted newest‑first)
49-
PREV_TAG=$(git tag --list "release/weekly/*" --sort=-creatordate | sed -n '2p')
50-
51-
# If we’re on the very first tag, fall back to main
52-
if [ -z "$PREV_TAG" ]; then
53-
PREV_TAG=main
54-
fi
55-
56-
# Resolve the commit hashes
57-
START_COMMIT=$(git rev-parse "$PREV_TAG")
58-
END_COMMIT=$(git rev-parse "$NEW_TAG")
59-
60-
# Export them as workflow outputs
61-
echo "commit_range_start=$START_COMMIT" >> $GITHUB_OUTPUT
62-
echo "commit_range_end=$END_COMMIT" >> $GITHUB_OUTPUT
63-
64-
# Then trigger the build workflow with the commit range.
65-
trigger-build:
66-
needs: tag-weekly-release
67-
uses: ./.github/workflows/build.yml
68-
with:
69-
commit_range_start: ${{ needs.tag-weekly-release.outputs.commit_range_start }}
70-
commit_range_end: ${{ needs.tag-weekly-release.outputs.commit_range_end }}
71-
is_scheduled: true
72-
secrets: inherit
37+

0 commit comments

Comments
 (0)