Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 1.8
distribution: temurin
java-version: 17
- uses: sbt/setup-sbt@v1
- name: Run tests
shell: bash
run: sbt test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.bloop/
.bsp/
.DS_Store
.idea/
target/
local_env.sh
*.iml

.env
2 changes: 2 additions & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
73 changes: 50 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ Experimental plugin for sbt to create Azure Function artefacts (function.json) n

in your `project/plugins.sbt` add sbt-assembly and sbt-azure-functions:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1")
addSbtPlugin("nl.codestar" % "sbt-azure-functions" % "<latest version>")

in your `build.sbt` provide values for the assembly and azure-functions plugins:

lazy val root = (project in file("."))
.settings(
...
// replace these values with appropriate values for your Azure Function
azfunFunctionAppName := "ScalaFunction",
azfunLocation := "azure-location", // e.g. "westeurope", "eastus", etc.
azfunResourceGroup := "your-resource-group",
azfunStorageAccount := "yourstorageaccount"

// optional: override the zip and/or jar name (defaults are AzureFunction.zip and AzureFunction.jar)
azfunZipName := "myFunctions.zip",
azfunJarName := "ScalaFunctions.jar",

// you need this dependency to be able to use the annotations
libraryDependencies ++= Seq(
"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1"
"com.microsoft.azure.functions" % "azure-functions-java-library" % "3.1.0"
)

)
Expand All @@ -52,13 +57,12 @@ in your `build.sbt` provide values for the assembly and azure-functions plugins:
and logged in to the correct Azure Subscription.
You will also have to install the app-insights extension to the CLI, by running `az extension add -n application-insights`

You can provide the following settings to determine the destination:
You must provide the following settings to determine the destination:
* `azfunResourceGroup`
* `azfunStorageAccount`


## TODO:
1. add task to upload to Azure
1. add support for App Insights workspaces
1. add tests against multiple Java versions (java 8 and Java 11)

