Skip to content

Commit

Permalink
Generate GitHub workflow using sbt-github-actions (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive authored Sep 30, 2024
1 parent 00cdfdb commit 05deba0
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 41 deletions.
107 changes: 92 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,103 @@
name: CI
# 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:
push:
branches:
- master
pull_request:
branches:
- master
branches: [master]
push:
branches: [master]
tags: [v*]

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

jobs:
build:
runs-on: ubuntu-latest
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.19]
java: [zulu@8]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (zulu@8)
if: matrix.java == 'zulu@8'
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 8
cache: sbt

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

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

- name: Build project
run: sbt '++ ${{ matrix.scala }}' test

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

- name: Upload target directories
uses: actions/upload-artifact@v4
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/tags/v'))
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.19]
java: [zulu@8]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: olafurpg/setup-scala@v13
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (zulu@8)
if: matrix.java == 'zulu@8'
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 8
cache: sbt

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

- name: Cache SBT coursier cache
uses: coursier/cache-action@v6
- name: Download target directories (2.12.19)
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-2.12.19-${{ matrix.java }}

- name: Scalafmt
run: sbt scalafmtAll scalafmtSbt
- name: Inflate target directories (2.12.19)
run: |
tar xf targets.tar
rm targets.tar
- name: Tests
run: sbt scripted
- 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
60 changes: 60 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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
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
20 changes: 0 additions & 20 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Maksim Ochenashko
Copyright (c) 2020 Maksym Ochenashko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sbt-integration-env

[![Build Status](https://github.com/iRevive/sbt-integration-env/workflows/CI/badge.svg)](https://github.com/iRevive/sbt-integration-env/actions?query=branch%3Amaster+workflow%3ACI+)
[![Build Status](https://github.com/iRevive/sbt-integration-env/workflows/CI/badge.svg)](https://github.com/iRevive/sbt-integration-env/actions)
[![sbt-integration-env Scala version support](https://index.scala-lang.org/irevive/sbt-integration-env/sbt-integration-env/latest-by-scala-version.svg?targetType=Sbt)](https://index.scala-lang.org/irevive/sbt-integration-env/sbt-integration-env)

sbt-integration-env is an SBT plugin for environment management.
Expand Down
22 changes: 19 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
ThisBuild / githubWorkflowTargetBranches := Seq("master")
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v")))

ThisBuild / githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
)
)

lazy val root = project
.in(file("."))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-integration-env",
organization := "io.github.irevive",
crossSbtVersions := Seq("1.5.3"),
crossSbtVersions := Seq("1.10.2"),
scriptedBufferLog := false,
scriptedLaunchOpts ++= Seq("-Xmx1024M", "-Dplugin.version=" + version.value),
homepage := Some(url("https://github.com/iRevive/sbt-integration-env")),
licenses := List("MIT" -> url("http://opensource.org/licenses/MIT")),
developers := List(Developer("iRevive", "Maksim Ochenashko", "", url("https://github.com/iRevive")))
licenses := List(License.MIT),
developers := List(Developer("iRevive", "Maksym Ochenashko", "", url("https://github.com/iRevive")))
)
3 changes: 2 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.6.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.24.0")

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value

0 comments on commit 05deba0

Please sign in to comment.