Skip to content

Commit b59566f

Browse files
authored
Merge pull request #16246 from argotorg/prerelease-logic-update
Correct handling of tagged prereleases
2 parents 728ecd6 + 8439e2a commit b59566f

File tree

8 files changed

+69
-56
lines changed

8 files changed

+69
-56
lines changed

.circleci/config.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,12 @@ commands:
182182
# --------------------------------------------------------------------------
183183
# Build Commands
184184

185-
setup_prerelease_commit_hash:
185+
setup_prerelease:
186186
steps:
187187
- run:
188-
name: Store commit hash and prerelease
188+
name: Store prerelease suffix
189189
command: |
190-
if [[ $CIRCLE_BRANCH == release || -n $CIRCLE_TAG ]]; then
191-
echo -n > prerelease.txt;
192-
else
193-
date -u +"nightly.%Y.%-m.%-d" > prerelease.txt;
194-
fi
195-
echo -n "$CIRCLE_SHA1" > commit_hash.txt
190+
"scripts/prerelease_suffix.sh" nightly "$CIRCLE_TAG" > prerelease.txt
196191
197192
install_and_check_minimum_requirements:
198193
parameters:
@@ -1006,6 +1001,7 @@ jobs:
10061001
<<: *base_ubuntu2404_xlarge
10071002
steps:
10081003
- build
1004+
- run: cat prerelease.txt
10091005

10101006
# x64 ASAN build, for testing for memory related bugs
10111007
b_ubu_asan: &b_ubu_asan
@@ -1115,7 +1111,7 @@ jobs:
11151111
<<: *base_ubuntu_clang_large
11161112
steps:
11171113
- checkout
1118-
- setup_prerelease_commit_hash
1114+
- setup_prerelease
11191115
- run_build_ossfuzz
11201116
- persist_ossfuzz_executables_to_workspace
11211117
- matrix_notify_failure_unless_pr
@@ -1225,7 +1221,7 @@ jobs:
12251221
<<: *base_ubuntu2404_small
12261222
steps:
12271223
- checkout
1228-
- setup_prerelease_commit_hash
1224+
- setup_prerelease
12291225
- run:
12301226
name: Install build system dependencies
12311227
command: |

docs/conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ def get_github_username_repo(url):
126126
with open('../CMakeLists.txt', 'r', encoding='utf8') as f:
127127
version = re.search('PROJECT_VERSION "([^"]+)"', f.read()).group(1)
128128
# The full version, including alpha/beta/rc tags.
129-
if not os.path.isfile('../prerelease.txt') or os.path.getsize('../prerelease.txt') == 0:
129+
if os.path.isfile('../prerelease.txt') and os.path.getsize('../prerelease.txt') == 0:
130130
release = version
131+
elif os.path.isfile('../prerelease.txt'):
132+
with open('../prerelease.txt', 'r', encoding='utf8') as prerelease_file:
133+
release = version + '-' + prerelease_file.read()
131134
else:
132-
# This is a prerelease version
133135
release = version + '-develop'
134136

135137
# The language for content autogenerated by Sphinx. Refer to documentation

scripts/build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ else
1010
BUILD_TYPE="$1"
1111
fi
1212

13-
if [[ $(git tag --points-at HEAD 2> /dev/null) == v* ]]; then
14-
touch "${ROOTDIR}/prerelease.txt"
13+
# Intentionally not using prerelease_suffix.sh here. We do not want lingering prerelease.txt in
14+
# dev builds, accidentally overriding version when someone runs the build manually.
15+
if [[ $(git tag --points-at HEAD 2> /dev/null) =~ ^v[0-9.]+$ ]]; then
16+
echo -n > prerelease.txt
1517
fi
1618

1719
mkdir -p "$BUILDDIR"

scripts/ci/build.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,12 @@ prerelease_source="${1:-ci}"
99

1010
cd "${ROOTDIR}"
1111

