Skip to content

Commit f3a2525

Browse files
committed
Add a GitHub workflow to prepare the branches for embargoed Git for Windows versions
When embargoed Git for Windows versions (or backport versions) need to be prepared, a couple of branches need to be created (internally nicknamed "time-traveling branches"), to pick back up at the precise revisions from where the preceding version was built. That way, the embargoed version will only differ in the fixed Git artifacts, and avoid shipping with updates in other components that might cause risk of regressions. This new workflow prepares these branches. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent d7c47eb commit f3a2525

File tree

3 files changed

+161
-1
lines changed

3 files changed

+161
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: prepare-embargoed-branches
2+
run-name: Prepare branches for embargoed Git ${{ inputs.version }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: 'The Git version for which to prepare the branches'
9+
required: true
10+
11+
jobs:
12+
prepare-embargoed-branches:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: sanity check
16+
if: ${{ github.repository_owner == 'git-for-windows' }}
17+
run: echo "This action is not meant to be run on the Git for Windows repository" >&2 && exit 1
18+
- run: actions/checkout@v4
19+
- name: identify actor
20+
id: actor
21+
uses: actions/github-script@v7
22+
with:
23+
script: |
24+
const githubApiRequest = require('./github-api-request')
25+
const answer = await githubApiRequest(
26+
console,
27+
'${{ secrets.GITHUB_TOKEN }}',
28+
'GET',
29+
'/users/${{ github.triggering_actor }}'
30+
)
31+
core.setOutput('name', answer.name)
32+
core.setOutput('email', answer.email || '${{ github.triggering_actor }}@users.noreply.github.com')
33+
- name: configure
34+
run: |
35+
USER_NAME="${{ steps.actor.outputs.name }}" &&
36+
USER_EMAIL="${{ steps.actor.outputs.email }}" &&
37+
git config --global user.name "$USER_NAME" &&
38+
git config --global user.email "$USER_EMAIL" &&
39+
git config --global url.https://github.com/${{ github.repository_owner }}.insteadOf \
40+
https://github.com/embargoed-git-for-windows-builds &&
41+
git config --global credential.helper '' &&
42+
git config --global --add credential.helper cache
43+
- name: configure push token
44+
uses: actions/github-script@v7
45+
with:
46+
script: |
47+
const { callGit, getPushAuthorizationHeader } = require('./repository-updates.js')
48+
for (const repo of ['build-extra', 'git', 'git-sdk-32', 'git-sdk-64', 'MINGW-packages']) {
49+
const header = await getPushAuthorizationHeader(
50+
console,
51+
core.setSecret,
52+
${{ secrets.GH_APP_ID }},
53+
${{ toJSON(secrets.GH_APP_PRIVATE_KEY) }},
54+
context.repo.owner,
55+
repo
56+
)
57+
console.log(callGit(['config', '--global', `http.https://github.com/${context.repo.owner}/${repo}.extraHeader`, header]))
58+
}
59+
- name: Prepare embargoed branches
60+
run: sh -x ./prepare-embargoed-branches.sh "${{ inputs.version }}"

prepare-embargoed-branches.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/sh
2+
3+
die () {
4+
echo "$*" >&2
5+
exit 1
6+
}
7+
8+
dry_run=
9+
mingit=
10+
while case "$1" in
11+
--dry-run|-n) dry_run=1;;
12+
--mingit) mingit=1;;
13+
-*) die "Unknown option: $1";;
14+
*) break;;
15+
esac; do shift; done
16+
17+
test $# = 1 ||
18+
die "Usage: $0 [--dry-run] [--mingit] <version> # e.g. 2.39.1"
19+
20+
version=${1#v}
21+
if test -z "$mingit"
22+
then
23+
case "$version" in
24+
*[^0-9.]*|*..*|.*|*.) die "Invalid version: '$version'";;
25+
*.*.*) ;; # okay
26+
*) die "Invalid version: '$version'";;
27+
esac
28+
previous_version_prefix=${version%.*}.$((${version##*.}-1))
29+
branch_name=git-$version
30+
else
31+
previous_version_prefix="$(expr "$version" : '\([0-9]\+\.[0-9]\+\)\.\{0,1\}[0-9]*$')"
32+
test -n "$previous_version_prefix" || die "Invalid version: '$version'"
33+
branch_name=mingit-$previous_version_prefix.x-releases
34+
fi
35+
grep_version_regex="$(echo "$previous_version_prefix" | sed 's/\./\\\\&/g')"
36+
37+
handle_repo () {
38+
name="$1"
39+
path="$2"
40+
args="$3"
41+
42+
echo "### Handling $name ###" &&
43+
44+
if test -e "$path/.git"
45+
then
46+
git_dir="$path/.git"
47+
main_refspec="refs/remotes/origin/main:refs/heads/main"
48+
else
49+
# To allow for running this script on Linux/macOS, fall back to cloning to pwd
50+
git_dir=${path##*/}.git &&
51+
if test ! -d "$git_dir"
52+
then
53+
# We only need a partial clone
54+
git clone --bare --filter=blob:none \
55+
https://github.com/git-for-windows/$name "$git_dir"
56+
fi
57+
main_refspec="refs/heads/main:refs/heads/main"
58+
fi &&
59+
60+
# ensure that the `embargoed-git-for-windows-builds` remote is set
61+
remote_url=https://github.com/embargoed-git-for-windows-builds/$name &&
62+
case "$(git --git-dir "$git_dir" remote show -n embargoed-git-for-windows-builds)" in
63+
*"Fetch URL: $remote_url"*"Push URL: $remote_url"*) ;; # okay
64+
*) git --git-dir "$git_dir" remote add embargoed-git-for-windows-builds $remote_url;;
65+
esac &&
66+
67+
# if `embargoed-git-for-windows-builds` already has the branch, everything's fine already
68+
revision=$(git --git-dir "$git_dir" ls-remote embargoed-git-for-windows-builds refs/heads/$branch_name | cut -f 1) &&
69+
if test -n "$revision"
70+
then
71+
echo "$name already has $branch_name @$revision"
72+
else
73+
git --git-dir "$git_dir" fetch origin main &&
74+
revision="$(eval git --git-dir "\"$git_dir\"" rev-list -1 FETCH_HEAD $args)" &&
75+
if test -z "$revision"
76+
then
77+
die "No matching revision for $args in $name"
78+
fi &&
79+
echo "Creating $branch_name in $name @$revision" &&
80+
push_ref_spec="$revision:refs/heads/$branch_name $main_refspec" &&
81+
if test -n "$dry_run"
82+
then
83+
git --git-dir "$git_dir" show -s "$revision" &&
84+
echo "Would call 'git push embargoed-git-for-windows-builds $push_ref_spec'"
85+
else
86+
echo "git push embargoed-git-for-windows-builds $push_ref_spec" &&
87+
git --git-dir "$git_dir" push embargoed-git-for-windows-builds $push_ref_spec
88+
fi
89+
fi
90+
}
91+
92+
handle_repo git-sdk-32 /c/git-sdk-32 \
93+
"\"--grep=mingw-w64-i686-git \".*\" -> $grep_version_regex\" -- cmd/git.exe" &&
94+
handle_repo git-sdk-64 /c/git-sdk-64 \
95+
"\"--grep=mingw-w64-x86_64-git \".*\" -> $grep_version_regex\" -- cmd/git.exe" &&
96+
handle_repo build-extra /usr/src/build-extra \
97+
"-- versions/package-versions-$previous_version_prefix\\*-MinGit.txt" &&
98+
handle_repo MINGW-packages /usr/src/MINGW-packages \
99+
"\"--grep=mingw-w64-git: new version .v$grep_version_regex\" -- mingw-w64-git/PKGBUILD"

repository-updates.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,6 @@ module.exports = {
158158
callGit,
159159
getWorkflowRunArtifact,
160160
pushRepositoryUpdate,
161-
pushGitBranch
161+
pushGitBranch,
162+
getPushAuthorizationHeader
162163
}

0 commit comments

Comments
 (0)