Skip to content

Commit 100ee78

Browse files
committed
git-artifacts: port to git-for-windows-automation
This ports the git-artifacts.yml CI pipeline over to the git-for-windows-automation repo, where it can also access arm64 runners in the future. The code is mostly the same as in the original git-for-windows/git repo but has a few optimizations to create the build matrix dynamically. Signed-off-by: Dennis Ameling <[email protected]>
1 parent e9b20e2 commit 100ee78

File tree

2 files changed

+360
-0
lines changed

2 files changed

+360
-0
lines changed

.github/workflows/git-artifacts.yml

Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
name: git-artifacts
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
build_only:
7+
description: 'Optionally restrict what artifacts to build (portable, installer, etc.). Separate artifacts with spaces'
8+
required: false
9+
ref:
10+
description: 'Optionally override which branch to build'
11+
required: false
12+
default: main
13+
repository:
14+
description: 'Optionally override from where to fetch the specified ref'
15+
required: false
16+
default: git-for-windows/git
17+
architecture:
18+
type: choice
19+
description: 'Architecture to build'
20+
required: true
21+
options:
22+
- x86_64
23+
- i686
24+
25+
env:
26+
GPG_OPTIONS: "--batch --yes --no-tty --list-options no-show-photos --verify-options no-show-photos --pinentry-mode loopback"
27+
HOME: "${{github.workspace}}\\home"
28+
USERPROFILE: "${{github.workspace}}\\home"
29+
BUILD_ONLY: "${{github.event.inputs.build_only}}"
30+
REPOSITORY: "${{github.event.inputs.repository}}"
31+
REF: "${{github.event.inputs.ref}}"
32+
ARCHITECTURE: "${{github.event.inputs.architecture}}"
33+
34+
defaults:
35+
run:
36+
shell: bash
37+
38+
jobs:
39+
bundle-artifacts:
40+
runs-on: windows-latest
41+
outputs:
42+
msystem: ${{steps.configure-environment.outputs.MSYSTEM}}
43+
mingw_prefix: ${{steps.configure-environment.outputs.MINGW_PREFIX}}
44+
bitness: ${{steps.configure-environment.outputs.BITNESS}}
45+
git_version: ${{steps.generate-bundle-artifacts.outputs.GIT_VERSION}}
46+
steps:
47+
- name: Configure environment
48+
id: configure-environment
49+
run: |
50+
case "$ARCHITECTURE" in
51+
x86_64)
52+
MSYSTEM=MINGW64
53+
MINGW_PREFIX="/mingw64"
54+
BITNESS=64
55+
;;
56+
i686)
57+
MSYSTEM=MINGW32
58+
MINGW_PREFIX="/mingw32"
59+
BTNESS=32
60+
;;
61+
*)
62+
echo "Unhandled architecture: $ARCHITECTURE"
63+
exit 1
64+
;;
65+
esac
66+
echo "MSYSTEM=$MSYSTEM" >> $GITHUB_ENV
67+
echo "MSYSTEM=$MSYSTEM" >> $GITHUB_OUTPUT
68+
echo "MINGW_PREFIX=$MINGW_PREFIX" >> $GITHUB_ENV
69+
echo "MINGW_PREFIX=$MINGW_PREFIX" >> $GITHUB_OUTPUT
70+
echo "BITNESS=$BITNESS" >> $GITHUB_OUTPUT
71+
- name: Configure user
72+
run:
73+
USER_NAME="${{github.actor}}" &&
74+
USER_EMAIL="${{github.actor}}@users.noreply.github.com" &&
75+
mkdir "$HOME" &&
76+
git config --global user.name "$USER_NAME" &&
77+
git config --global user.email "$USER_EMAIL" &&
78+
echo "PACKAGER=$USER_NAME <$USER_EMAIL>" >> $GITHUB_ENV
79+
- uses: git-for-windows/setup-git-for-windows-sdk@v1
80+
with:
81+
flavor: build-installers
82+
architecture: ${{env.architecture}}
83+
- name: Clone build-extra
84+
run: |
85+
d=/usr/src/build-extra &&
86+
if test ! -d $d/.git
87+
then
88+
git clone --single-branch -b main https://github.com/git-for-windows/build-extra $d
89+
else
90+
git -C $d fetch https://github.com/git-for-windows/build-extra main &&
91+
git -C $d switch -C main FETCH_HEAD
92+
fi
93+
- name: Prepare home directory for GPG signing
94+
if: env.GPGKEY != ''
95+
run: |
96+
echo '${{secrets.PRIVGPGKEY}}' | tr % '\n' | gpg $GPG_OPTIONS --import &&
97+
mkdir -p home &&
98+
git config --global gpg.program "/usr/src/build-extra/gnupg-with-gpgkey.sh" &&
99+
info="$(gpg --list-keys --with-colons "${GPGKEY%% *}" | cut -d : -f 1,10 | sed -n '/^uid/{s|uid:||p;q}')" &&
100+
git config --global user.name "${info% <*}" &&
101+
git config --global user.email "<${info#*<}"
102+
env:
103+
GPGKEY: ${{secrets.GPGKEY}}
104+
- name: Generate bundle artifacts
105+
env:
106+
GPGKEY: ${{secrets.GPGKEY}}
107+
id: generate-bundle-artifacts
108+
run: |
109+
printf '#!/bin/sh\n\nexec $MINGW_PREFIX/bin/git.exe "$@"\n' >/usr/bin/git &&
110+
mkdir -p bundle-artifacts &&
111+
git -c init.defaultBranch=main init --bare &&
112+
git remote add -f origin https://github.com/git-for-windows/git &&
113+
git fetch "https://github.com/$REPOSITORY" "$REF:$REF" &&
114+
tag_name="$(git describe --match 'v[0-9]*' FETCH_HEAD)" &&
115+
echo "GIT_VERSION=$tag_name" >> $GITHUB_OUTPUT &&
116+
echo "prerelease-${tag_name#v}" >bundle-artifacts/ver &&
117+
echo "${tag_name#v}" >bundle-artifacts/display_version &&
118+
echo "$tag_name" >bundle-artifacts/next_version &&
119+
git tag $(test -z "$GPGKEY" || echo " -s") -m "Snapshot build" "$tag_name" FETCH_HEAD &&
120+
git bundle create bundle-artifacts/git.bundle origin/main.."$tag_name" &&
121+
sh -x /usr/src/build-extra/please.sh mention feature "Snapshot of $(git show -s --pretty='tformat:%h (%s, %ad)' --date=short FETCH_HEAD)" &&
122+
git -C /usr/src/build-extra bundle create "$PWD/bundle-artifacts/build-extra.bundle" origin/main..main
123+
- name: 'Publish Pipeline Artifact: bundle-artifacts'
124+
uses: actions/upload-artifact@v3
125+
with:
126+
name: bundle-artifacts
127+
path: bundle-artifacts
128+
pkg:
129+
runs-on: windows-latest
130+
needs: bundle-artifacts
131+
outputs:
132+
artifact_matrix: ${{steps.artifact-build-matrix.outputs.matrix}}
133+
env:
134+
MSYSTEM: ${{ needs.bundle-artifacts.outputs.msystem }}
135+
MINGW_PREFIX: ${{ needs.bundle-artifacts.outputs.mingw_prefix }}
136+
BITNESS: ${{ needs.bundle-artifacts.outputs.bitness }}
137+
MSVC_FOLDER_SUFFIX: ${{ github.event.inputs.architecture == 'x86_64' && '/amd64' || '' }}
138+
GIT_VERSION: ${{ needs.bundle-artifacts.outputs.git_version }}
139+
steps:
140+
- name: Configure user
141+
run:
142+
USER_NAME="${{github.actor}}" &&
143+
USER_EMAIL="${{github.actor}}@users.noreply.github.com" &&
144+
mkdir "$HOME" &&
145+
git config --global user.name "$USER_NAME" &&
146+
git config --global user.email "$USER_EMAIL" &&
147+
echo "PACKAGER=$USER_NAME <$USER_EMAIL>" >> $GITHUB_ENV
148+
- uses: git-for-windows/setup-git-for-windows-sdk@v1
149+
with:
150+
flavor: build-installers
151+
architecture: ${{env.architecture}}
152+
- name: Download bundle-artifacts
153+
uses: actions/download-artifact@v3
154+
with:
155+
name: bundle-artifacts
156+
path: bundle-artifacts
157+
- name: Clone and update build-extra
158+
run: |
159+
d=/usr/src/build-extra &&
160+
if test ! -d $d/.git
161+
then
162+
git clone --single-branch -b main https://github.com/git-for-windows/build-extra $d
163+
else
164+
git -C $d fetch https://github.com/git-for-windows/build-extra main &&
165+
git -C $d switch -C main FETCH_HEAD
166+
fi &&
167+
git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main
168+
- name: Check out git/git
169+
shell: bash
170+
run: |
171+
git -c init.defaultBranch=main init &&
172+
git remote add -f origin https://github.com/git-for-windows/git &&
173+
git fetch --tags bundle-artifacts/git.bundle $(cat bundle-artifacts/next_version) &&
174+
git reset --hard $(cat bundle-artifacts/next_version)
175+
- name: Prepare home directory for code-signing
176+
env:
177+
CODESIGN_P12: ${{secrets.CODESIGN_P12}}
178+
CODESIGN_PASS: ${{secrets.CODESIGN_PASS}}
179+
if: env.CODESIGN_P12 != '' && env.CODESIGN_PASS != ''
180+
run: |
181+
cd home &&
182+
mkdir -p .sig &&
183+
echo -n "$CODESIGN_P12" | tr % '\n' | base64 -d >.sig/codesign.p12 &&
184+
echo -n "$CODESIGN_PASS" >.sig/codesign.pass
185+
git config --global alias.signtool '!sh "/usr/src/build-extra/signtool.sh"'
186+
- name: Prepare home directory for GPG signing
187+
if: env.GPGKEY != ''
188+
run: |
189+
echo '${{secrets.PRIVGPGKEY}}' | tr % '\n' | gpg $GPG_OPTIONS --import &&
190+
info="$(gpg --list-keys --with-colons "${GPGKEY%% *}" | cut -d : -f 1,10 | sed -n '/^uid/{s|uid:||p;q}')" &&
191+
git config --global user.name "${info% <*}" &&
192+
git config --global user.email "<${info#*<}"
193+
env:
194+
GPGKEY: ${{secrets.GPGKEY}}
195+
- name: Cache mingw-w64-${{env.ARCHITECTURE}}-git
196+
id: cache-git-pkg
197+
uses: actions/cache@v3
198+
with:
199+
path: artifacts
200+
key: pkg-${{env.GIT_VERSION}}-${{env.ARCHITECTURE}}
201+
- name: Build mingw-w64-${{env.ARCHITECTURE}}-git
202+
if: steps.cache-git-pkg.outputs.cache-hit != 'true'
203+
env:
204+
GPGKEY: "${{secrets.GPGKEY}}"
205+
run: |
206+
set -x
207+
# Make sure that there is a `/usr/bin/git` that can be used by `makepkg-mingw`
208+
printf '#!/bin/sh\n\nexec $MINGW_PREFIX/bin/git.exe "$@"\n' >/usr/bin/git &&
209+
# Restrict `PATH` to MSYS2 and to Visual Studio (to let `cv2pdb` find the relevant DLLs)
210+
PATH="$MINGW_PREFIX/bin:/usr/bin:/c/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/:/C/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin$MSVC_FOLDER_SUFFIX:/C/Windows/system32"
211+
type -p mspdb140.dll || exit 1
212+
sh -x /usr/src/build-extra/please.sh build-mingw-w64-git --only-$BITNESS-bit --build-src-pkg -o artifacts HEAD &&
213+
cp bundle-artifacts/ver artifacts/ &&
214+
if test -n "$GPGKEY"
215+
then
216+
for tar in artifacts/*.tar*
217+
do
218+
/usr/src/build-extra/gnupg-with-gpgkey.sh --detach-sign --no-armor $tar
219+
done
220+
fi &&
221+
b=$PWD/artifacts &&
222+
version=$(cat bundle-artifacts/next_version) &&
223+
(cd /usr/src/MINGW-packages/mingw-w64-git &&
224+
cp PKGBUILD.$version PKGBUILD &&
225+
git commit -s -m "mingw-w64-git: new version ($version)" PKGBUILD &&
226+
git bundle create "$b"/MINGW-packages.bundle origin/main..main)
227+
- name: Publish mingw-w64-${{env.ARCHITECTURE}}-git
228+
uses: actions/upload-artifact@v3
229+
with:
230+
name: pkg-${{env.ARCHITECTURE}}
231+
path: artifacts
232+
- uses: actions/setup-node@v3
233+
with:
234+
node-version: 16
235+
- uses: actions/checkout@v3
236+
with:
237+
path: automation-scripts
238+
clean: false
239+
- name: Prepare artifact build matrix
240+
id: artifact-build-matrix
241+
run: |
242+
ARTIFACTS=$(test -n "$BUILD_ONLY" && echo $BUILD_ONLY || echo "installer portable archive mingit mingit-busybox")
243+
MATRIX=$(node ./automation-scripts/create-artifacts-matrix.js $ARTIFACTS)
244+
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
245+
echo "Will be using the following matrix: $MATRIX"
246+
artifacts:
247+
runs-on: windows-latest
248+
needs: [bundle-artifacts, pkg]
249+
env:
250+
MSYSTEM: ${{ needs.bundle-artifacts.outputs.msystem }}
251+
BITNESS: ${{ needs.bundle-artifacts.outputs.bitness }}
252+
strategy:
253+
fail-fast: false
254+
matrix: ${{ fromJSON(needs.pkg.outputs.artifact_matrix) }}
255+
steps:
256+
- name: Download pkg-${{env.ARCHITECTURE}}
257+
uses: actions/download-artifact@v3
258+
with:
259+
name: pkg-${{env.ARCHITECTURE}}
260+
path: pkg-${{env.ARCHITECTURE}}
261+
- name: Download bundle-artifacts
262+
uses: actions/download-artifact@v3
263+
with:
264+
name: bundle-artifacts
265+
path: bundle-artifacts
266+
- uses: git-for-windows/setup-git-for-windows-sdk@v1
267+
with:
268+
flavor: build-installers
269+
architecture: ${{env.ARCHITECTURE}}
270+
- name: Clone and update build-extra
271+
run: |
272+
d=/usr/src/build-extra &&
273+
if test ! -d $d/.git
274+
then
275+
git clone --single-branch -b main https://github.com/git-for-windows/build-extra $d
276+
else
277+
git -C $d fetch https://github.com/git-for-windows/build-extra main &&
278+
git -C $d switch -C main FETCH_HEAD
279+
fi &&
280+
git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main
281+
- name: Prepare home directory for code-signing
282+
env:
283+
CODESIGN_P12: ${{secrets.CODESIGN_P12}}
284+
CODESIGN_PASS: ${{secrets.CODESIGN_PASS}}
285+
if: (matrix.artifact.name == 'installer' || matrix.artifact.name == 'portable') && env.CODESIGN_P12 != '' && env.CODESIGN_PASS != ''
286+
run: |
287+
mkdir -p home/.sig &&
288+
echo -n "$CODESIGN_P12" | tr % '\n' | base64 -d >home/.sig/codesign.p12 &&
289+
echo -n "$CODESIGN_PASS" >home/.sig/codesign.pass &&
290+
git config --global alias.signtool '!sh "/usr/src/build-extra/signtool.sh"'
291+
- name: Build ${{env.ARCHITECTURE}} ${{matrix.artifact.name}}
292+
run: |
293+
set -x
294+
eval /usr/src/build-extra/please.sh make_installers_from_mingw_w64_git --version=$(cat pkg-${{env.ARCHITECTURE}}/ver) -o artifacts --${{matrix.artifact.name}} --pkg=pkg-${{env.ARCHITECTURE}}/mingw-w64-${{env.ARCHITECTURE}}-git-[0-9]*.tar.xz --pkg=pkg-${{env.ARCHITECTURE}}/mingw-w64-${{env.ARCHITECTURE}}-git-doc-html-[0-9]*.tar.xz &&
295+
if test portable = '${{matrix.artifact.name}}' && test -n "$(git config alias.signtool)"
296+
then
297+
git signtool artifacts/PortableGit-*.exe
298+
fi &&
299+
openssl dgst -sha256 artifacts/${{matrix.artifact.fileprefix}}-*.${{matrix.artifact.fileextension}} | sed "s/.* //" >artifacts/sha-256.txt
300+
- name: Copy package-versions and pdbs
301+
if: matrix.artifact.name == 'installer'
302+
run: |
303+
cp /usr/src/build-extra/installer/package-versions.txt artifacts/ &&
304+
a=$PWD/artifacts &&
305+
p=$PWD/pkg-${{env.ARCHITECTURE}} &&
306+
(cd /usr/src/build-extra &&
307+
mkdir -p cached-source-packages &&
308+
cp "$p"/*-pdb* cached-source-packages/ &&
309+
GIT_CONFIG_PARAMETERS="'windows.sdk${{env.BITNESS}}.path='" ./please.sh bundle_pdbs --arch=${{env.ARCHITECTURE}} --directory="$a" installer/package-versions.txt)
310+
- name: Publish ${{matrix.artifact.name}}-${{env.ARCHITECTURE}}
311+
uses: actions/upload-artifact@v3
312+
with:
313+
name: ${{matrix.artifact.name}}-${{env.ARCHITECTURE}}
314+
path: artifacts

create-artifacts-matrix.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const artifacts = process.argv.slice(2)
2+
3+
if (artifacts.length < 1) {
4+
throw new Error("No artifacts provided. Provide in the format ./create-artifacts-matrix.js ARTIFACT1 ARTIFACT2")
5+
}
6+
7+
const validArtifacts = [
8+
{
9+
name: "installer",
10+
filePrefix: "Git",
11+
fileExtension: "exe"
12+
},
13+
{
14+
name: "portable",
15+
filePrefix: "PortableGit",
16+
fileExtension: "exe"
17+
},
18+
{
19+
name: "archive",
20+
filePrefix: "Git",
21+
fileExtension: "tar.bz2"
22+
},
23+
{
24+
name: "mingit",
25+
filePrefix: "MinGit",
26+
fileExtension: "zip"
27+
},
28+
{
29+
name: "mingit-busybox",
30+
filePrefix: "MinGit",
31+
fileExtension: "zip"
32+
}
33+
]
34+
35+
const artifactsToBuild = []
36+
37+
for (const artifact of artifacts) {
38+
const artifactObject = validArtifacts.find(a => a.name === artifact)
39+
if (!artifactObject) {
40+
throw new Error(`${artifact} is not a valid artifact`)
41+
}
42+
43+
artifactsToBuild.push(artifactObject)
44+
}
45+
46+
console.log(JSON.stringify({artifact: artifactsToBuild}))

0 commit comments

Comments
 (0)