Skip to content

Commit 94cec9f

Browse files
devversionmmalerba
authored andcommitted
build: do generate invalid semver versions for snapshot builds (#17267)
Apparently there is a long-standing issue in the snapshot builds where we generate invalid versions if the snapshot SHA starts with zero's. In order to fix this, we need to ensure that the commit SHA is part of a version segment that starts with text (i.e. `-sha-{val}`). Fixes #17264
1 parent 8c98013 commit 94cec9f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

scripts/deploy/publish-build-artifacts.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ publishPackage() {
3838
commitAuthorEmail=$(git --no-pager show -s --format='%ae' HEAD)
3939
commitMessage=$(git log --oneline -n 1)
4040

41-
buildVersionName="${buildVersion}-${commitSha}"
41+
# Note that we cannot store the commit SHA in its own version segment
42+
# as it will not comply with the semver specification. For example:
43+
# 1.0.0-00abcdef will break since the SHA starts with zeros. To fix this,
44+
# we create a new version segment with the following format: "1.0.0-sha-00abcdef".
45+
# See issue: https://jubianchi.github.io/semver-check/#/^8.0.0/8.2.2-0462599
46+
buildVersionName="${buildVersion}-sha-${commitSha}"
4247
buildTagName="${branchName}-${commitSha}"
4348
buildCommitMessage="${branchName} - ${commitMessage}"
4449

@@ -89,7 +94,7 @@ publishPackage() {
8994

9095
# Replace the version in every file recursively with a more specific version that also includes
9196
# the SHA of the current build job. Normally this "sed" call would just replace the version
92-
# placeholder, but the version placeholders have been replaced by the release task already.
97+
# placeholder, but the version placeholders have been replaced by "npm_package" already.
9398
sed -i "s/${buildVersion}/${buildVersionName}/g" $(find . -type f -not -path '*\/.*')
9499

95100
echo "Updated the build version in every file to include the SHA of the latest commit."

scripts/deploy/publish-docs-content.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ commitAuthorEmail=$(git --no-pager show -s --format='%ae' HEAD)
4242
commitMessage=$(git log --oneline -n 1)
4343
commitTag="${buildVersion}-${commitSha}"
4444

45-
buildVersionName="${buildVersion}-${commitSha}"
45+
# Note that we cannot store the commit SHA in its own version segment
46+
# as it will not comply with the semver specification. For example:
47+
# 1.0.0-00abcdef will break since the SHA starts with zeros. To fix this,
48+
# we create a new version segment with the following format: "1.0.0-sha-00abcdef".
49+
# See issue: https://jubianchi.github.io/semver-check/#/^8.0.0/8.2.2-0462599
50+
buildVersionName="${buildVersion}-sha-${commitSha}"
4651
buildTagName="${branchName}-${commitSha}"
4752
buildCommitMessage="${branchName} - ${commitMessage}"
4853

@@ -86,6 +91,11 @@ if [[ $(git ls-remote origin "refs/tags/${buildTagName}") ]]; then
8691
exit 0
8792
fi
8893

94+
# Replace the version in every file recursively with a more specific version that also includes
95+
# the SHA of the current build job. Normally this "sed" call would just replace the version
96+
# placeholder, but the version placeholders have been replaced by "npm_package" already.
97+
sed -i "s/${buildVersion}/${buildVersionName}/g" $(find . -type f -not -path '*\/.*')
98+
8999
# Setup the Git configuration
90100
git config user.name "$commitAuthorName"
91101
git config user.email "$commitAuthorEmail"

0 commit comments

Comments
 (0)