12-
if [[ $CIRCLE_BRANCH == release || -n $CIRCLE_TAG || -n $FORCE_RELEASE ]]; then
13-
echo -n > prerelease.txt
14-
else
15-
# Use last commit date rather than build date to avoid ending up with builds for
16-
# different platforms having different version strings (and therefore producing different bytecode)
17-
# if the CI is triggered just before midnight.
18-
TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="${prerelease_source}.%cd" > prerelease.txt
19-
fi
20-
21-
if [[ -n $CIRCLE_SHA1 ]]; then
22-
echo -n "$CIRCLE_SHA1" > commit_hash.txt
23-
fi
12+
"${ROOTDIR}/scripts/prerelease_suffix.sh" "$prerelease_source" "$CIRCLE_TAG" > prerelease.txt
2413

2514
mkdir -p build
2615
cd build
2716

28-
[[ -n $COVERAGE && $CIRCLE_BRANCH != release && -z $CIRCLE_TAG ]] && CMAKE_OPTIONS="$CMAKE_OPTIONS -DCOVERAGE=ON"
17+
[[ -n $COVERAGE && -z $CIRCLE_TAG ]] && CMAKE_OPTIONS="$CMAKE_OPTIONS -DCOVERAGE=ON"
2918

3019
# shellcheck disable=SC2086
3120
cmake .. -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Release}" $CMAKE_OPTIONS

