Skip to content

Commit 2375791

Browse files
committed
Use sbt-github-actions
1 parent 9b3310f commit 2375791

File tree

4 files changed

+181
-39
lines changed

4 files changed

+181
-39
lines changed

.github/workflows/ci.yml

Lines changed: 93 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,117 @@
1-
name: CI
1+
# This file was automatically generated by sbt-github-actions using the
2+
# githubWorkflowGenerate task. You should add and commit this file to
3+
# your git repository. It goes without saying that you shouldn't edit
4+
# this file by hand! Instead, if you wish to make changes, you should
5+
# change your sbt build configuration to revise the workflow description
6+
# to meet your needs, then regenerate this file.
27

3-
env:
4-
JAVA_OPTS: "-Dfile.encoding=UTF-8 -Xms1024M -Xmx3072M -Xss4M"
8+
name: Continuous Integration
59

610
on:
7-
push:
8-
branches: '**'
9-
tags: [ "v[0-9]+*" ]
1011
pull_request:
11-
# avoid duplicate checks (push & PR) further in the review process
12-
types: [opened]
12+
branches: [ '**' ]
13+
push:
14+
branches: [ '**' ]
15+
tags: [ v* ]
16+
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1319

1420
jobs:
15-
test:
16-
name: Run tests
17-
runs-on: ubuntu-22.04 # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
21+
build:
22+
name: Build and Test
1823
strategy:
19-
fail-fast: false
2024
matrix:
25+
os: [ ubuntu-latest ]
2126
scala: [ 2.13.16 ]
22-
java-version: [ 17, 21, 25 ]
23-
command: [ udash-jvm/test, udash-js/test, guide-selenium/test ]
27+
java: [ temurin@17, temurin@21, temurin@25 ]
28+
runs-on: ${{ matrix.os }}
2429
steps:
25-
- uses: actions/checkout@v4
26-
- uses: actions/setup-java@v4
30+
- name: Checkout current branch (full)
31+
uses: actions/checkout@v5
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Setup Java (temurin@17)
36+
if: matrix.java == 'temurin@17'
37+
uses: actions/setup-java@v5
2738
with:
2839
distribution: temurin
29-
java-version: ${{ matrix.java-version }}
40+
java-version: 17
3041
cache: sbt
31-
- uses: actions/setup-node@v4
42+
43+
- name: Setup Java (temurin@21)
44+
if: matrix.java == 'temurin@21'
45+
uses: actions/setup-java@v5
3246
with:
33-
cache: npm
34-
- name: Install npm dependencies
35-
run: npm install
36-
- name: Run tests
37-
run: sbt ++${{ matrix.scala }} ${{ matrix.command }}
47+
distribution: temurin
48+
java-version: 21
49+
cache: sbt
50+
51+
- name: Setup Java (temurin@25)
52+
if: matrix.java == 'temurin@25'
53+
uses: actions/setup-java@v5
54+
with:
55+
distribution: temurin
56+
java-version: 25
57+
cache: sbt
58+
59+
- name: Setup sbt
60+
uses: sbt/setup-sbt@v1
61+
62+
- name: Setup Node.js
63+
uses: actions/setup-node@v4
64+
65+
- name: Check that workflows are up to date
66+
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck
67+
68+
- name: Build project
69+
run: sbt '++ ${{ matrix.scala }}' test
3870

3971
publish:
40-
name: Publish to Sonatype
41-
# only run on tag push
42-
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v'))
43-
needs: [ test ]
44-
runs-on: ubuntu-22.04
72+
name: Publish Artifacts
73+
needs: [ build ]
74+
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
75+
strategy:
76+
matrix:
77+
os: [ ubuntu-latest ]
78+
scala: [ 2.13.16 ]
79+
java: [ temurin@17 ]
80+
runs-on: ${{ matrix.os }}
4581
steps:
46-
- uses: actions/checkout@v4
47-
- name: Set up JDK
48-
uses: actions/setup-java@v4
82+
- name: Checkout current branch (full)
83+
uses: actions/checkout@v5
84+
with:
85+
fetch-depth: 0
86+
87+
- name: Setup Java (temurin@17)
88+
if: matrix.java == 'temurin@17'
89+
uses: actions/setup-java@v5
4990
with:
5091
distribution: temurin
5192
java-version: 17
5293
cache: sbt
53-
- name: Get version
54-
id: get_tag_name
55-
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
56-
- name: Publish artifacts
57-
env:
94+
95+
- name: Setup Java (temurin@21)
96+
if: matrix.java == 'temurin@21'
97+
uses: actions/setup-java@v5
98+
with:
99+
distribution: temurin
100+
java-version: 21
101+
cache: sbt
102+
103+
- name: Setup Java (temurin@25)
104+
if: matrix.java == 'temurin@25'
105+
uses: actions/setup-java@v5
106+
with:
107+
distribution: temurin
108+
java-version: 25
109+
cache: sbt
110+
111+
- name: Setup sbt
112+
uses: sbt/setup-sbt@v1
113+
114+
- env:
58115
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
59116
PGP_SECRET: ${{ secrets.PGP_SECRET }}
60117
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}

