Skip to content

Commit cf30a4a

Browse files
authored
Merge pull request #226 from lrytz/gh-upload
add ghUpload for publishing to GitHub releases
2 parents 3755b0e + 9ac9d3f commit cf30a4a

File tree

13 files changed

+91
-93
lines changed

13 files changed

+91
-93
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ install:
2222
- sudo apt-get install -y rpm
2323

2424
language: scala
25-
jdk: openjdk8
25+
# java 11+ needed for sttp
26+
jdk: openjdk21
2627

2728
env:
2829
global:

admin/build.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ if ($env:APPVEYOR_FORCED_BUILD -eq 'true') {
3434
ensureVersion
3535
clearIvyCache
3636
if ($env:mode -eq 'release') {
37-
echo "Running a release for $env:version"
38-
$repositoriesFile="$env:APPVEYOR_BUILD_FOLDER\conf\repositories"
39-
& cmd /c "sbt ""-Dsbt.override.build.repos=true"" ""-Dsbt.repository.config=$repositoriesFile"" ""-Dproject.version=$env:version"" ""show fullResolvers"" clean update s3Upload" '2>&1'
37+
if ($env:version -match '-bin-' -or $env:version -match '-pre-') {
38+
& cmd /c "sbt ""-Dproject.version=$env:version"" clean update ""show s3Upload/mappings""" '2>&1'
39+
} else {
40+
echo "Running a release for $env:version"
41+
& cmd /c "sbt ""-Dproject.version=$env:version"" clean update ghUpload" '2>&1'
42+
}
4043
checkExit
4144
} else {
4245
echo "Unknown mode: '$env:mode'"

admin/build.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,20 @@ if [[ "$TRAVIS_EVENT_TYPE" == "api" ]]; then
9090
setupSSH
9191
. scripts/jobs/release/website/update-api
9292
elif [[ "$mode" == "release" ]]; then
93-
echo "Running a release for $version"
9493
triggerMsiRelease
95-
repositoriesFile="$TRAVIS_BUILD_DIR/conf/repositories"
96-
# The log is too long for the travis UI, so remove ANSI codes to have a clean raw version
97-
sbt -Dsbt.log.noformat=true \
98-
-Dsbt.override.build.repos=true -Dsbt.repository.config="$repositoriesFile" \
99-
-Dproject.version=$version \
100-
"show fullResolvers" clean update s3Upload
101-
triggerSmoketest
94+
if [[ "$version" =~ -bin- || "$version" =~ -pre- ]]; then
95+
# The log is too long for the travis UI, so remove ANSI codes to have a clean raw version
96+
sbt -Dsbt.log.noformat=true \
97+
-Dproject.version=$version \
98+
clean update "show s3Upload/mappings"
99+
else
100+
echo "Running a release for $version"
101+
# The log is too long for the travis UI, so remove ANSI codes to have a clean raw version
102+
sbt -Dsbt.log.noformat=true \
103+
-Dproject.version=$version \
104+
clean update ghUpload
105+
triggerSmoketest
106+
fi
102107
else
103108
echo "Unknown build mode: '$mode'"
104109
exit 1

appveyor.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ branches:
66
- 2.12.x
77
- 2.13.x
88

9-
image: Visual Studio 2015
9+
image: Visual Studio 2019
1010

1111
environment:
12-
JAVA_HOME: C:\Program Files\Java\jdk1.8.0
12+
# java 11+ needed for sttp
13+
JAVA_HOME: C:\Program Files\Java\jdk21
1314
AWS_ACCESS_KEY_ID:
1415
secure: X1Ix1soRBDMtfbi8IFNPOggDP2XquhW+uKcJ+XC0kiM=
1516
AWS_SECRET_ACCESS_KEY:
@@ -18,7 +19,7 @@ environment:
1819
secure: nfWNfbyzNQwdg1eWHZX93XIJLoAhFOr1fR8+L86s7a3jdo/HydEZ8TyEKsPipQ+/
1920

2021
install:
21-
- cmd: choco install sbt --version=1.3.2 -ia "INSTALLDIR=""C:\sbt"""
22+
- cmd: choco install sbt --version=1.10.11 -ia "INSTALLDIR=""C:\sbt"""
2223
- cmd: SET PATH=C:\sbt\bin;%JAVA_HOME%\bin;%PATH%
2324

2425
build_script:

build.sbt

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import ScalaDist.upload
1+
import ScalaDist.{s3Upload, ghUpload}
2+
3+
resolvers += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/"
24

35
// so we don't require a native git install
46
useJGit
@@ -22,9 +24,9 @@ Versioning.settings
2224
// are known/understood, at scala/scala-dist#171
2325
scalaVersion := version.value
2426

25-
upload / mappings := Seq()
27+
s3Upload / mappings := Seq()
2628

27-
upload := {
29+
s3Upload := {
2830
import com.amazonaws.services.s3.AmazonS3ClientBuilder
2931
import com.amazonaws.services.s3.model.PutObjectRequest
3032
import com.amazonaws.regions.Regions
@@ -33,12 +35,50 @@ upload := {
3335
val client = AmazonS3ClientBuilder.standard.withRegion(Regions.US_EAST_1).build
3436

3537
val log = streams.value.log
36-
(upload / mappings).value map { case (file, key) =>
38+
(s3Upload / mappings).value map { case (file, key) =>
3739
log.info("Uploading "+ file.getAbsolutePath() +" as "+ key)
3840
client.putObject(new PutObjectRequest("downloads.typesafe.com", key, file))
3941
}
4042
}
4143

44+
ghUpload := {
45+
import sttp.client3._
46+
import _root_.io.circe._, _root_.io.circe.parser._
47+
48+
val log = streams.value.log
49+
val ghRelease = s"v${(Universal / version).value}"
50+
51+
val token = sys.env.getOrElse("GITHUB_OAUTH_TOKEN", throw new MessageOnlyException("GITHUB_OAUTH_TOKEN missing"))
52+
53+
val backend = HttpURLConnectionBackend()
54+
55+
val rRes = basicRequest
56+
.get(uri"https://github.com/api/repos/scala/scala/releases/tags/$ghRelease")
57+
.header("Accept", "application/vnd.github+json")
58+
.header("Authorization", s"Bearer $token")
59+
.header("X-GitHub-Api-Version", "2022-11-28")
60+
.send(backend)
61+
val releaseId = rRes.body.flatMap(parse).getOrElse(Json.Null).hcursor.downField("id").as[Int].getOrElse(
62+
throw new MessageOnlyException(s"Release not found: $ghRelease"))
63+
64+
(s3Upload / mappings).value map { case (file, _) =>
65+
log.info(s"Uploading ${file.getAbsolutePath} as ${file.getName} to https://github.com/scala/scala/releases/tag/$ghRelease")
66+
67+
// https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset
68+
val request = basicRequest
69+
.post(uri"https://uploads.github.com/repos/scala/scala/releases/${releaseId}/assets?name=${file.getName}")
70+
.contentType("application/octet-stream")
71+
.header("Accept", "application/vnd.github+json")
72+
.header("Authorization", s"Bearer $token")
73+
.header("X-GitHub-Api-Version", "2022-11-28")
74+
.body(file)
75+
76+
val response = request.send(backend)
77+
if (response.code.code != 201)
78+
throw new MessageOnlyException(s"Upload failed: status=${response.code}\n${response.body}")
79+
}
80+
}
81+
4282
ScalaDist.settings
4383

4484
Docs.settings

conf/repositories

Lines changed: 0 additions & 8 deletions
This file was deleted.

project/ScalaDist.scala

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import com.amazonaws.services.s3.model.PutObjectResult
1010

1111
// can't call it Universal -- that's taken by the packager
1212
object ScalaDist {
13-
val upload=TaskKey[Seq[PutObjectResult]]("s3-upload","Uploads files to an S3 bucket.")
13+
val s3Upload = TaskKey[Seq[PutObjectResult]]("s3Upload","Uploads files to an S3 bucket.")
14+
val ghUpload = TaskKey[Seq[Unit]]("ghUpload","Uploads files to GitHub Releases.")
1415

1516
def createMappingsWith(deps: Seq[(sbt.librarymanagement.ConfigRef, ModuleID, Artifact, File)],
1617
distMappingGen: (ModuleID, Artifact, File) => Seq[(File, String)]): Seq[(File, String)] =
@@ -21,30 +22,30 @@ object ScalaDist {
2122
case _ => Seq()
2223
}
2324

24-
// used to make s3-upload upload the file produced by fileTask to the path scala/$version/${file.name}
25+
// used to make s3Upload upload the file produced by fileTask to the path scala/$version/${file.name}
2526
private def uploadMapping(fileTask: TaskKey[File]) = Def.task {
2627
val file = fileTask.value
2728
file -> s"scala/${version.value}/${file.getName}"
2829
}
2930

30-
// make it so that s3-upload will upload the msi when we're running on windows, and everything else when we're on linux
31-
// s3-upload thus depends on the package tasks listed below
31+
// make it so that s3Upload will upload the msi when we're running on windows, and everything else when we're on linux
32+
// s3Upload thus depends on the package tasks listed below
3233
def platformSettings =
3334
if (sys.props("os.name").toLowerCase(java.util.Locale.US) contains "windows")
34-
Wix.settings :+ (upload / mappings += uploadMapping(Windows / packageBin).value)
35+
Wix.settings :+ (s3Upload / mappings += uploadMapping(Windows / packageBin).value)
3536
else Unix.settings ++ Seq(
36-
upload / mappings += uploadMapping(Universal / packageBin).value,
37-
upload / mappings += uploadMapping(Universal / packageZipTarball).value,
38-
upload / mappings += uploadMapping(UniversalDocs / packageBin).value,
39-
upload / mappings += uploadMapping(UniversalDocs / packageZipTarball).value,
40-
upload / mappings += uploadMapping(UniversalDocs / packageXzTarball).value,
41-
upload / mappings += uploadMapping(Rpm / packageBin).value,
37+
s3Upload / mappings += uploadMapping(Universal / packageBin).value,
38+
s3Upload / mappings += uploadMapping(Universal / packageZipTarball).value,
39+
s3Upload / mappings += uploadMapping(UniversalDocs / packageBin).value,
40+
s3Upload / mappings += uploadMapping(UniversalDocs / packageZipTarball).value,
41+
s3Upload / mappings += uploadMapping(UniversalDocs / packageXzTarball).value,
42+
s3Upload / mappings += uploadMapping(Rpm / packageBin).value,
4243
// Debian needs special handling because the value sbt-native-packager
4344
// gives us for `Debian / packageBin` (coming from the archiveFilename
4445
// method) includes the debian version and arch information,
4546
// which we historically have not included. I don't see a way to
4647
// override the filename on disk, so we re-map at upload time
47-
upload / mappings += Def.task {
48+
s3Upload / mappings += Def.task {
4849
(Debian / packageBin).value ->
4950
s"scala/${version.value}/${(Debian / name).value}-${version.value}.deb"
5051
}.value
@@ -65,13 +66,6 @@ object ScalaDist {
6566
// create lib directory by resolving scala-dist's dependencies
6667
// to populate the rest of the distribution, explode scala-dist artifact itself
6768
Universal / mappings ++= createMappingsWith(update.value.toSeq, universalMappings),
68-
69-
// work around regression in sbt-native-packager 1.0.5 where
70-
// these tasks invoke `tar` without any flags at all. the issue
71-
// was fixed in 1.1.0, so this could be revisited when we upgrade
72-
UniversalDocs / packageZipTarball / universalArchiveOptions := Seq("--force-local", "-pcvf"),
73-
UniversalDocs / packageXzTarball / universalArchiveOptions := Seq("--force-local", "-pcvf")
74-
7569
)
7670

7771
// private lazy val onWindows = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.10.6
1+
sbt.version=1.10.11

project/plugins.sbt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.8.1")
77

88
libraryDependencies += "com.amazonaws" % "aws-java-sdk-s3" % "1.12.5"
99

10-
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.1")
10+
libraryDependencies += "com.softwaremill.sttp.client3" %% "core" % "3.11.0"
11+
libraryDependencies ++= Seq(
12+
"io.circe" %% "circe-core",
13+
"io.circe" %% "circe-generic",
14+
"io.circe" %% "circe-parser"
15+
).map(_ % "0.14.13")
1116

17+
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.1")

scripts/common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function travis_fold_end() {
1414
function postCommitStatus() {
1515
if [[ "$scala_sha" != "" ]]; then
1616
local jsonTemplate='{ "state": "%s", "target_url": "%s", "description": "%s", "context": "%s"}'
17-
local json=$(printf "$jsonTemplate" "$1" "https://travis-ci.com/scala/scala-dist/builds/$TRAVIS_BUILD_ID" "$1" "travis/scala-dist/$version/$mode")
17+
local json=$(printf "$jsonTemplate" "$1" "https://app.travis-ci.com/github/scala/scala-dist/builds/$TRAVIS_BUILD_ID" "$1" "travis/scala-dist/$version/$mode")
1818
[[ -z "$GITHUB_OAUTH_TOKEN" ]] && (echo "Missing environment variable GITHUB_OAUTH_TOKEN!"; exit 1)
1919
TMPFILE=$(mktemp -t curl.XXXXXXXXXX)
2020

scripts/jobs/release/package/generic

Lines changed: 0 additions & 32 deletions
This file was deleted.

scripts/jobs/release/package/unix

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/jobs/release/package/windows

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)