Skip to content

Commit 7b75a4a

Browse files
committed
git-artifacts: allow building from an existing tag
So far, we have an implementation of the common flow where the `tag-git` workflow is started to create "bundle-artifacts" including a Git bundle with the newly-tagged Git version and another Git bundle with the updated release notes. However, for the just-published Git for Windows v2.39.2, we would like to build the ARM64 flavor of the artifacts, i.e. for an _existing_ tag. Let's introduce two new inputs (referring to an existing tag and an existing build-extra revision) that can be used instead of the input referring to a `tag-git` workflow run, and handle that scenario, too. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7fe1247 commit 7b75a4a

File tree

1 file changed

+65
-4
lines changed

1 file changed

+65
-4
lines changed

.github/workflows/git-artifacts.yml

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ on:
2626
bundle_artifacts_workflow_run_id:
2727
description: 'Workflow run ID from bundle-artifacts pipeline'
2828
required: false
29+
existing_git_tag:
30+
description: 'Existing tag to build from. Requires bundle_artifacts_workflow_run_id to be empty'
31+
required: false
32+
build_extra_rev_for_existing_git_tag:
33+
description: 'build-extra revision to use if building from an existing Git tag. Required if existing_git_tag is non-empty'
34+
required: false
2935

3036
env:
3137
GPG_OPTIONS: "--batch --yes --no-tty --list-options no-show-photos --verify-options no-show-photos --pinentry-mode loopback"
@@ -36,6 +42,8 @@ env:
3642
REF: "${{github.event.inputs.ref}}"
3743
ARCHITECTURE: "${{github.event.inputs.architecture}}"
3844
BUNDLE_ARTIFACTS_WORKFLOW_RUN_ID: "${{github.event.inputs.bundle_artifacts_workflow_run_id}}"
45+
EXISTING_GIT_TAG: "${{github.event.inputs.existing_git_tag}}"
46+
BUILD_EXTRA_REV_FOR_EXISTING_GIT_TAG: "${{github.event.inputs.build_extra_rev_for_existing_git_tag}}"
3947

