Skip to content

Commit a12675e

Browse files
authored
Merge pull request #1413 from UdashFramework/sbt-github-actions
Use sbt-github-actions
2 parents 9b3310f + 1b8c002 commit a12675e

File tree

4 files changed

+193
-36
lines changed

4 files changed

+193
-36
lines changed

.github/workflows/ci.yml

Lines changed: 96 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,123 @@
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 }}
19+
JAVA_OPTS: '-Dfile.encoding=UTF-8 -Xmx4G'
1320

1421
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
22+
build:
23+
name: Build and Test
1824
strategy:
1925
fail-fast: false
2026
matrix:
21-
scala: [ 2.13.16 ]
22-
java-version: [ 17, 21, 25 ]
23-
command: [ udash-jvm/test, udash-js/test, guide-selenium/test ]
27+
os: [ubuntu-latest]
28+
scala: [2.13.16]
29+
java: [temurin@17, temurin@21, temurin@25]
30+
command: [udash-jvm/test, udash-js/test, guide-selenium/test]
31+
runs-on: ${{ matrix.os }}
2432
steps:
25-
- uses: actions/checkout@v4
26-
- uses: actions/setup-java@v4
33+
- name: Checkout current branch (full)
34+
uses: actions/checkout@v5
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Setup Java (temurin@17)
39+
if: matrix.java == 'temurin@17'
40+
uses: actions/setup-java@v5
2741
with:
2842
distribution: temurin
29-
java-version: ${{ matrix.java-version }}
43+
java-version: 17
3044
cache: sbt
31-
- uses: actions/setup-node@v4
45+
46+
- name: Setup Java (temurin@21)
47+
if: matrix.java == 'temurin@21'
48+
uses: actions/setup-java@v5
3249
with:
33-
cache: npm
50+
distribution: temurin
51+
java-version: 21
52+
cache: sbt
53+
54+
- name: Setup Java (temurin@25)
55+
if: matrix.java == 'temurin@25'
56+
uses: actions/setup-java@v5
57+
with:
58+
distribution: temurin
59+
java-version: 25
60+
cache: sbt
61+
62+
- name: Setup sbt
63+
uses: sbt/setup-sbt@v1
64+
65+
- name: Setup Node.js
66+
uses: actions/setup-node@v4
67+
3468
- name: Install npm dependencies
3569
run: npm install
70+
71+
- name: Check that workflows are up to date
72+
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck
73+
3674
- name: Run tests
37-
run: sbt ++${{ matrix.scala }} ${{ matrix.command }}
75+
run: sbt '++ ${{ matrix.scala }}' '${{ matrix.command }}'
3876

3977
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
78+
name: Publish Artifacts
79+
needs: [build]
80+
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
81+
strategy:
82+
matrix:
83+
os: [ubuntu-latest]
84+
scala: [2.13.16]
85+
java: [temurin@17]
86+
runs-on: ${{ matrix.os }}
4587
steps:
46-
- uses: actions/checkout@v4
47-
- name: Set up JDK
48-
uses: actions/setup-java@v4
88+
- name: Checkout current branch (full)
89+
uses: actions/checkout@v5
90+
with:
91+
fetch-depth: 0
92+
93+
- name: Setup Java (temurin@17)
94+
if: matrix.java == 'temurin@17'
95+
uses: actions/setup-java@v5
4996
with:
5097
distribution: temurin
5198
java-version: 17
5299
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:
100+
101+
- name: Setup Java (temurin@21)
102+
if: matrix.java == 'temurin@21'
103+
uses: actions/setup-java@v5
104+
with:
105+
distribution: temurin
106+
java-version: 21
107+
cache: sbt
108+
109+
- name: Setup Java (temurin@25)
110+
if: matrix.java == 'temurin@25'
111+
uses: actions/setup-java@v5
112+
with:
113+
distribution: temurin
114+
java-version: 25
115+
cache: sbt
116+
117+
- name: Setup sbt
118+
uses: sbt/setup-sbt@v1
119+
120+
- env:
58121
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
59122
PGP_SECRET: ${{ secrets.PGP_SECRET }}
60123
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: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,38 @@ 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+
githubWorkflowTargetTags ++= Seq("v*"),
28+
githubWorkflowArtifactUpload := false,
29+
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17"), JavaSpec.temurin("21"), JavaSpec.temurin("25")),
30+
githubWorkflowBuildPreamble ++= Seq(
31+
WorkflowStep.Use(
32+
ref = UseRef.Public("actions", "setup-node", "v4"),
33+
name = Some("Setup Node.js"),
34+
),
35+
WorkflowStep.Run(
36+
commands = List("npm install"),
37+
name = Some("Install npm dependencies")
38+
)
39+
),
40+
githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v"))),
41+
githubWorkflowEnv += "JAVA_OPTS" -> "-Dfile.encoding=UTF-8 -Xmx4G",
42+
githubWorkflowBuildMatrixFailFast := Some(false),
43+
githubWorkflowBuildMatrixAdditions += "command" -> List("udash-jvm/test", "udash-js/test", "guide-selenium/test"),
44+
githubWorkflowBuild := Seq(WorkflowStep.Sbt(
45+
commands = List("${{ matrix.command }}"),
46+
name = Some("Run tests"),
47+
)),
48+
githubWorkflowPublish := Seq(WorkflowStep.Sbt(
49+
List("ci-release"),
50+
env = Map(
51+
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
52+
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
53+
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
54+
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
55+
)
56+
)),
2557
))
2658

2759
val forIdeaImport = System.getProperty("idea.managed", "false").toBoolean && System.getProperty("idea.runid") == null
@@ -34,8 +66,6 @@ val browserCapabilities: Capabilities = {
3466
}
3567

3668
val commonSettings = Seq(
37-
scalaVersion := Dependencies.versionOfScala,
38-
crossScalaVersions := Seq(Dependencies.versionOfScala),
3969
scalacOptions ++= Seq(
4070
"-feature",
4171
"-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)