Expand All @@ -70,37 +74,60 @@ released for different scala versions and different sbt versions. I have not (ye
what Scala version is used for each sbt release, except for https://github.com/sbt/sbt/issues/5032,
so I am also keeping track here:

| SBT release(s)| Scala version | Remarks |
|---------------|-------------------|--------------------------------------------------|
| 0.x | 2.10.x |
| 1.x | 2.12.x |
| 2.x | 2.13.x or 3.0.x |
| 3.x | 3.0.x or 3.1.x |
| SBT release(s) | Scala version | Remarks |
|-----------------|-----------------|---------|
| 0.x | 2.10.x | |
| 1.x | 2.12.x | |
| 2.x | 2.13.x or 3.0.x | |
| 3.x | 3.0.x or 3.1.x | |

For now, I will focus only on sbt 1.x and Scala 2.12.x

### Microsoft Azure Dependencies
This plugin uses artifacts from Microsoft:
* "com.microsoft.azure" % "azure-tools-common" % "0.10.0"
* "com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1" % "test"
* `"com.microsoft.azure" % "azure-tools-common" % "0.10.0"`
* `"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1" % "test"`

For now I will use these versions

### Testing
#### Unit tests
* `sbt clean test`
#### Scripted tests
* `sbt publishLocal`
* `sbt scripted`

## Releasing (for plugin maintainers)
To release a new version:
* Get a [bintray](https://bintray.com) account and make sure you're a member of the [`code-star`](https://bintray.com/code-star) organization.
* Set your credentials - you can use `sbt bintrayChangeCredentials`, but when run from the interactive sbt prompt
you will not see the requests for username and password. So blindly first type your username, press enter, then
paste your API key and press enter again.

(found a workaround that shows the prompt again: add to build.sbt: `ThisBuild / useSuperShell := false`)
* reload to make new settings known to sbt
* Run `sbt release`
Note: to successfully run the `deploy` scripted test, you need to have the Azure CLI installed and logged in to Azure with proper access
to a subscription that has a resource group and storage account as specified in the `sbt-test/sbt-azure-functions/deploy/build.sbt` file.

Update Feb 2021: we started moving away from Bintray. We will start using sbt-ci-release and release to Maven Central.
## Releasing (for plugin maintainers)
To release a new version, make sure you have:
* proper access to the `nl.codestar` namespace on Sonatype.
* GnuPG (`gpg`) installed and a signing key configured.
* We use `sbt-pgp` plugin to sign, which relies on the `gpg` command line tool
* create a `.env` file in the project root with the following variables:
```
PGP_KEYID=<id of the signing key>
PGP_PASSPHRASE=<your PGP passphrase>
SONATYPE_USER=<user id or token id>
SONATYPE_PASSWORD=<password or token>

```

Note: The `.env` file needs to be kept out of the git repository (it is `.gitignore`d).

See [Using Sonatype](https://www.scala-sbt.org/1.x/docs/Using-Sonatype.html) in the SBT documentation.

### SNAPSHOT versions
Steps to release SNAPSHOT version:
1. Make sure HEAD is not directly pointing to a tag
2. `sbt publishSigned`
3. make note of the SNAPSHOT version that is used (Sonatype does not allow searching/browsing for SNAPSHOT versions)

### Production versions
Steps to release production version:
1. Tag the current commit with the new version number, e.g. `git tag v0.5.0`
2. `sbt publishSigned`
3. `sbt sonaUpload`
4. Go to https://central.sonatype.com/publishing/deployments and publish the deployment.
* or run `sbt sonaRelease` to publish the deployment automatically
86 changes: 72 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,34 +1,83 @@
lazy val commonSettings = Seq(
organization := "nl.codestar",
homepage := Some(url("https://github.com/code-star/sbt-azure-functions-plugin")),
// version is set by sbt-dynver plugin (included through sbt-ci-assembly)
// version is set by sbt-dynver plugin (included through sbt-ci-release)
description := "SBT Plugin to generate function.json artefacts needed to publish code as an Azure Function",
organization := "nl.codestar",
organizationName := "Codestar powered by Sopra Steria",
organizationHomepage := Some(url("https://codestar.nl")),
homepage := Some(url("https://codestar.nl/sbt-azure-functions-plugin")),
licenses += ("MIT", url("https://opensource.org/licenses/MIT")),
developers := List(
Developer(
"jeanmarc",
"Jean-Marc van Leerdam",
"[email protected]",
url("https://github.com/jeanmarc")
"[email protected]",
url("https://soprasteria.com")
)
),
scmInfo := Some(
ScmInfo(
url("https://github.com/code-star/sbt-azure-functions-plugin"),"scm:[email protected]:code-star/sbt-azure-functions-plugin.git")
),
credentials ++= Seq(
Credentials(
"GnuPG Key ID",
"gpg",
System.getenv("PGP_KEYID"), // key identifier
"ignored" // this field is ignored; passwords are supplied by pinentry
),
Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
System.getenv("SONATYPE_USER"),
System.getenv("SONATYPE_PASSWORD") // Use environment variable for security
),
Credentials(
"Sonatype Nexus Repository Manager",
"central.sonatype.com",
System.getenv("SONATYPE_USER"),
System.getenv("SONATYPE_PASSWORD") // Use environment variable for security
),
Credentials(
"central-snapshots",
"central.sonatype.com",
System.getenv("SONATYPE_USER"),
System.getenv("SONATYPE_PASSWORD") // Use environment variable for security
)
)

)

lazy val root = (project in file("."))
lazy val root = project.in(file("."))
.aggregate(plugin)
.settings(
name := "sbt-azure-functions-plugin",
commonSettings,
// the root project should not produce any artifacts
publishArtifact := false,
publish := {}
publish := {},
sonaDeploymentName := {
val o = organization.value
val n = "sbt-azure-functions"
val v = version.value
val dt = java.time.LocalDateTime.now.format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))
s"$o:$n:$v:$dt"
},
)

lazy val plugin = (project in file("plugin"))
lazy val plugin = project.in(file("plugin"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-azure-functions",
commonSettings,

scalaVersion := "2.12.18",
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" => "1.11.4" // set minimum version
}
},
scalacOptions ++= Seq(
"-encoding",
"UTF8",
Expand All @@ -41,22 +90,31 @@ lazy val plugin = (project in file("plugin"))
"-Ywarn-adapted-args"
),
libraryDependencies ++= Seq(
"com.fasterxml.jackson.core" % "jackson-databind" % "2.12.0",
"com.microsoft.azure" % "azure-tools-common" % "0.10.0",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1" % "test",
"org.scalatest" %% "scalatest" % "3.2.2" % "test",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.19.2",
"com.microsoft.azure" % "azure-tools-common" % "0.14.0",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.5",
"com.microsoft.azure.functions" % "azure-functions-java-library" % "3.1.0" % "test",
"org.scalatest" %% "scalatest" % "3.2.19" % "test",
"org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
),
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10"),
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1"),
scriptedLaunchOpts := {
scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
},
scriptedBufferLog := false,
logBuffered in Test := false,
publishArtifact in Test := false
Test / logBuffered := false,
Test / publishArtifact := false
)

