Skip to content

Commit 9af748f

Browse files
committed
Refactor update-and-rebase workflow for efficiency and reliability
Replace step-level skip checks with a dynamic matrix that only includes selected branches, ensuring proper UI status. Changes: - Add prepare job that queries upstream tags via git ls-remote without cloning the massive kernel repo - Switch from gh workflow run to workflow_call for triggering builds (workflow_dispatch rejects dynamic branch names with type: choice) - Fetch only the specific branch and tag needed per rebase job - Use separate build jobs with !cancelled() condition so builds proceed even if some rebases fail Signed-off-by: Ian May <ianm@nvidia.com>
1 parent d3a175c commit 9af748f

File tree

1 file changed

+85
-66
lines changed

1 file changed

+85
-66
lines changed

.github/workflows/update-and-rebase.yml

Lines changed: 85 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,99 +10,118 @@ on:
1010
required: false
1111
type: choice
1212
options:
13+
- ''
1314
- linux-nvidia-6.6
1415
- linux-nvidia-6.12
1516
- linux-nvidia-6.18
1617

1718
jobs:
18-
update-rebase-branch:
19+
prepare:
1920
runs-on: ubuntu-latest
20-
strategy:
21-
fail-fast: false
22-
matrix:
23-
branch:
24-
- linux-nvidia-6.6
25-
- linux-nvidia-6.12
26-
- linux-nvidia-6.18
21+
outputs:
22+
matrix: ${{ steps.set-matrix.outputs.matrix }}
2723
steps:
28-
- name: Check if branch should be processed
29-
id: check
24+
- name: Build matrix
25+
id: set-matrix
3026
run: |
31-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
32-
# Skip only if a specific branch was selected AND it's not this one
33-
# Empty means process all branches
34-
if [ -n "${{ inputs.branch }}" ] && [ "${{ inputs.branch }}" != "${{ matrix.branch }}" ]; then
35-
echo "skip=true" >> $GITHUB_OUTPUT
36-
else
37-
echo "skip=false" >> $GITHUB_OUTPUT
38-
fi
27+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ inputs.branch }}" ]; then
28+
branches='${{ inputs.branch }}'
3929
else
40-
echo "skip=false" >> $GITHUB_OUTPUT
30+
branches='linux-nvidia-6.6 linux-nvidia-6.12 linux-nvidia-6.18'
4131
fi
4232
43-
- name: Checkout target branch
44-
if: steps.check.outputs.skip != 'true'
45-
uses: actions/checkout@v4
46-
with:
47-
ref: ${{ matrix.branch }}
48-
fetch-depth: 0
49-
50-
- name: Add upstream remote (if not exists)
51-
if: steps.check.outputs.skip != 'true'
52-
run: |
53-
if ! git remote | grep -q upstream; then
54-
git remote add upstream https://github.com/gregkh/linux.git
55-
fi
33+
matrix='{"include":['
34+
first=true
35+
for branch in $branches; do
36+
version=$(echo "$branch" | sed 's/^linux-nvidia-//')
5637
57-
- name: Fetch upstream tags
58-
if: steps.check.outputs.skip != 'true'
59-
run: git fetch upstream --tags --force
38+
# Query tags remotely without fetching
39+
tag=$(git ls-remote --tags https://github.com/gregkh/linux.git "v${version}.*" | \
40+
grep -v '\^{}' | \
41+
sed 's|.*/||' | \
42+
sort -V | \
43+
tail -1)
6044
61-
- name: Find latest stable tag for branch
62-
if: steps.check.outputs.skip != 'true'
63-
id: latest_tag
45+
if [ "$first" = true ]; then
46+
first=false
47+
else
48+
matrix+=','
49+
fi
50+
matrix+="{\"branch\":\"$branch\",\"tag\":\"$tag\"}"
51+
done
52+
matrix+=']}'
53+
54+
echo "matrix=$matrix" >> $GITHUB_OUTPUT
55+
56+
update-rebase-branch:
57+
needs: prepare
58+
runs-on: ubuntu-latest
59+
strategy:
60+
fail-fast: false
61+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
62+
outputs:
63+
branch-6-6: ${{ steps.mark-success.outputs.branch-6-6 }}
64+
branch-6-12: ${{ steps.mark-success.outputs.branch-6-12 }}
65+
branch-6-18: ${{ steps.mark-success.outputs.branch-6-18 }}
66+
steps:
67+
- name: Checkout target branch
6468
run: |
65-
version=$(echo "${{ matrix.branch }}" | sed 's/^linux-nvidia-//')
66-
tag=$(git describe --abbrev=0 --tags upstream/linux-${version}.y)
67-
echo "tag=$tag" >> $GITHUB_OUTPUT
69+
git init -q
70+
git remote add origin https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git
71+
git fetch origin ${{ matrix.branch }}
72+
git checkout -b ${{ matrix.branch }} origin/${{ matrix.branch }}
6873
69-
- name: Fetch patch branch
70-
if: steps.check.outputs.skip != 'true'
71-
run: git fetch origin ${{ matrix.branch }}
74+
- name: Fetch upstream tag
75+
run: |
76+
git remote add upstream https://github.com/gregkh/linux.git
77+
git fetch upstream tag ${{ matrix.tag }} --no-tags
7278
73-
- name: Find merge base between patch branch and updated LTS
74-
if: steps.check.outputs.skip != 'true'
79+
- name: Find merge base
7580
id: merge_base
7681
run: |
77-
base=$(git merge-base origin/${{ matrix.branch }} ${{ steps.latest_tag.outputs.tag }})
82+
base=$(git merge-base HEAD ${{ matrix.tag }})
7883
echo "base=$base" >> $GITHUB_OUTPUT
7984
80-
- name: Create new branch for rebased patches
81-
if: steps.check.outputs.skip != 'true'
85+
- name: Create rebased branch
8286
run: |
83-
git checkout -b ${{ matrix.branch }}-${{ steps.latest_tag.outputs.tag }} origin/${{ matrix.branch }}
87+
git checkout -b ${{ matrix.branch }}-${{ matrix.tag }}
8488
8589
- name: Set git user identity
86-
if: steps.check.outputs.skip != 'true'
8790
run: |
88-
git config --local user.name "github-actions[bot]"
89-
git config --local user.email "github-actions[bot]@users.noreply.github.com"
91+
git config user.name "github-actions[bot]"
92+
git config user.email "github-actions[bot]@users.noreply.github.com"
9093
91-
- name: Rebase patch branch onto updated LTS
92-
if: steps.check.outputs.skip != 'true'
94+
- name: Rebase onto upstream tag
9395
run: |
94-
git rebase --onto ${{ steps.latest_tag.outputs.tag }} ${{ steps.merge_base.outputs.base }}
96+
git rebase --onto ${{ matrix.tag }} ${{ steps.merge_base.outputs.base }}
9597
96-
- name: Push rebased patch branch
97-
if: steps.check.outputs.skip != 'true'
98+
- name: Push rebased branch
9899
run: |
99-
git push --force origin HEAD:${{ matrix.branch }}-${{ steps.latest_tag.outputs.tag }}
100+
git push --force origin HEAD:${{ matrix.branch }}-${{ matrix.tag }}
100101
101-
- name: Trigger kernel build for rebased branch
102-
if: steps.check.outputs.skip != 'true'
103-
env:
104-
GH_TOKEN: ${{ github.token }}
102+
- name: Mark rebase successful
103+
id: mark-success
105104
run: |
106-
gh workflow run kernel-build.yml \
107-
--ref github-actions \
108-
-f branch=${{ matrix.branch }}-${{ steps.latest_tag.outputs.tag }}
105+
key=$(echo "${{ matrix.branch }}" | sed 's/linux-nvidia-/branch-/' | tr '.' '-')
106+
echo "${key}=${{ matrix.branch }}-${{ matrix.tag }}" >> $GITHUB_OUTPUT
107+
108+
build-6-6:
109+
needs: [prepare, update-rebase-branch]
110+
if: ${{ !cancelled() && needs.update-rebase-branch.outputs.branch-6-6 != '' }}
111+
uses: ./.github/workflows/kernel-build.yml
112+
with:
113+
branch: ${{ needs.update-rebase-branch.outputs.branch-6-6 }}
114+
115+
build-6-12:
116+
needs: [prepare, update-rebase-branch]
117+
if: ${{ !cancelled() && needs.update-rebase-branch.outputs.branch-6-12 != '' }}
118+
uses: ./.github/workflows/kernel-build.yml
119+
with:
120+
branch: ${{ needs.update-rebase-branch.outputs.branch-6-12 }}
121+
122+
build-6-18:
123+
needs: [prepare, update-rebase-branch]
124+
if: ${{ !cancelled() && needs.update-rebase-branch.outputs.branch-6-18 != '' }}
125+
uses: ./.github/workflows/kernel-build.yml
126+
with:
127+
branch: ${{ needs.update-rebase-branch.outputs.branch-6-18 }}

0 commit comments

Comments
 (0)