scripts/ci/build_emscripten.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,7 @@ function build() {
4545

4646
cd "${ROOT_DIR}"
4747

48-
if [[ $CIRCLE_BRANCH == release || -n $CIRCLE_TAG || -n $FORCE_RELEASE || $(git tag --points-at HEAD 2> /dev/null) == v* ]]; then
49-
echo -n > prerelease.txt
50-
else
51-
# Use last commit date rather than build date to avoid ending up with builds for
52-
# different platforms having different version strings (and therefore producing different bytecode)
53-
# if the CI is triggered just before midnight.
54-
TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="${prerelease_source}.%cd" > prerelease.txt
55-
fi
56-
if [[ -n $CIRCLE_SHA1 ]]; then
57-
echo -n "$CIRCLE_SHA1" > commit_hash.txt
58-
fi
48+
"${SCRIPT_DIR}/prerelease_suffix.sh" "$prerelease_source" "$(git tag --points-at HEAD 2> /dev/null)" > prerelease.txt
5949

6050
# Disable warnings for unqualified `move()` calls, introduced and enabled by
6151
# default in clang-16 which is what the emscripten docker image uses.

scripts/ci/build_win.sh

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,7 @@ FORCE_RELEASE="${FORCE_RELEASE:-}"
88
CIRCLE_TAG="${CIRCLE_TAG:-}"
99

1010
cd "$ROOTDIR"
11-
if [[ $FORCE_RELEASE != "" || $CIRCLE_TAG != "" ]]; then
12-
echo -n > prerelease.txt
13-
else
14-
# Use last commit date rather than build date to avoid ending up with builds for
15-
# different platforms having different version strings (and therefore producing different bytecode)
16-
# if the CI is triggered just before midnight.
17-
# NOTE: The -local suffix makes git not use the timezone from the commit but instead convert to
18-
# local one, which we explicitly set to UTC.
19-
# NOTE: git --date is supposed to support the %-m/%-d format too, but it does not seem to
20-
# work on Windows. Without it we get leading zeros for month and day.
21-
last_commit_date=$(TZ=UTC git show --quiet --date="format-local:%Y-%m-%d" --format="%cd")
22-
last_commit_date_stripped=$(date --date="$last_commit_date" "+%Y.%-m.%-d")
23-
echo -n "${prerelease_source}.${last_commit_date_stripped}" > prerelease.txt
24-
fi
11+
"${ROOTDIR}/scripts/prerelease_suffix.sh" "$prerelease_source" "$CIRCLE_TAG" > prerelease.txt
2512

2613
mkdir -p build/
2714
cd build/

scripts/create_source_tarball.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,36 @@
22
set -euo pipefail
33

44
REPO_ROOT="$(dirname "$0")"/..
5+
# shellcheck source=scripts/common.sh
6+
source "${REPO_ROOT}/scripts/common.sh"
7+
58
cd "$REPO_ROOT"
69
version=$(scripts/get_version.sh)
710
commit_hash=$(git rev-parse --short=8 HEAD)
8-
commit_date=$(git show --format=%ci HEAD | head -n 1 | cut - -b1-10 | sed -e 's/-0?/./' | sed -e 's/-0?/./')
911

10-
# File exists and has zero size -> not a prerelease
11-
if [[ -e prerelease.txt && ! -s prerelease.txt ]]; then
12-
version_string="$version"
12+
if [[ -e prerelease.txt ]]; then
13+
prerelease_suffix=$(cat prerelease.txt)
14+
if [[ $prerelease_suffix == "" ]]; then
15+
# File exists and has zero size -> not a prerelease
16+
version_string="$version"
17+
elif [[ $prerelease_suffix == pre.* ]]; then
18+
# Tagged prerelease -> unambiguous, so commit hash not needed
19+
version_string="${version}-${prerelease_suffix}"
20+
else
21+
# Nightly/develop/other prerelease -> include commit hash
22+
version_string="${version}-${prerelease_suffix}-${commit_hash}"
23+
fi
1324
else
25+
# Nightly/develop/other prerelease -> include commit hash + default prerelease suffix
26+
commit_date=$(TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="%cd")
1427
version_string="${version}-nightly-${commit_date}-${commit_hash}"
1528
fi
1629

30+
# The only purpose of commit_hash.txt is to make it possible to build the compiler without git.
31+
# It is not meant as an override of the real hash.
32+
[[ ! -e commit_hash.txt ]] || \
33+
fail "commit_hash.txt is present in the repository root, but will not be used to override the commit hash for the source package."
34+
1735
TEMPDIR=$(mktemp -d -t "solc-src-tarball-XXXXXX")
1836
SOLDIR="${TEMPDIR}/solidity_${version_string}/"
1937
mkdir "$SOLDIR"

scripts/prerelease_suffix.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
(( $# <= 2 )) || { >&2 echo "Usage: $0 [PRERELEASE_SOURCE] [GIT_TAG]"; exit 1; }
5+
prerelease_source="${1:-nightly}"
6+
git_tag="${2:-}"
7+
FORCE_RELEASE="${FORCE_RELEASE:-}"
8+
9+
GNU_DATE="date"
10+
if [[ "$OSTYPE" == "darwin"* ]]; then
11+
GNU_DATE=gdate
12+
fi
13+
14+
if [[ $FORCE_RELEASE != "" || $git_tag =~ ^v[0-9.]+$ ]]; then
15+
echo -n
16+
elif [[ $git_tag =~ ^v[0-9.]+-pre. ]]; then
17+
echo -n "pre.${git_tag#*-pre.}"
18+
else
19+
# Use last commit date rather than build date to avoid ending up with builds for
20+
# different platforms having different version strings (and therefore producing different bytecode)
21+
# if the CI is triggered just before midnight.
22+
# NOTE: The -local suffix makes git not use the timezone from the commit but instead convert to
23+
# local one, which we explicitly set to UTC.
24+
# NOTE: git --date is supposed to support the %-m/%-d format too, but it does not seem to
25+
# work on Windows. Without it we get leading zeros for month and day.
26+
last_commit_date=$(TZ=UTC git show --quiet --date="format-local:%Y-%m-%d" --format="%cd")
27+
last_commit_date_stripped=$("$GNU_DATE" --date "$last_commit_date" "+%Y.%-m.%-d")
28+
echo -n "${prerelease_source}.${last_commit_date_stripped}"
29+
fi

0 commit comments

Comments
 (0)