.github/workflows/clean.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This file was automatically generated by sbt-github-actions using the
2+
# githubWorkflowGenerate task. You should add and commit this file to
3+
# your git repository. It goes without saying that you shouldn't edit
4+
# this file by hand! Instead, if you wish to make changes, you should
5+
# change your sbt build configuration to revise the workflow description
6+
# to meet your needs, then regenerate this file.
7+
8+
name: Clean
9+
10+
on: push
11+
12+
permissions:
13+
actions: write
14+
15+
jobs:
16+
delete-artifacts:
17+
name: Delete Artifacts
18+
runs-on: ubuntu-latest
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
steps:
22+
- name: Delete artifacts
23+
shell: bash {0}
24+
run: |
25+
# Customize those three lines with your repository and credentials:
26+
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}
27+
28+
# A shortcut to call GitHub API.
29+
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }
30+
31+
# A temporary file which receives HTTP response headers.
32+
TMPFILE=$(mktemp)
33+
34+
# An associative array, key: artifact name, value: number of artifacts of that name.
35+
declare -A ARTCOUNT
36+
37+
# Process all artifacts on this repository, loop on returned "pages".
38+
URL=$REPO/actions/artifacts
39+
while [[ -n "$URL" ]]; do
40+
41+
# Get current page, get response headers in a temporary file.
42+
JSON=$(ghapi --dump-header $TMPFILE "$URL")
43+
44+
# Get URL of next page. Will be empty if we are at the last page.
45+
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
46+
rm -f $TMPFILE
47+
48+
# Number of artifacts on this page:
49+
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))
50+
51+
# Loop on all artifacts on this page.
52+
for ((i=0; $i < $COUNT; i++)); do
53+
54+
# Get name of artifact and count instances of this name.
55+
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
56+
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))
57+
58+
id=$(jq <<<$JSON -r ".artifacts[$i].id?")
59+
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
60+
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
61+
ghapi -X DELETE $REPO/actions/artifacts/$id
62+
done
63+
done

build.sbt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ inThisBuild(Seq(
2222
developers := List(
2323
Developer("ddworak", "Dawid Dworak", "d.dworak@avsystem.com", url("https://github.com/ddworak")),
2424
),
25+
scalaVersion := Dependencies.versionOfScala,
26+
27+
28+
githubWorkflowTargetTags ++= Seq("v*"),
29+
30+
githubWorkflowArtifactUpload := false,
31+
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17"), JavaSpec.temurin("21"), JavaSpec.temurin("25")),
32+
githubWorkflowBuildPreamble += WorkflowStep.Use(
33+
UseRef.Public("actions", "setup-node", "v4"),
34+
name = Some("Setup Node.js"),
35+
),
36+
37+
githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v"))),
38+
39+
githubWorkflowPublish := Seq(WorkflowStep.Sbt(
40+
List("ci-release"),
41+
env = Map(
42+
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
43+
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
44+
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
45+
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
46+
)
47+
)),
2548
))
2649

2750
val forIdeaImport = System.getProperty("idea.managed", "false").toBoolean && System.getProperty("idea.runid") == null
@@ -34,8 +57,6 @@ val browserCapabilities: Capabilities = {
3457
}
3558

3659
val commonSettings = Seq(
37-
scalaVersion := Dependencies.versionOfScala,
38-
crossScalaVersions := Seq(Dependencies.versionOfScala),
3960
scalacOptions ++= Seq(
4061
"-feature",
4162
"-deprecation",

project/plugins.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ addSbtPlugin("org.jetbrains.scala" % "sbt-ide-settings" % "1.1.3")
1010
addSbtPlugin("com.github.sbt" % "sbt-less" % "2.0.1")
1111
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.11.4")
1212
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.11.2")
13-
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.8")
13+
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.8")
14+
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.28.0")

0 commit comments

Comments
 (0)