Skip to content

Commit df9d658

Browse files
authored
Merge pull request #22 from git-for-windows/git-artifacts
Port `git-artifacts` pipeline to `git-for-windows-automation`
2 parents 4bc8132 + 58d8d70 commit df9d658

File tree

4 files changed

+438
-0
lines changed

4 files changed

+438
-0
lines changed

.github/workflows/git-artifacts.yml

+272
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
name: git-artifacts
2+
run-name: Build git-artifacts (${{ inputs.architecture }})
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
artifacts:
8+
description: 'Optionally restrict what artifacts to build (portable, installer, etc.). Separate artifacts with spaces'
9+
required: false
10+
ref:
11+
description: 'Optionally override which branch to build'
12+
required: false
13+
default: main
14+
repository:
15+
description: 'Optionally override from where to fetch the specified ref'
16+
required: false
17+
default: git-for-windows/git
18+
architecture:
19+
type: choice
20+
description: 'Architecture to build'
21+
required: true
22+
options:
23+
- x86_64
24+
- i686
25+
- aarch64
26+
bundle_artifacts_workflow_run_id:
27+
description: 'Workflow run ID from bundle-artifacts pipeline'
28+
required: false
29+
30+
env:
31+
GPG_OPTIONS: "--batch --yes --no-tty --list-options no-show-photos --verify-options no-show-photos --pinentry-mode loopback"
32+
HOME: "${{github.workspace}}\\home"
33+
USERPROFILE: "${{github.workspace}}\\home"
34+
ARTIFACTS_TO_BUILD: "${{github.event.inputs.artifacts}}"
35+
REPOSITORY: "${{github.event.inputs.repository}}"
36+
REF: "${{github.event.inputs.ref}}"
37+
ARCHITECTURE: "${{github.event.inputs.architecture}}"
38+
BUNDLE_ARTIFACTS_WORKFLOW_RUN_ID: "${{github.event.inputs.bundle_artifacts_workflow_run_id}}"
39+
40+
defaults:
41+
run:
42+
shell: bash
43+
44+
jobs:
45+
pkg:
46+
runs-on: ${{ github.event.inputs.architecture == 'aarch64' && fromJSON('["Windows", "ARM64"]') || 'windows-latest' }}
47+
outputs:
48+
artifact_matrix: ${{steps.artifact-build-matrix.outputs.matrix}}
49+
msystem: ${{steps.configure-environment.outputs.MSYSTEM}}
50+
mingw_package_prefix: ${{steps.configure-environment.outputs.MINGW_PACKAGE_PREFIX}}
51+
sdk_repo_arch: ${{steps.configure-environment.outputs.SDK_REPO_ARCH}}
52+
steps:
53+
- name: Configure environment
54+
id: configure-environment
55+
run: |
56+
case "$ARCHITECTURE" in
57+
x86_64)
58+
MSYSTEM=MINGW64
59+
MINGW_PREFIX=/mingw64
60+
MINGW_PACKAGE_PREFIX=mingw-w64-x86_64
61+
SDK_REPO_ARCH=64
62+
;;
63+
i686)
64+
MSYSTEM=MINGW32
65+
MINGW_PREFIX=/mingw32
66+
MINGW_PACKAGE_PREFIX=mingw-w64-i686
67+
SDK_REPO_ARCH=32
68+
;;
69+
aarch64)
70+
MSYSTEM=CLANGARM64
71+
MINGW_PREFIX=/clangarm64
72+
MINGW_PACKAGE_PREFIX=mingw-w64-clang-aarch64
73+
SDK_REPO_ARCH=arm64
74+
;;
75+
*)
76+
echo "Unhandled architecture: $ARCHITECTURE"
77+
exit 1
78+
;;
79+
esac
80+
echo "MSYSTEM=$MSYSTEM" >> $GITHUB_ENV
81+
echo "MSYSTEM=$MSYSTEM" >> $GITHUB_OUTPUT
82+
echo "MINGW_PREFIX=$MINGW_PREFIX" >> $GITHUB_ENV
83+
echo "MINGW_PACKAGE_PREFIX=$MINGW_PACKAGE_PREFIX" >> $GITHUB_ENV
84+
echo "MINGW_PACKAGE_PREFIX=$MINGW_PACKAGE_PREFIX" >> $GITHUB_OUTPUT
85+
echo "SDK_REPO_ARCH=$SDK_REPO_ARCH" >> $GITHUB_OUTPUT
86+
echo "ARTIFACTS_TO_BUILD=$(test -n "$ARTIFACTS_TO_BUILD" && echo $ARTIFACTS_TO_BUILD || \
87+
echo "installer portable archive mingit$(test "$ARCHITECTURE" = aarch64 || echo ' mingit-busybox')")" >> $GITHUB_ENV
88+
- name: Configure user
89+
run:
90+
USER_NAME="${{github.actor}}" &&
91+
USER_EMAIL="${{github.actor}}@users.noreply.github.com" &&
92+
mkdir "$HOME" &&
93+
git config --global user.name "$USER_NAME" &&
94+
git config --global user.email "$USER_EMAIL" &&
95+
echo "PACKAGER=$USER_NAME <$USER_EMAIL>" >> $GITHUB_ENV
96+
- uses: git-for-windows/setup-git-for-windows-sdk@v1
97+
with:
98+
flavor: build-installers
99+
architecture: ${{env.architecture}}
100+
- name: clone git-for-windows-automation
101+
run: git clone --single-branch -b $GITHUB_REF_NAME https://github.com/git-for-windows/git-for-windows-automation
102+
- uses: actions/github-script@v6
103+
id: artifact-build-matrix
104+
name: Create artifact build matrix
105+
with:
106+
script: |
107+
core.info('Preparing artifact build matrix...')
108+
const createArtifactsMatrix = require('./git-for-windows-automation/create-artifacts-matrix')
109+
createArtifactsMatrix(core, process.env.ARTIFACTS_TO_BUILD, process.env.ARCHITECTURE)
110+
- uses: actions/github-script@v6
111+
id: get-bundle-artifacts-url
112+
name: Get bundle-artifacts download URL
113+
with:
114+
script: |
115+
const getArtifact = require('./git-for-windows-automation/get-bundle-artifacts-artifact')
116+
const workflowId = process.env.BUNDLE_ARTIFACTS_WORKFLOW_RUN_ID
117+
core.info('Getting download URL for bundle-artifacts...')
118+
await getArtifact(github, context, core, workflowId)
119+
- name: Download bundle-artifacts zip
120+
run: |
121+
mkdir bundle-artifacts
122+
curl -o bundle-artifacts.zip "${{steps.get-bundle-artifacts-url.outputs.downloadUrl}}"
123+
unzip bundle-artifacts.zip -d bundle-artifacts
124+
echo "GIT_VERSION=$(cat bundle-artifacts/next_version)" >> $GITHUB_ENV
125+
- name: Re-publish bundle-artifacts so the next job can easily use it
126+
uses: actions/upload-artifact@v3
127+
with:
128+
name: bundle-artifacts
129+
path: bundle-artifacts
130+
- name: Clone and update build-extra
131+
run: |
132+
d=/usr/src/build-extra &&
133+
if test ! -d $d/.git
134+
then
135+
git clone --single-branch -b main https://github.com/git-for-windows/build-extra $d
136+
else
137+
git -C $d fetch https://github.com/git-for-windows/build-extra main &&
138+
git -C $d switch -C main FETCH_HEAD
139+
fi &&
140+
git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main
141+
- name: Check out git/git
142+
shell: bash
143+
run: |
144+
git -c init.defaultBranch=main init &&
145+
git remote add -f origin https://github.com/git-for-windows/git &&
146+
git fetch --tags bundle-artifacts/git.bundle $(cat bundle-artifacts/next_version) &&
147+
git reset --hard $(cat bundle-artifacts/next_version)
148+
- name: Prepare home directory for code-signing
149+
env:
150+
CODESIGN_P12: ${{secrets.CODESIGN_P12}}
151+
CODESIGN_PASS: ${{secrets.CODESIGN_PASS}}
152+
if: env.CODESIGN_P12 != '' && env.CODESIGN_PASS != ''
153+
run: |
154+
cd home &&
155+
mkdir -p .sig &&
156+
echo -n "$CODESIGN_P12" | tr % '\n' | base64 -d >.sig/codesign.p12 &&
157+
echo -n "$CODESIGN_PASS" >.sig/codesign.pass
158+
git config --global alias.signtool '!sh "/usr/src/build-extra/signtool.sh"'
159+
- name: Prepare home directory for GPG signing
160+
if: env.GPGKEY != ''
161+
run: |
162+
echo '${{secrets.PRIVGPGKEY}}' | tr % '\n' | gpg $GPG_OPTIONS --import &&
163+
info="$(gpg --list-keys --with-colons "${GPGKEY%% *}" | cut -d : -f 1,10 | sed -n '/^uid/{s|uid:||p;q}')" &&
164+
git config --global user.name "${info% <*}" &&
165+
git config --global user.email "<${info#*<}"
166+
env:
167+
GPGKEY: ${{secrets.GPGKEY}}
168+
- name: Cache ${{env.MINGW_PACKAGE_PREFIX}}-git
169+
id: cache-git-pkg
170+
uses: actions/cache@v3
171+
with:
172+
path: artifacts
173+
key: pkg-${{env.GIT_VERSION}}-${{env.ARCHITECTURE}}
174+
- name: Build ${{env.MINGW_PACKAGE_PREFIX}}-git
175+
if: steps.cache-git-pkg.outputs.cache-hit != 'true'
176+
env:
177+
GPGKEY: "${{secrets.GPGKEY}}"
178+
run: |
179+
set -x
180+
BUILD_SRC=$(test x86_64 != "$ARCHITECTURE" || echo "--build-src-pkg")
181+
# Make sure that there is a `/usr/bin/git` that can be used by `makepkg-mingw`
182+
printf '#!/bin/sh\n\nexec '$MINGW_PREFIX'/bin/git.exe "$@"\n' >/usr/bin/git &&
183+
/usr/src/build-extra/please.sh build-mingw-w64-git --only-$ARCHITECTURE $BUILD_SRC -o artifacts HEAD &&
184+
cp bundle-artifacts/ver artifacts/ &&
185+
if test -n "$GPGKEY"
186+
then
187+
for tar in artifacts/*.tar*
188+
do
189+
/usr/src/build-extra/gnupg-with-gpgkey.sh --detach-sign --no-armor $tar
190+
done
191+
fi &&
192+
b=$PWD/artifacts &&
193+
version=$(cat bundle-artifacts/next_version) &&
194+
(cd /usr/src/MINGW-packages/mingw-w64-git &&
195+
cp PKGBUILD.$version PKGBUILD &&
196+
git commit -s -m "mingw-w64-git: new version ($version)" PKGBUILD &&
197+
git bundle create "$b"/MINGW-packages.bundle origin/main..main)
198+
- name: Publish ${{env.MINGW_PACKAGE_PREFIX}}-git
199+
uses: actions/upload-artifact@v3
200+
with:
201+
name: pkg-${{env.ARCHITECTURE}}
202+
path: artifacts
203+
artifacts:
204+
runs-on: ${{ github.event.inputs.architecture == 'aarch64' && fromJSON('["Windows", "ARM64"]') || 'windows-latest' }}
205+
needs: pkg
206+
env:
207+
MSYSTEM: ${{ needs.pkg.outputs.msystem }}
208+
MINGW_PACKAGE_PREFIX: ${{ needs.pkg.outputs.mingw_package_prefix }}
209+
SDK_REPO_ARCH: ${{ needs.pkg.outputs.sdk_repo_arch }}
210+
strategy:
211+
fail-fast: false
212+
matrix: ${{ fromJSON(needs.pkg.outputs.artifact_matrix) }}
213+
steps:
214+
- name: Download pkg-${{env.ARCHITECTURE}}
215+
uses: actions/download-artifact@v3
216+
with:
217+
name: pkg-${{env.ARCHITECTURE}}
218+
path: pkg-${{env.ARCHITECTURE}}
219+
- name: Download bundle-artifacts
220+
uses: actions/download-artifact@v3
221+
with:
222+
name: bundle-artifacts
223+
path: bundle-artifacts
224+
- uses: git-for-windows/setup-git-for-windows-sdk@v1
225+
with:
226+
flavor: build-installers
227+
architecture: ${{env.ARCHITECTURE}}
228+
- name: Clone and update build-extra
229+
run: |
230+
d=/usr/src/build-extra &&
231+
if test ! -d $d/.git
232+
then
233+
git clone --single-branch -b main https://github.com/git-for-windows/build-extra $d
234+
else
235+
git -C $d fetch https://github.com/git-for-windows/build-extra main &&
236+
git -C $d switch -C main FETCH_HEAD
237+
fi &&
238+
git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main
239+
- name: Prepare home directory for code-signing
240+
env:
241+
CODESIGN_P12: ${{secrets.CODESIGN_P12}}
242+
CODESIGN_PASS: ${{secrets.CODESIGN_PASS}}
243+
if: (matrix.artifact.name == 'installer' || matrix.artifact.name == 'portable') && env.CODESIGN_P12 != '' && env.CODESIGN_PASS != ''
244+
run: |
245+
mkdir -p home/.sig &&
246+
echo -n "$CODESIGN_P12" | tr % '\n' | base64 -d >home/.sig/codesign.p12 &&
247+
echo -n "$CODESIGN_PASS" >home/.sig/codesign.pass &&
248+
git config --global alias.signtool '!sh "/usr/src/build-extra/signtool.sh"'
249+
- name: Build ${{env.ARCHITECTURE}} ${{matrix.artifact.name}}
250+
run: |
251+
set -x
252+
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}}/${{env.MINGW_PACKAGE_PREFIX}}-git-[0-9]*.tar.xz --pkg=pkg-${{env.ARCHITECTURE}}/${{env.MINGW_PACKAGE_PREFIX}}-git-doc-html-[0-9]*.tar.xz &&
253+
if test portable = '${{matrix.artifact.name}}' && test -n "$(git config alias.signtool)"
254+
then
255+
git signtool artifacts/PortableGit-*.exe
256+
fi &&
257+
openssl dgst -sha256 artifacts/${{matrix.artifact.fileprefix}}-*.${{matrix.artifact.fileextension}} | sed "s/.* //" >artifacts/sha-256.txt
258+
- name: Copy package-versions and pdbs
259+
if: matrix.artifact.name == 'installer'
260+
run: |
261+
cp /usr/src/build-extra/installer/package-versions.txt artifacts/ &&
262+
a=$PWD/artifacts &&
263+
p=$PWD/pkg-${{env.ARCHITECTURE}} &&
264+
(cd /usr/src/build-extra &&
265+
mkdir -p cached-source-packages &&
266+
cp "$p"/*-pdb* cached-source-packages/ &&
267+
GIT_CONFIG_PARAMETERS="'windows.sdk${{env.SDK_REPO_ARCH}}.path='" ./please.sh bundle_pdbs --arch=${{env.ARCHITECTURE}} --directory="$a" installer/package-versions.txt)
268+
- name: Publish ${{matrix.artifact.name}}-${{env.ARCHITECTURE}}
269+
uses: actions/upload-artifact@v3
270+
with:
271+
name: ${{matrix.artifact.name}}-${{env.ARCHITECTURE}}
272+
path: artifacts

.github/workflows/tag-git.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: tag-git
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: 'Optionally override which branch to build'
8+
required: false
9+
default: main
10+
repository:
11+
description: 'Optionally override from where to fetch the specified ref'
12+
required: false
13+
default: git-for-windows/git
14+
15+
env:
16+
GPG_OPTIONS: "--batch --yes --no-tty --list-options no-show-photos --verify-options no-show-photos --pinentry-mode loopback"
17+
HOME: "${{github.workspace}}\\home"
18+
USERPROFILE: "${{github.workspace}}\\home"
19+
REPOSITORY: "${{github.event.inputs.repository}}"
20+
REF: "${{github.event.inputs.ref}}"
21+
NODEJS_VERSION: 16
22+
23+
jobs:
24+
tag-git:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Configure user
28+
run:
29+
USER_NAME="${{github.actor}}" &&
30+
USER_EMAIL="${{github.actor}}@users.noreply.github.com" &&
31+
mkdir "$HOME" &&
32+
git config --global user.name "$USER_NAME" &&
33+
git config --global user.email "$USER_EMAIL" &&
34+
echo "PACKAGER=$USER_NAME <$USER_EMAIL>" >> $GITHUB_ENV
35+
- name: Clone build-extra
36+
run: git clone --single-branch -b main https://github.com/git-for-windows/build-extra $RUNNER_TEMP/build-extra
37+
- name: Prepare home directory for GPG signing
38+
if: env.GPGKEY != ''
39+
run: |
40+
echo '${{secrets.PRIVGPGKEY}}' | tr % '\n' | gpg $GPG_OPTIONS --import &&
41+
mkdir -p home &&
42+
git config --global gpg.program "$RUNNER_TEMP/build-extra/gnupg-with-gpgkey.sh" &&
43+
info="$(gpg --list-keys --with-colons "${GPGKEY%% *}" | cut -d : -f 1,10 | sed -n '/^uid/{s|uid:||p;q}')" &&
44+
git config --global user.name "${info% <*}" &&
45+
git config --global user.email "<${info#*<}"
46+
env:
47+
GPGKEY: ${{secrets.GPGKEY}}
48+
- uses: actions/setup-node@v3
49+
with:
50+
node-version: ${{env.NODEJS_VERSION}}
51+
- name: Generate bundle artifacts
52+
env:
53+
GPGKEY: ${{secrets.GPGKEY}}
54+
run: |
55+
mkdir -p bundle-artifacts &&
56+
git -c init.defaultBranch=main init --bare &&
57+
git remote add -f origin https://github.com/git-for-windows/git &&
58+
git fetch "https://github.com/$REPOSITORY" "$REF:$REF" &&
59+
tag_name="$(git describe --match 'v[0-9]*' FETCH_HEAD)" &&
60+
echo "prerelease-${tag_name#v}" >bundle-artifacts/ver &&
61+
echo "${tag_name#v}" >bundle-artifacts/display_version &&
62+
echo "$tag_name" >bundle-artifacts/next_version &&
63+
git tag $(test -z "$GPGKEY" || echo " -s") -m "Snapshot build" "$tag_name" FETCH_HEAD &&
64+
git bundle create bundle-artifacts/git.bundle origin/main.."$tag_name" &&
65+
release_note=$(git show -s --pretty='tformat:%h (%s, %ad)' --date=short FETCH_HEAD) &&
66+
cd $RUNNER_TEMP/build-extra &&
67+
node ./add-release-note.js --commit feature "Snapshot of $release_note" &&
68+
git bundle create "$GITHUB_WORKSPACE/bundle-artifacts/build-extra.bundle" origin/main..main
69+
- name: 'Publish Pipeline Artifact: bundle-artifacts'
70+
uses: actions/upload-artifact@v3
71+
with:
72+
name: bundle-artifacts
73+
path: ${{ github.workspace }}/bundle-artifacts

0 commit comments

Comments
 (0)