Skip to content

Commit b8715f5

Browse files
committed
Perform dynamic matching of latest and snapshot swift-version inputs
1 parent a823b0a commit b8715f5

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

action.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,38 @@ runs:
112112
# https://github.com/skiptools/swift-android-toolchain/releases/download/6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a-android-24-0.1.artifactbundle.tar.gz.zip
113113
# https://download.swift.org/swift-6.1-branch/ubuntu2404/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a-ubuntu24.04.tar.gz
114114
115-
SWIFT_VERSION=${{ inputs.swift-version }}
116-
117115
# fetch the most recent release tag from the toolchain repo
118-
#LATEST_RELEASE=$(curl -fsSL -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" --retry 10 --retry-max-time 600 https://api.github.com/repos/skiptools/swift-android-toolchain/releases/latest | jq -r '.tag_name')
119116
# disabled because it frequently gives "The requested URL returned error: 403"
117+
#LATEST_RELEASE=$(curl -fsSL -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" --retry 10 --retry-max-time 600 https://api.github.com/repos/skiptools/swift-android-toolchain/releases/latest | jq -r '.tag_name')
118+
119+
# fetch the Atom feed for the latest releases
120+
curl -fsSL --retry 8 --retry-connrefused https://github.com/skiptools/swift-android-toolchain/releases.atom --output ~/swift-releases.xml
121+
yq -oy '.feed.entry[].title' ~/swift-releases.xml | sort -rn > ~/swift-versions.txt
120122
121-
# we hardcode the latest builds and will need to update them every time a new snapshot is released
122-
LATEST_RELEASE="6.0.3"
123-
LATEST_SNAPSHOT="6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a"
123+
# if we hardcode the latest builds, we would need to update them every time a new snapshot is released
124+
125+
SWIFT_VERSION=${{ inputs.swift-version }}
124126
125127
# translate swift-version "latest" into our known latest version
126-
if [[ "${SWIFT_VERSION}" == '6.0' || "${SWIFT_VERSION}" == 'latest' ]]; then
127-
SWIFT_VERSION="${LATEST_RELEASE}"
128-
elif [[ "${SWIFT_VERSION}" == '6.1' || "${SWIFT_VERSION}" == 'snapshot' ]]; then
129-
SWIFT_VERSION="${LATEST_SNAPSHOT}"
128+
if [[ "${SWIFT_VERSION}" == 'latest' ]]; then
129+
#LATEST_RELEASE="6.0.3"
130+
#SWIFT_VERSION="${LATEST_RELEASE}"
131+
# use the latest non-snapshot release
132+
SWIFT_VERSION=$(cat ~/swift-versions.txt | grep -v -- '-SNAPSHOT' | head -n 1)
133+
elif [[ "${SWIFT_VERSION}" == 'snapshot' ]]; then
134+
#LATEST_SNAPSHOT="6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a"
135+
#SWIFT_VERSION="${LATEST_SNAPSHOT}"
136+
# use the latest snapshot release
137+
SWIFT_VERSION=$(cat ~/swift-versions.txt | grep -- '-SNAPSHOT' | head -n 1)
138+
else
139+
# match "6.0" to "6.0.3"
140+
# match "6.1" to "6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a"
141+
SWIFT_VERSION=$(cat ~/swift-versions.txt | grep -- "^${SWIFT_VERSION}" | head -n 1)
142+
fi
143+
144+
if [[ "${SWIFT_VERSION}" == "" ]]; then
145+
echo "::error::Could not find any swift version matching: ${{ inputs.swift-version }}"
146+
exit 1
130147
fi
131148
132149
echo "SWIFT_VERSION: ${SWIFT_VERSION}"

0 commit comments

Comments
 (0)