Skip to content

Commit 039ebd7

Browse files
authored
Merge pull request #12 from gitgitgadget/consolidate-sync-branches-workflows
Consolidate the `sync-*` workflows
2 parents 8e3ff0b + 3c327fc commit 039ebd7

File tree

4 files changed

+46
-177
lines changed

4 files changed

+46
-177
lines changed

.github/workflows/sync-gitster-git.yml

Lines changed: 0 additions & 140 deletions
This file was deleted.

.github/workflows/sync-git-mailing-list-mirror.yml renamed to .github/workflows/sync-mailing-list-mirror.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
name: sync-git-mailing-list-mirror
1+
name: sync-mailing-list-mirror
22

33
on:
44
workflow_dispatch:
55
schedule:
6-
- cron: "2,7,12,17,22,27,32,37,42,47,52,57 * * * *"
6+
- cron: "*/5 * * * *"
77

88
env:
99
LORE_EPOCH: 1 # also adjust SOURCE_REPOSITORY
1010
SOURCE_REPOSITORY: https://lore.kernel.org/git/1 # LORE_EPOCH
1111
TARGET_GITHUB_REPOSITORY: gitgitgadget/git-mailing-list-mirror
1212

1313
concurrency:
14-
group: sync-git-mailing-list-mirror
14+
group: sync-mailing-list-mirror
1515
cancel-in-progress: true
1616

1717
jobs:
18-
sync-git-mailing-list-mirror:
18+
sync-mailing-list-mirror:
1919
runs-on: ubuntu-latest
2020
permissions:
2121
contents: write

.github/workflows/sync-git-gui.yml renamed to .github/workflows/sync-upstream-branches.yml

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
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+
- sourceRepo: j6t/git-gui
21+
targetRepo: gitgitgadget/git
22+
targetRefNamespace: git-gui/
23+
- sourceRepo: gitster/git
24+
targetRepo: gitgitgadget/git
25+
sourceRefRegex: "^refs/heads/(maint-\\d|[a-z][a-z]/)"
26+
2227
steps:
2328
- name: check which refs need to be synchronized
2429
uses: actions/github-script@v7
2530
id: check
2631
with:
2732
script: |
28-
const [targetRepoOwner, targetRepoName] = process.env.TARGET_REPOSITORY.split('/')
33+
const sourceRepo = ${{ toJSON(matrix.spec.sourceRepo) }}
34+
const sourceRefRegexp = ((p) => p ? new RegExp(p) : null)(${{ toJSON(matrix.spec.sourceRefRegex) }})
35+
const targetRepo = ${{ toJSON(matrix.spec.targetRepo) }}
36+
const targetRefNamespace = ${{ toJSON(matrix.spec.targetRefNamespace) }} || ''
37+
38+
const [targetRepoOwner, targetRepoName] = targetRepo.split('/')
2939
core.setOutput('target-repo-owner', targetRepoOwner)
3040
core.setOutput('target-repo-name', targetRepoName)
3141
@@ -38,27 +48,26 @@ jobs:
3848
for (;;) {
3949
try {
4050
const [owner, repo] = repository.split('/')
41-
let { data } = await github.rest.git.listMatchingRefs({
42-
owner,
43-
repo,
44-
ref: 'heads/'
45-
})
46-
47-
data = data.filter(e => {
48-
if (!e.ref.startsWith('refs/heads/')) return false
49-
e.name = e.ref.slice(11)
50-
return true
51-
})
52-
53-
if (stripRefsPrefix) {
54-
data = data.filter(e => {
55-
if (!e.name.startsWith(stripRefsPrefix)) return false
56-
e.name = e.name.slice(stripRefsPrefix.length)
51+
return (
52+
await github.rest.git.listMatchingRefs({
53+
owner,
54+
repo,
55+
// We cannot match `source-ref-regex` as freely as we
56+
// want with GitHub's REST API, hence we do it below via
57+
// the `filter()` call.
58+
ref: 'heads/'
59+
})
60+
).data
61+
.filter((e) => {
62+
if (sourceRefRegexp && !sourceRefRegexp.test(e.ref)) return false
63+
if (!e.ref.startsWith('refs/heads/')) return false
64+
e.name = e.ref.slice(11)
65+
if (stripRefsPrefix) {
66+
if (!e.name.startsWith(stripRefsPrefix)) return false
67+
e.name = e.name.slice(stripRefsPrefix.length)
68+
}
5769
return true
5870
})
59-
}
60-
61-
return data
6271
.sort((a, b) => a.ref.localeCompare(b.ref))
6372
} catch (e) {
6473
if (e?.status !== 502) throw e
@@ -72,10 +81,10 @@ jobs:
7281
}
7382
}
7483
75-
const sourceRefs = await getRefs(process.env.SOURCE_REPOSITORY)
76-
const targetRefs = await getRefs(process.env.TARGET_REPOSITORY, process.env.TARGET_REF_NAMESPACE)
84+
const sourceRefs = await getRefs(sourceRepo)
85+
const targetRefs = await getRefs(targetRepo, targetRefNamespace)
7786
78-
const targetPrefix = `refs/heads/${process.env.TARGET_REF_NAMESPACE}`
87+
const targetPrefix = `refs/heads/${targetRefNamespace}`
7988
8089
const refspecs = []
8190
const toFetch = new Set()
@@ -138,7 +147,7 @@ jobs:
138147
set -ex
139148
git init --bare
140149
141-
git remote add source "${{ github.server_url }}/$SOURCE_REPOSITORY"
150+
git remote add source '${{ github.server_url }}/${{ matrix.spec.sourceRepo }}'
142151
# pretend to be a partial clone
143152
git config remote.source.promisor true
144153
git config remote.source.partialCloneFilter blob:none
@@ -151,4 +160,4 @@ jobs:
151160
# push the commits
152161
printf '%s' '${{ steps.check.outputs.refspec }}' |
153162
xargs -d ' ' -r git -c http.extraHeader='${{ steps.auth.outputs.header }}' \
154-
push "${{ github.server_url }}/$TARGET_REPOSITORY"
163+
push '${{ github.server_url }}/${{ matrix.spec.targetRepo }}'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ This repository contains GitHub workflows, i.e. automated tasks, that keep [GitG
44

55
## Keeping the mirror of the Git mailing list up to date
66

7-
The `sync-git-mailing-list.yml` workflow keeps the mirror at https://github.com/gitgitgadget/git-mailing-list of the Git mailing list mirror at https://lore.kernel.org/git up to date. Since that mirror chunks the archive by epochs, this mirror fetches each epoch into its own branch: the oldest epoch into `lore-0`, the next one into `lore-1`, etc.
7+
The `sync-mailing-list-mirror.yml` workflow keeps the mirror at https://github.com/gitgitgadget/git-mailing-list of the Git mailing list mirror at https://lore.kernel.org/git up to date. Since that mirror chunks the archive by epochs, this mirror fetches each epoch into its own branch: the oldest epoch into `lore-0`, the next one into `lore-1`, etc.
88

99
Previously, this workflow lived in the `git-mailing-list` repository in the `sync` branch, which was the default branch because scheduled workflows _must_ live in the default branch.

0 commit comments

Comments
 (0)