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

github workflows setup #2

Merged
merged 9 commits into from
Nov 7, 2024
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
90 changes: 90 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Continuous Integration

on:
pull_request:
branches: [ '**' ]
push:
branches: [ master ]
tags: [ "*" ]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build and Test
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
distribution: temurin
java: 17

runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: "${{ matrix.distribution }}"
java-version: "${{ matrix.java }}"

- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Build project
run: sbt -v scalafmtCheckAll test scripted
env:
PROTOFETCH_GIT_PROTOCOL: https

- name: Compress target directories
run: tar cf targets.tar target sbt-protofetch/target project/target

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

publish:
name: Publish Artifacts
needs: [ build ]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master')
runs-on: ubuntu-latest
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@17)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17

- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Download target directories
uses: actions/download-artifact@v4
with:
name: target-17

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

- name: Publish project
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
run: sbt ci-release
61 changes: 61 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
m-kalai marked this conversation as resolved.
Show resolved Hide resolved
# 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.
# UPDATE: Plugin was removed since then, but we still keep the 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
shell: bash {0}
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=$(mktemp)

# 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
18 changes: 14 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
val versions = new {
val sbt = "1.6.0"
val scala212 = "2.12.20"
val sbt = "1.5.8"
val commonsCompress = "1.27.1"
val toml4j = "0.7.3"
val munit = "1.0.2"
}

val common = Seq(
val common: Seq[Setting[_]] = Seq(
organizationName := "Coralogix Ltd.",
organization := "com.coralogix",
startYear := Some(2024),
Expand All @@ -14,14 +15,23 @@ val common = Seq(
)),
headerLicense := Some(HeaderLicense.ALv2("2024", "Coralogix Ltd.")),
homepage := Some(url("https://github.com/coralogix/sbt-protofetch")),
version := "0.1.0-SNAPSHOT"
version := "0.1.0-SNAPSHOT",
scalaVersion := versions.scala212
)

lazy val `sbt-protofetch` = (project in file("sbt-protofetch"))
.enablePlugins(SbtPlugin)
.settings(common)
.settings(
pluginCrossBuild / sbtVersion := versions.sbt,
crossScalaVersions := Seq(versions.scala212),
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" =>
versions.sbt
case _ =>
"2.0.0-M2" // just a preparation for Scala 3 / sbt 2
}
},
libraryDependencies ++= Seq(
"org.apache.commons" % "commons-compress" % versions.commonsCompress,
"io.hotmoka" % "toml4j" % versions.toml4j,
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.7
sbt.version=1.10.4
5 changes: 3 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.6.1")