Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sbt-github-actions #299

Merged
merged 3 commits into from
Apr 10, 2021
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
125 changes: 125 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Continuous Integration

on:
pull_request:
branches: ['*']
push:
branches: ['*']
tags: [v*]

env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.13, 2.13.5]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v10
with:
java-version: ${{ matrix.java }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Check that workflows are up to date
run: sbt ++${{ matrix.scala }} githubWorkflowCheck

- run: sbt ++${{ matrix.scala }} test mimaReportBinaryIssues

- name: Compress target directories
run: tar cf targets.tar modules/sttp/target modules/http4s/target modules/scalacache/target modules/doobie/target modules/log4cats/target modules/akka-http/target microsite/target modules/circe/target modules/http4s-client/target modules/redis/target modules/core/target target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
path: targets.tar

publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v'))
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.13]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v10
with:
java-version: ${{ matrix.java }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.12.13)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.12.13-${{ matrix.java }}

- name: Inflate target directories (2.12.13)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.5)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.13.5-${{ matrix.java }}

- name: Inflate target directories (2.13.5)
run: |
tar xf targets.tar
rm targets.tar

- uses: olafurpg/setup-gpg@v3

- run: sbt ++${{ matrix.scala }} ci-release
59 changes: 59 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Clean

on: push

jobs:
delete-artifacts:
name: Delete Artifacts
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Delete artifacts
run: |
# Customize those three lines with your repository and credentials:
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}

# A shortcut to call GitHub API.
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }

# A temporary file which receives HTTP response headers.
TMPFILE=/tmp/tmp.$$

# An associative array, key: artifact name, value: number of artifacts of that name.
declare -A ARTCOUNT

# Process all artifacts on this repository, loop on returned "pages".
URL=$REPO/actions/artifacts
while [[ -n "$URL" ]]; do

# Get current page, get response headers in a temporary file.
JSON=$(ghapi --dump-header $TMPFILE "$URL")

# Get URL of next page. Will be empty if we are at the last page.
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
rm -f $TMPFILE

# Number of artifacts on this page:
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))

# Loop on all artifacts on this page.
for ((i=0; $i < $COUNT; i++)); do

# Get name of artifact and count instances of this name.
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))

id=$(jq <<<$JSON -r ".artifacts[$i].id?")
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
ghapi -X DELETE $REPO/actions/artifacts/$id
done
done
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ target/
**/secret.conf
**/.DS_Store
.vscode/

metals.sbt
therealcisse marked this conversation as resolved.
Show resolved Hide resolved
project/metals.sbt
project/project/

.bsp
3 changes: 2 additions & 1 deletion .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ pull_request_rules:
- name: automatically merge Scala Steward PRs on CI success
conditions:
- author=scala-steward
- status-success=Travis CI - Pull Request
- status-success=Build and Test (ubuntu-latest, 2.12.13, [email protected])
- status-success=Build and Test (ubuntu-latest, 2.13.5, [email protected])
- body~=labels:.*semver-patch.*
actions:
merge:
Expand Down
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

35 changes: 29 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val Scala_212 = "2.12.11"
val Scala_213 = "2.13.2"
val Scala_212 = "2.12.13"
val Scala_213 = "2.13.5"

val catsEffectVersion = "2.4.1"
val catsTaglessVersion = "0.12"
Expand All @@ -14,6 +14,32 @@ val http4sVersion = "0.21.21"
val circeVersion = "0.13.0"
val sttpVersion = "1.7.2"

val GraalVM11 = "[email protected]"

ThisBuild / scalaVersion := Scala_212
ThisBuild / crossScalaVersions := Seq(Scala_212, Scala_213)
ThisBuild / githubWorkflowJavaVersions := Seq(GraalVM11)
ThisBuild / githubWorkflowBuild := Seq(
WorkflowStep.Sbt(List("test", "mimaReportBinaryIssues"))
)

//sbt-ci-release settings
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches := Seq(
RefPredicate.StartsWith(Ref.Branch("master")),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually thought of having both master and main here, but it's alright :)

RefPredicate.StartsWith(Ref.Tag("v"))
)
ThisBuild / githubWorkflowPublishPreamble := Seq(
WorkflowStep.Use(UseRef.Public("olafurpg", "setup-gpg", "v3"))
)
ThisBuild / githubWorkflowPublish := Seq(WorkflowStep.Sbt(List("ci-release")))
ThisBuild / githubWorkflowEnv ++= List(
"PGP_PASSPHRASE",
"PGP_SECRET",
"SONATYPE_PASSWORD",
"SONATYPE_USERNAME"
).map(envKey => envKey -> s"$${{ secrets.$envKey }}").toMap

inThisBuild(
List(
organization := "com.kubukoz",
Expand All @@ -35,7 +61,6 @@ val compilerPlugins = List(
)

val commonSettings = Seq(
scalaVersion := Scala_212,
scalacOptions --= Seq("-Xfatal-warnings"),
name := "sup",
updateOptions := updateOptions.value.withGigahorse(false), //may fix publishing bug
Expand All @@ -49,10 +74,8 @@ val commonSettings = Seq(
mimaPreviousArtifacts := Set(organization.value %% name.value % "0.7.0")
)

val crossBuiltCommonSettings = commonSettings ++ Seq(crossScalaVersions := Seq(Scala_212, Scala_213))

def module(moduleName: String): Project =
Project(moduleName, file("modules") / moduleName).settings(crossBuiltCommonSettings).settings(name += s"-$moduleName")
Project(moduleName, file("modules") / moduleName).settings(commonSettings).settings(name += s"-$moduleName")

val core = module("core").settings(
libraryDependencies ++= Seq(
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ addSbtPlugin("com.47deg" % "sbt-microsites" % "1.3.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.8.1")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.16")
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.10.1")