Skip to content

Commit 200e424

Browse files
committed
add support for publishing an old release against a new Scala
taken from scala/scala-swing#60
1 parent 02da785 commit 200e424

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

admin/README.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ To configure tag driven releases from Travis CI.
1919
Edit `.travis.yml` as prompted.
2020
4. Edit `.travis.yml` to use `./admin/build.sh` as the build script,
2121
and edit that script to use the tasks required for this project.
22-
5. Edit `build.sbt` to select which JDK will be used for publishing.
22+
5. Edit `build.sbt`'s `scalaVersionsByJvm` to select which Scala and JDK will
23+
be used for publishing.
2324

2425
It is important to add comments in .travis.yml to identify the name
2526
of each environment variable encoded in a `:secure` section.
@@ -37,12 +38,13 @@ form:
3738
# SONA_PASS
3839
- secure: "XXXXXX"
3940
script: admin/build.sh
41+
jdk:
42+
- openjdk6
43+
- oraclejdk8
4044

4145
If Sonatype credentials change in the future, step 3 can be repeated
4246
without generating a new key.
4347

44-
Be sure to use SBT 0.13.7 or higher to avoid [#1430](https://github.com/sbt/sbt/issues/1430)!
45-
4648
### Testing
4749

4850
1. Follow the release process below to create a dummy release (e.g. 0.1.0-TEST1).
@@ -53,8 +55,13 @@ Be sure to use SBT 0.13.7 or higher to avoid [#1430](https://github.com/sbt/sbt/
5355

5456
1. Create a GitHub "Release" (with a corresponding tag) via the GitHub
5557
web interface.
56-
2. Travis CI will schedule a build for this release. Review the build logs.
57-
3. Log into https://oss.sonatype.org/ and identify the staging repository.
58-
4. Sanity check its contents
59-
5. Release staging repository to Maven and send out release announcement.
58+
2. The release will be published using the Scala and JVM version combinations specified
59+
in `scalaVersionsByJvm` in `build.sbt`.
60+
- If you need to release against a different Scala version, include the Scala version
61+
and the JVM version to use in the tag name, separated by `#`s (e.g., `v0.1.1#2.13.0-M1#8`).
62+
Note that the JVM version needs to be listed in `.travis.yml` for the build to run.
63+
3. Travis CI will schedule a build for this release. Review the build logs.
64+
4. Log into https://oss.sonatype.org/ and identify the staging repository.
65+
5. Sanity check its contents
66+
6. Release staging repository to Maven and send out release announcement.
6067

admin/build.sh

+43-15
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,52 @@
22

33
set -e
44

5-
# prep environment for publish to sonatype staging if the HEAD commit is tagged
5+
# Builds of tagged revisions are published to sonatype staging.
66

7-
# git on travis does not fetch tags, but we have TRAVIS_TAG
8-
# headTag=$(git describe --exact-match ||:)
7+
# Travis runs a build on new revisions and on new tags, so a tagged revision is built twice.
8+
# Builds for a tag have TRAVIS_TAG defined, which we use for identifying tagged builds.
9+
# Checking the local git clone would not work because git on travis does not fetch tags.
910

10-
if [[ "$TRAVIS_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)? ]]; then
11-
echo "Going to release from tag $TRAVIS_TAG!"
12-
myVer=$(echo $TRAVIS_TAG | sed -e s/^v//)
13-
publishVersion='set every version := "'$myVer'"'
14-
extraTarget="+publish-signed"
15-
cat admin/gpg.sbt >> project/plugins.sbt
16-
cp admin/publish-settings.sbt .
11+
# The version number to be published is extracted from the tag, e.g., v1.2.3 publishes
12+
# version 1.2.3 using all Scala versions in build.sbt's `crossScalaVersions`.
1713

18-
# Copied from the output of genKeyPair.sh
19-
K=$encrypted_5e972ec514e2_key
20-
IV=$encrypted_5e972ec514e2_iv
14+
# When a new, binary incompatible Scala version becomes available, a previously released version
15+
# can be released using that new Scala version by creating a new tag containing the Scala and the
16+
# JVM version after hashes, e.g., v1.2.3#2.13.0-M1#8. The JVM version needs to be listed in
17+
# `.travis.yml`, otherwise the required build doesn't run.
2118

22-
openssl aes-256-cbc -K $K -iv $IV -in admin/secring.asc.enc -out admin/secring.asc -d
19+
verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?"
20+
tagPat="^v$verPat(#$verPat#[0-9]+)?$"
21+
22+
if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
23+
currentJvmVer=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | sed 's/^1\.//' | sed 's/[^0-9].*//')
24+
25+
tagVer=$(echo $TRAVIS_TAG | sed s/#.*// | sed s/^v//)
26+
publishVersion='set every version := "'$tagVer'"'
27+
scalaAndJvmVer=$(echo $TRAVIS_TAG | sed s/[^#]*// | sed s/^#//)
28+
if [ "$scalaAndJvmVer" != "" ]; then
29+
scalaVer=$(echo $scalaAndJvmVer | sed s/#.*//)
30+
jvmVer=$(echo $scalaAndJvmVer | sed s/[^#]*// | sed s/^#//)
31+
if [ "$jvmVer" != "$currentJvmVer" ]; then
32+
echo "Not publishing $TRAVIS_TAG on Java version $currentJvmVer."
33+
exit 0
34+
fi
35+
publishScalaVersion='set every scalaVersionsByJvm := Map('$jvmVer' -> List("'$scalaVer'" -> true))'
36+
echo "Releasing $tagVer using Scala $scalaVer on Java version $jvmVer."
37+
else
38+
echo "Releasing $tagVer on Java version $currentJvmVer according to 'scalaVersionsByJvm' in build.sbt."
39+
fi
40+
41+
42+
extraTarget="+publish-signed"
43+
cat admin/gpg.sbt >> project/plugins.sbt
44+
cp admin/publish-settings.sbt .
45+
46+
# Copied from the output of genKeyPair.sh
47+
K=$encrypted_5e972ec514e2_key
48+
IV=$encrypted_5e972ec514e2_iv
49+
50+
openssl aes-256-cbc -K $K -iv $IV -in admin/secring.asc.enc -out admin/secring.asc -d
2351
fi
2452
25-
sbt "$publishVersion" clean update +test +publishLocal $extraTarget
53+
sbt "$publishVersion" "$publishScalaVersion" clean update +test +publishLocal $extraTarget

0 commit comments

Comments
 (0)