Skip to content

Commit 1e31bde

Browse files
committed
github workflows setup
1 parent f4331de commit 1e31bde

File tree

4 files changed

+187
-2
lines changed

4 files changed

+187
-2
lines changed

.github/workflows/ci.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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: Continuous Integration
9+
10+
on:
11+
pull_request:
12+
branches: ['**']
13+
push:
14+
branches: ['**']
15+
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
19+
jobs:
20+
build:
21+
name: Build and Test
22+
strategy:
23+
matrix:
24+
os: [ubuntu-latest]
25+
scala: [2.12.18]
26+
java: [temurin@17]
27+
runs-on: ${{ matrix.os }}
28+
steps:
29+
- name: Checkout current branch (full)
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Setup Java (temurin@17)
35+
if: matrix.java == 'temurin@17'
36+
uses: actions/setup-java@v4
37+
with:
38+
distribution: temurin
39+
java-version: 17
40+
cache: sbt
41+
42+
- name: Setup sbt
43+
uses: sbt/setup-sbt@v1
44+
45+
- name: Check that workflows are up to date
46+
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck
47+
48+
- name: Build project
49+
run: sbt '++ ${{ matrix.scala }}' test
50+
51+
- name: Compress target directories
52+
run: tar cf targets.tar target sbt-protofetch/target project/target
53+
54+
- name: Upload target directories
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
58+
path: targets.tar
59+
60+
publish:
61+
name: Publish Artifacts
62+
needs: [build]
63+
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master')
64+
strategy:
65+
matrix:
66+
os: [ubuntu-latest]
67+
scala: [2.12.18]
68+
java: [temurin@17]
69+
runs-on: ${{ matrix.os }}
70+
steps:
71+
- name: Checkout current branch (full)
72+
uses: actions/checkout@v4
73+
with:
74+
fetch-depth: 0
75+
76+
- name: Setup Java (temurin@17)
77+
if: matrix.java == 'temurin@17'
78+
uses: actions/setup-java@v4
79+
with:
80+
distribution: temurin
81+
java-version: 17
82+
cache: sbt
83+
84+
- name: Setup sbt
85+
uses: sbt/setup-sbt@v1
86+
87+
- name: Download target directories (2.12.18)
88+
uses: actions/download-artifact@v4
89+
with:
90+
name: target-${{ matrix.os }}-2.12.18-${{ matrix.java }}
91+
92+
- name: Inflate target directories (2.12.18)
93+
run: |
94+
tar xf targets.tar
95+
rm targets.tar
96+
97+
- name: Publish project
98+
env:
99+
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
100+
PGP_SECRET: ${{ secrets.PGP_SECRET }}
101+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
102+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
103+
run: sbt ci-release

.github/workflows/clean.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
jobs:
13+
delete-artifacts:
14+
name: Delete Artifacts
15+
runs-on: ubuntu-latest
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
steps:
19+
- name: Delete artifacts
20+
shell: bash {0}
21+
run: |
22+
# Customize those three lines with your repository and credentials:
23+
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}
24+
25+
# A shortcut to call GitHub API.
26+
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }
27+
28+
# A temporary file which receives HTTP response headers.
29+
TMPFILE=$(mktemp)
30+
31+
# An associative array, key: artifact name, value: number of artifacts of that name.
32+
declare -A ARTCOUNT
33+
34+
# Process all artifacts on this repository, loop on returned "pages".
35+
URL=$REPO/actions/artifacts
36+
while [[ -n "$URL" ]]; do
37+
38+
# Get current page, get response headers in a temporary file.
39+
JSON=$(ghapi --dump-header $TMPFILE "$URL")
40+
41+
# Get URL of next page. Will be empty if we are at the last page.
42+
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
43+
rm -f $TMPFILE
44+
45+
# Number of artifacts on this page:
46+
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))
47+
48+
# Loop on all artifacts on this page.
49+
for ((i=0; $i < $COUNT; i++)); do
50+
51+
# Get name of artifact and count instances of this name.
52+
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
53+
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))
54+
55+
id=$(jq <<<$JSON -r ".artifacts[$i].id?")
56+
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
57+
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
58+
ghapi -X DELETE $REPO/actions/artifacts/$id
59+
done
60+
done

build.sbt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ lazy val `sbt-protofetch` = (project in file("sbt-protofetch"))
3030
scriptedLaunchOpts ++= Seq(
3131
"-Xmx1024M",
3232
"-Dsbt.protofetch.version=" + version.value
33+
),
34+
ThisBuild / githubWorkflowJavaVersions := Seq(
35+
JavaSpec.temurin("17")
36+
),
37+
ThisBuild / githubWorkflowPublishTargetBranches :=
38+
Seq(
39+
RefPredicate.StartsWith(Ref.Tag("v")),
40+
RefPredicate.Equals(Ref.Branch("master"))
41+
),
42+
ThisBuild / githubWorkflowPublish := Seq(
43+
WorkflowStep.Sbt(
44+
commands = List("ci-release"),
45+
name = Some("Publish project"),
46+
env = Map(
47+
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
48+
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
49+
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
50+
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
51+
)
52+
)
3353
)
3454
)
3555

project/plugins.sbt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
2-
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
1+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
2+
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
3+
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.24.0")
4+
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.6.1")

0 commit comments

Comments
 (0)