Skip to content

Commit fdffcbf

Browse files
committed
CI: skip publishing nightly build when no new commits since last publish
Attempting to publish an already published version using `sbt-sonatype` fails with a "Failed to promote the repository" error. There don't appear to be any configuration settings in `sbt-sontaype` for avoiding this, so instead we ask for published versions from the Maven Central metadata and skip the publish step if we find a match.
1 parent 69108bf commit fdffcbf

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,20 @@ jobs:
447447
- name: Add SBT proxy repositories
448448
run: cp -vf .github/workflows/repositories /root/.sbt/ ; true
449449

450+
- name: Get version string for this build
451+
run: |
452+
ver=$(./project/scripts/sbt "print scala3-compiler-bootstrapped/version" | tail -n1)
453+
echo "This build version: $ver"
454+
echo "THISBUILD_VERSION=$ver" >> $GITHUB_ENV
455+
456+
- name: Check whether not yet published
457+
id: not_yet_published
458+
continue-on-error: true
459+
run: |
460+
! ./project/scripts/is-version-published.sh "$THISBUILD_VERSION"
461+
450462
- name: Publish Nightly
463+
if: "steps.not_yet_published.outcome == 'success'"
451464
run: |
452465
./project/scripts/sbtPublish ";project scala3-bootstrapped ;publishSigned ;sonatypeBundleRelease"
453466
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
# Check whether a specific version of the Scala 3 compiler is published to Maven Central
4+
#
5+
# Usage:
6+
# is-version-published.sh <version_string>
7+
# e.g.
8+
# ./is-version-published.sh 3.0.1-RC1-bin-20210411-b44cafa-NIGHTLY
9+
#
10+
# Exit status:
11+
# zero if the specified version is published on Maven Central
12+
# non-zero otherwise
13+
14+
ver=$1
15+
if [[ -z "$ver" ]]; then
16+
echo "error: missing version parameter"
17+
echo "usage: $0 <version_string>"
18+
exit 2
19+
fi
20+
21+
set -eu
22+
23+
major=${ver%%-bin-*}
24+
maven_url=https://repo1.maven.org/maven2/org/scala-lang/scala3-compiler_$major/maven-metadata.xml
25+
26+
echo "Checking whether $ver is published"
27+
echo "at $maven_url"
28+
echo ""
29+
30+
published=$(curl -s --fail --show-error -L "$maven_url" | sed -ne '/<version>/ s!<version>\(.*\)</version>!\1! p')
31+
if [[ -n "$published" ]]; then
32+
echo "Found published versions:"
33+
echo "$published" | xargs -n1
34+
echo ""
35+
36+
for p in $published ; do
37+
if [[ "$p" == "$ver" ]]; then
38+
echo "Version $ver is already published."
39+
exit 0
40+
fi
41+
done
42+
echo "Version $ver is not yet published."
43+
exit 10
44+
else
45+
echo "Unable to determine published versions."
46+
exit 20
47+
fi

0 commit comments

Comments
 (0)