Skip to content

Commit 5eb6540

Browse files
committed
sync-upstream-branches: turn the workflow into a matrix
The workflow still only handles the `git-gui` branches, but is now almost generic enough to become a matrix workflow that also handles the `gitster/git` synchronization. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 169d356 commit 5eb6540

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

.github/workflows/sync-upstream-branches.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1-
name: sync-git-gui-branches
1+
name: sync-upstream-branches
22

33
on:
44
schedule:
55
- cron: '31 22 * * *'
66
workflow_dispatch:
77

8-
env:
9-
SOURCE_REPOSITORY: j6t/git-gui
10-
TARGET_REPOSITORY: gitgitgadget/git
11-
TARGET_REF_NAMESPACE: git-gui/
12-
138
# We want to limit queuing to a single workflow run i.e. if there is already
149
# an active workflow run and a queued one, queue another one canceling the
1510
# already queued one.
1611
concurrency:
1712
group: ${{ github.workflow }}
1813

1914
jobs:
20-
sync-git-gui-branches:
15+
sync-upstream-branches:
2116
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
spec:
20+
- source-repo: j6t/git-gui
21+
target-repo: gitgitgadget/git
22+
target-ref-namespace: git-gui/
23+
2224
steps:
2325
- name: check which refs need to be synchronized
2426
uses: actions/github-script@v7
2527
id: check
2628
with:
2729
script: |
28-
const [targetRepoOwner, targetRepoName] = process.env.TARGET_REPOSITORY.split('/')
30+
const sourceRepo = ${{ toJSON(matrix.spec.source-repo) }}
31+
const targetRepo = ${{ toJSON(matrix.spec.target-repo) }}
32+
const targetRefNamespace = ${{ toJSON(matrix.spec.target-ref-namespace) }}
33+
34+
const [targetRepoOwner, targetRepoName] = targetRepo.split('/')
2935
core.setOutput('target-repo-owner', targetRepoOwner)
3036
core.setOutput('target-repo-name', targetRepoName)
3137
@@ -72,10 +78,10 @@ jobs:
7278
}
7379
}
7480
75-
const sourceRefs = await getRefs(process.env.SOURCE_REPOSITORY)
76-
const targetRefs = await getRefs(process.env.TARGET_REPOSITORY, process.env.TARGET_REF_NAMESPACE)
81+
const sourceRefs = await getRefs(sourceRepo)
82+
const targetRefs = await getRefs(targetRepo, targetRefNamespace)
7783
78-
const targetPrefix = `refs/heads/${process.env.TARGET_REF_NAMESPACE}`
84+
const targetPrefix = targetRefNamespace ? `refs/heads/${targetRefNamespace}` : 'refs/heads/'
7985
8086
const refspecs = []
8187
const toFetch = new Set()
@@ -138,7 +144,7 @@ jobs:
138144
set -ex
139145
git init --bare
140146
141-
git remote add source "${{ github.server_url }}/$SOURCE_REPOSITORY"
147+
git remote add source '${{ github.server_url }}/${{ matrix.spec.source-repo }}'
142148
# pretend to be a partial clone
143149
git config remote.source.promisor true
144150
git config remote.source.partialCloneFilter blob:none
@@ -151,4 +157,4 @@ jobs:
151157
# push the commits
152158
printf '%s' '${{ steps.check.outputs.refspec }}' |
153159
xargs -d ' ' -r git -c http.extraHeader='${{ steps.auth.outputs.header }}' \
154-
push "${{ github.server_url }}/$TARGET_REPOSITORY"
160+
push '${{ github.server_url }}/${{ matrix.spec.target-repo }}'

0 commit comments

Comments
 (0)