// workaround for interactive sessions that do not echo the user input (https://github.com/sbt/sbt-bintray/issues/177)
ThisBuild / useSuperShell := false

ThisBuild / pomIncludeRepository := { _ => false }
ThisBuild / publishMavenStyle := true

ThisBuild / publishTo := {
val centralSnapshots = "https://central.sonatype.com/repository/maven-snapshots/"
if (isSnapshot.value) Some("central-snapshots" at centralSnapshots)
else localStaging.value
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object CreateZipFileTask {

val log = sbt.Keys.streams.value.log

val tgtFolder = (target in Compile).value
val tgtFolder = (Compile / target).value

log.info("Running azfunCreateZipFile task...")
log.info(
Expand All @@ -28,7 +28,7 @@ object CreateZipFileTask {

val src = azfunTargetFolder.value
val tgt = tgtFolder / ensureExtension(azfunZipName.value, "zip")
IO.zip(allSubpaths(src), tgt)
IO.zip(allSubpaths(src), tgt, None)
tgt
}
)
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/main/scala/sbtazurefunctions/DefaultSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ object DefaultSettings {
def settings: Seq[Setting[_]] =
Seq(
azfunAppInsightsName := azfunFunctionAppName.value,
azfunHostJsonFile := (baseDirectory in Compile).value / "host.json",
azfunHostJsonFile := (Compile / baseDirectory).value / "host.json",
azfunJarName := "AzureFunction.jar",
azfunLocalSettingsFile := (baseDirectory in Compile).value / "local.settings.json",
azfunLocalSettingsFile := (Compile / baseDirectory).value / "local.settings.json",
azfunSKU := "Standard_LRS",
azfunTargetFolder := (target in Compile).value / stripExtension(azfunZipName.value),
azfunTargetFolder := (Compile / target).value / stripExtension(azfunZipName.value),
azfunZipName := "AzureFunction.zip"
)

Expand Down
10 changes: 5 additions & 5 deletions plugin/src/sbt-test/sbt-azure-functions/deploy/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import sbt.Keys.libraryDependencies
lazy val root = (project in file("."))
.settings(
version := "0.1",
scalaVersion := "2.12.7",
scalaVersion := "2.12.18",
libraryDependencies ++= Seq(
"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1"
"com.microsoft.azure.functions" % "azure-functions-java-library" % "3.1.0"
),
assemblyJarName in assembly := "ScalaFunctions.jar",
assembly / assemblyJarName := "ScalaFunctions.jar",
azfunFunctionAppName := "rd-scala-functions",
azfunLocation := "westeurope",
azfunResourceGroup := "rg-rd-scala-functions",
azfunStorageAccount := "a77a749630954151919e"
azfunResourceGroup := "rg-function-showcase",
azfunStorageAccount := "rgfunctionshowcasebaa9"
)
2 changes: 1 addition & 1 deletion plugin/src/sbt-test/sbt-azure-functions/deploy/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
"version": "[2.*, 3.0.0)"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1")

sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("nl.codestar" % "sbt-azure-functions" % x)
Expand Down
10 changes: 7 additions & 3 deletions plugin/src/sbt-test/sbt-azure-functions/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import sbt.Keys.libraryDependencies
lazy val root = (project in file("."))
.settings(
version := "0.1",
scalaVersion := "2.12.7",
scalaVersion := "2.12.18",
libraryDependencies ++= Seq(
"com.microsoft.azure.functions" % "azure-functions-java-library" % "1.3.1"
"com.microsoft.azure.functions" % "azure-functions-java-library" % "3.1.0"
),
assemblyJarName in assembly := "ScalaFunctions.jar"
assembly / assemblyJarName := "ScalaFunctions.jar",
azfunFunctionAppName := "rd-scala-functions",
azfunLocation := "westeurope",
azfunResourceGroup := "rg-function-showcase",
azfunStorageAccount := "rgfunctionshowcasebaa9"
)
2 changes: 1 addition & 1 deletion plugin/src/sbt-test/sbt-azure-functions/simple/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
"version": "[2.*, 3.0.0)"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1")

sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("nl.codestar" % "sbt-azure-functions" % x)
Expand Down
Loading