Skip to content

Commit

Permalink
Merge pull request #134 from eed3si9n/wip/publishing
Browse files Browse the repository at this point in the history
Set up automated publishing
  • Loading branch information
eed3si9n authored Jan 12, 2023
2 parents caad082 + e2d94f2 commit 330e561
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 30 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
branches: ['**']
push:
branches: ['**']
tags: [v*]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -74,11 +75,11 @@ jobs:
publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main')
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.15]
scala: [2.12.17]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -122,3 +123,10 @@ jobs:
run: |
tar xf targets.tar
rm targets.tar
- env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
run: sbt ++${{ matrix.scala }} ci-release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ An example of how this "source of truth" pattern differs between the two plugins
Add the following to your `plugins.sbt`:

```sbt
addSbtPlugin("com.codecommit" % "sbt-github-actions" % <latest>)
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % <latest>)
```

To use the generative functionality, run `sbt githubWorkflowGenerate` and *commit the results*. If your sbt build is ever changed such that the generated workflow is no longer in sync, the workflow run in GitHub Actions will begin failing and you will need to re-run this task (and commit the results).
Expand Down
60 changes: 47 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,37 @@

name := "sbt-github-actions"

ThisBuild / baseVersion := "0.14"

ThisBuild / organization := "com.codecommit"
ThisBuild / publishGithubUser := "djspiewak"
ThisBuild / publishFullName := "Daniel Spiewak"
ThisBuild / homepage := Some(url("https://github.com/djspiewak/sbt-github-actions"))
ThisBuild / startYear := Some(2020)
ThisBuild / endYear := Some(2021)

ThisBuild / organization := "com.github.sbt"
ThisBuild / crossScalaVersions := Seq("2.12.15")

// Add windows-latest when https://github.com/sbt/sbt/issues/7082 is resolved
ThisBuild / githubWorkflowOSes := Seq("ubuntu-latest", "macos-latest")
ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("test", "scripted")))
ThisBuild / githubWorkflowJavaVersions += JavaSpec.graalvm("20.3.1", "11")

// dummy publication just to test that setup works
ThisBuild / githubWorkflowPublishTargetBranches :=
Seq(RefPredicate.Equals(Ref.Branch("main")))

ThisBuild / githubWorkflowPublish := Seq()
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches :=
Seq(
RefPredicate.StartsWith(Ref.Tag("v")),
RefPredicate.Equals(Ref.Branch("main"))
)
ThisBuild / githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
)
)
ThisBuild / version := {
val orig = (ThisBuild / version).value
if (orig.endsWith("-SNAPSHOT")) orig.split("""\+""").head + "-SNAPSHOT"
else orig
}

sbtPlugin := true
pluginCrossBuild / sbtVersion := "1.5.5"
Expand All @@ -51,3 +61,27 @@ enablePlugins(SbtPlugin)

scriptedLaunchOpts ++= Seq("-Dplugin.version=" + version.value)
scriptedBufferLog := true

ThisBuild / homepage := Some(url("https://github.com/sbt/sbt-github-actions"))
ThisBuild / startYear := Some(2020)
ThisBuild / dynverSonatypeSnapshots := true
ThisBuild / developers := List(
Developer(
id = "djspiewak",
name = "Daniel Spiewak",
email = "@djspiewak",
url = url("https://github.com/djspiewak")
),
)
ThisBuild / description := "An sbt plugin which makes it easier to build with GitHub Actions"
ThisBuild / licenses := List("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0"))
ThisBuild / pomIncludeRepository := { _ =>
false
}
ThisBuild / publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
ThisBuild / publishMavenStyle := true
Global / excludeLintKeys ++= Set(pomIncludeRepository, publishMavenStyle)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.8.0
sbt.version=1.8.2
9 changes: 1 addition & 8 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@
// necessary hack to avoid an infinite project loading recursion.
val sbtGithubActionsSources = ProjectRef(file("project"), "sbtGithubActionsSources")

// Convoluted hack to force linking between the binary distribution of
// `sbt-spiewak-sonatype` with the `GitHubActionsPlugin` built from the sources
// of this repository.
val root = (project in file("."))
.dependsOn(sbtGithubActionsSources)
.settings(
addSbtPlugin("com.codecommit" % "sbt-spiewak-sonatype" % "0.22.1" exclude("com.codecommit", "sbt-github-actions"))
)
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-actions" % x)
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-github-actions" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
2 changes: 1 addition & 1 deletion src/sbt-test/sbtghactions/no-clean/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-actions" % x)
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-github-actions" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-actions" % x)
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-github-actions" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-actions" % x)
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-github-actions" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-actions" % x)
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-github-actions" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}

0 comments on commit 330e561

Please sign in to comment.