4048
defaults:
4149
run:
@@ -107,16 +115,43 @@ jobs:
107115
core.info('Preparing artifact build matrix...')
108116
const createArtifactsMatrix = require('./git-for-windows-automation/create-artifacts-matrix')
109117
createArtifactsMatrix(core, process.env.ARTIFACTS_TO_BUILD, process.env.ARCHITECTURE)
118+
- name: Construct bundle-artifacts from existing tag
119+
if: env.EXISTING_GIT_TAG != ''
120+
run: |
121+
die () {
122+
echo "$*" >&2
123+
exit 1
124+
}
125+
126+
test -z "$BUNDLE_ARTIFACTS_WORKFLOW_RUN_ID" ||
127+
die 'existing_git_tag cannot be used with bundle_artifacts_workflow_run_id!'
128+
129+
test -n "$BUILD_EXTRA_REV_FOR_EXISTING_GIT_TAG" ||
130+
die 'existing_git_tag needs build_extra_rev_for_existing_git_tag!'
131+
132+
set -o pipefail &&
133+
134+
mkdir -p bundle-artifacts &&
135+
echo "$EXISTING_GIT_TAG" >bundle-artifacts/next_version &&
136+
echo "$EXISTING_GIT_TAG" |
137+
sed -n '/^v[0-9]\+\.[0-9]\+\.[0-9]\+\.windows\.[0-9]\+$/{s/^v//;s/\.windows\.1//;s/\.windows\.\(.*\)/(\1)/;p}' \
138+
>bundle-artifacts/display_version &&
139+
sed 's/(\(.*\))$/.\1/' <bundle-artifacts/display_version >bundle-artifacts/ver
110140
- uses: actions/github-script@v6
141+
if: env.BUNDLE_ARTIFACTS_WORKFLOW_RUN_ID != ''
111142
id: get-bundle-artifacts-url
112143
name: Get bundle-artifacts download URL
113144
with:
114145
script: |
146+
if (process.env.EXISTING_GIT_TAG || process.env.BUILD_EXTRA_REV_FOR_EXISTING_GIT_TAG) {
147+
throw new Error('bundle_artifacts_workflow_run_id cannot be used with existing_git_tag or build_extra_rev_for_existing_git_tag!')
148+
}
115149
const getArtifact = require('./git-for-windows-automation/get-bundle-artifacts-artifact')
116150
const workflowId = process.env.BUNDLE_ARTIFACTS_WORKFLOW_RUN_ID
117151
core.info('Getting download URL for bundle-artifacts...')
118152
await getArtifact(github, context, core, workflowId)
119153
- name: Download bundle-artifacts zip
154+
if: env.BUNDLE_ARTIFACTS_WORKFLOW_RUN_ID != ''
120155
run: |
121156
mkdir bundle-artifacts
122157
curl -o bundle-artifacts.zip "${{steps.get-bundle-artifacts-url.outputs.downloadUrl}}"
@@ -137,13 +172,24 @@ jobs:
137172
git -C $d fetch https://github.com/git-for-windows/build-extra main &&
138173
git -C $d switch -C main FETCH_HEAD
139174
fi &&
140-
git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main
175+
if test -z "$BUILD_EXTRA_REV_FOR_EXISTING_GIT_TAG"
176+
then
177+
git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main
178+
else
179+
git -C $d fetch origin "$BUILD_EXTRA_REV_FOR_EXISTING_GIT_TAG" &&
180+
git reset --hard "$BUILD_EXTRA_REV_FOR_EXISTING_GIT_TAG"
181+
fi
141182
- name: Check out git/git
142183
shell: bash
143184
run: |
144185
git -c init.defaultBranch=main init &&
145186
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) &&
187+
if test -n "$EXISTING_GIT_TAG"
188+
then
189+
git fetch origin "refs/tags/$EXISTING_GIT_TAG:refs/tags/$EXISTING_GIT_TAG"
190+
else
191+
git fetch --tags bundle-artifacts/git.bundle $(cat bundle-artifacts/next_version)
192+
fi &&
147193
git reset --hard $(cat bundle-artifacts/next_version)
148194
- name: Prepare home directory for code-signing
149195
env:
@@ -193,7 +239,16 @@ jobs:
193239
version=$(cat bundle-artifacts/next_version) &&
194240
(cd /usr/src/MINGW-packages/mingw-w64-git &&
195241
cp PKGBUILD.$version PKGBUILD &&
196-
git commit -s -m "mingw-w64-git: new version ($version)" PKGBUILD &&
242+
if test -z "$EXISTING_GIT_TAG"
243+
then
244+
git commit -s -m "mingw-w64-git: new version ($version)" PKGBUILD
245+
elif ! git update-index --ignore-submodules --refresh ||
246+
! git diff-files --ignore-submodules ||
247+
! git diff-index --cached --ignore-submodules HEAD
248+
then
249+
echo "::warning::Uncommitted changes after build!" >&2
250+
git diff >&2
251+
fi &&
197252
git bundle create "$b"/MINGW-packages.bundle origin/main..main)
198253
- name: Publish ${{env.MINGW_PACKAGE_PREFIX}}-git
199254
uses: actions/upload-artifact@v3
@@ -235,7 +290,13 @@ jobs:
235290
git -C $d fetch https://github.com/git-for-windows/build-extra main &&
236291
git -C $d switch -C main FETCH_HEAD
237292
fi &&
238-
git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main
293+
if test -z "$BUILD_EXTRA_REV_FOR_EXISTING_GIT_TAG"
294+
then
295+
git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main
296+
else
297+
git -C $d fetch origin "$BUILD_EXTRA_REV_FOR_EXISTING_GIT_TAG" &&
298+
git reset --hard "$BUILD_EXTRA_REV_FOR_EXISTING_GIT_TAG"
299+
fi
239300
- name: Prepare home directory for code-signing
240301
env:
241302
CODESIGN_P12: ${{secrets.CODESIGN_P12}}

0 commit comments

Comments
 (0)