Skip to content

Commit 091bd8b

Browse files
authored
Automatically use latest patch for each Swift release in CI (#739)
1 parent d63c53d commit 091bd8b

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

.evergreen/config.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,26 @@ functions:
330330
done
331331
332332
"install swift":
333+
- command: shell.exec
334+
params:
335+
working_dir: "src"
336+
script: |
337+
set -o xtrace
338+
set -o errexit
339+
340+
if [ "${SWIFT_MINOR_VERSION}" = "main-snapshot" ]; then
341+
export SWIFT_VERSION="${SWIFT_MINOR_VERSION}"
342+
else
343+
# otherwise, find the latest patch release for the specified version
344+
${PYTHON} -m virtualenv ./requests-env
345+
./requests-env/${VENV_BIN_DIR}/python3 -m pip install requests
346+
export SWIFT_VERSION="$(./requests-env/${VENV_BIN_DIR}/python3 .evergreen/get_latest_swift_patch.py ${SWIFT_MINOR_VERSION})"
347+
fi
348+
echo "SWIFT_VERSION: $SWIFT_VERSION" > swift-version.yml
349+
cat swift-version.yml
350+
- command: expansions.update
351+
params:
352+
file: src/swift-version.yml
333353
- command: shell.exec
334354
params:
335355
working_dir: "src"
@@ -1094,27 +1114,27 @@ axes:
10941114
- id: "5.1"
10951115
display_name: "Swift 5.1"
10961116
variables:
1097-
SWIFT_VERSION: "5.1.5"
1117+
SWIFT_MINOR_VERSION: "5.1"
10981118
- id: "5.2"
10991119
display_name: "Swift 5.2"
11001120
variables:
1101-
SWIFT_VERSION: "5.2.5"
1121+
SWIFT_MINOR_VERSION: "5.2"
11021122
- id: "5.3"
11031123
display_name: "Swift 5.3"
11041124
variables:
1105-
SWIFT_VERSION: "5.3.3"
1125+
SWIFT_MINOR_VERSION: "5.3"
11061126
- id: "5.4"
11071127
display_name: "Swift 5.4"
11081128
variables:
1109-
SWIFT_VERSION: "5.4.2"
1129+
SWIFT_MINOR_VERSION: "5.4"
11101130
- id: "5.5"
11111131
display_name: "Swift 5.5"
11121132
variables:
1113-
SWIFT_VERSION: "5.5.1"
1133+
SWIFT_MINOR_VERSION: "5.5"
11141134
- id: "5.6-dev"
11151135
display_name: "Swift 5.6-dev"
11161136
variables:
1117-
SWIFT_VERSION: "main-snapshot"
1137+
SWIFT_MINOR_VERSION: "main-snapshot"
11181138

11191139
- id: ssl-auth
11201140
display_name: SSL and Auth
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import re
2+
import requests
3+
import sys
4+
5+
# This script accepts a version number in the form "x.y" as an argument. It will query the Swift Github
6+
# repo for releases and find the latest x.y.z patch release if available, and print out the matching tag.
7+
8+
if len(sys.argv) != 2:
9+
print("Expected 1 argument, but got: {}".format(sys.argv[1:]))
10+
exit(1)
11+
12+
version = sys.argv[1]
13+
components = version.split('.')
14+
if len(components) != 2:
15+
print("Expected version number in form x.y, got {}".format(version))
16+
exit(1)
17+
18+
major = components[0]
19+
minor = components[1]
20+
21+
version_regex = '^swift-({}\.{}(\.(\d+))?)-RELEASE$'.format(major, minor)
22+
23+
release_data = requests.get('https://api.github.com/repos/apple/swift/releases').json()
24+
tag_names = map(lambda release: release['tag_name'], release_data)
25+
26+
# find tags matching the specified regexes
27+
matches = filter(lambda match: match is not None, map(lambda tag: re.match(version_regex, tag), tag_names))
28+
29+
# sort matches by their patch versions. patch versions of 0 are omitted so substitute 0 when the group is None.
30+
sorted_matches = sorted(matches, key=lambda match: int(match.group(2)[1:]) if match.group(2) is not None else 0, reverse=True)
31+
32+
# map to the first match group which contains the full version number.
33+
sorted_version_numbers = map(lambda match: match.group(1), sorted_matches)
34+
print(next(sorted_version_numbers))

0 commit comments

Comments
 (0)