Skip to content

Commit

Permalink
Added test to ensure that artifacts filtering works
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Jun 16, 2020
1 parent 81e6389 commit 3c40ebb
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 0 deletions.
176 changes: 176 additions & 0 deletions src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# 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:
pull_request:
branches: ['*']
push:
branches: ['*']

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

jobs:
build:
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.2]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (fast)
uses: actions/checkout@v2

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v5
with:
java-version: ${{ matrix.java }}

- name: Cache ivy2
uses: actions/cache@v1
with:
path: ~/.ivy2/cache
key: ${{ runner.os }}-sbt-ivy-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache coursier (generic)
uses: actions/cache@v1
with:
path: ~/.coursier/cache/v1
key: ${{ runner.os }}-generic-sbt-coursier-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache coursier (linux)
if: contains(runner.os, 'linux')
uses: actions/cache@v1
with:
path: ~/.cache/coursier/v1
key: ${{ runner.os }}-sbt-coursier-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache coursier (macOS)
if: contains(runner.os, 'macos')
uses: actions/cache@v1
with:
path: ~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-coursier-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache coursier (windows)
if: contains(runner.os, 'windows')
uses: actions/cache@v1
with:
path: ~/AppData/Local/Coursier/Cache/v1
key: ${{ runner.os }}-sbt-coursier-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache sbt
uses: actions/cache@v1
with:
path: ~/.sbt
key: ${{ runner.os }}-sbt-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

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

- run: sbt ++${{ matrix.scala }} withTarget/compile

- name: Upload target directory 'target' (${{ matrix.scala }})
uses: actions/upload-artifact@v1
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}-target
path: target

- name: Upload target directory 'withTarget/target' (${{ matrix.scala }})
uses: actions/upload-artifact@v1
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}-withTarget_target
path: withTarget/target

- name: Upload target directory 'project/target'
uses: actions/upload-artifact@v1
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-project_target
path: project/target

publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/master')
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.2]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (fast)
uses: actions/checkout@v2

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v5
with:
java-version: ${{ matrix.java }}

- name: Cache ivy2
uses: actions/cache@v1
with:
path: ~/.ivy2/cache
key: ${{ runner.os }}-sbt-ivy-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache coursier (generic)
uses: actions/cache@v1
with:
path: ~/.coursier/cache/v1
key: ${{ runner.os }}-generic-sbt-coursier-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache coursier (linux)
if: contains(runner.os, 'linux')
uses: actions/cache@v1
with:
path: ~/.cache/coursier/v1
key: ${{ runner.os }}-sbt-coursier-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache coursier (macOS)
if: contains(runner.os, 'macos')
uses: actions/cache@v1
with:
path: ~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-coursier-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache coursier (windows)
if: contains(runner.os, 'windows')
uses: actions/cache@v1
with:
path: ~/AppData/Local/Coursier/Cache/v1
key: ${{ runner.os }}-sbt-coursier-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Cache sbt
uses: actions/cache@v1
with:
path: ~/.sbt
key: ${{ runner.os }}-sbt-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directory 'target' (2.13.2)
uses: actions/download-artifact@v1
with:
name: target-${{ matrix.os }}-2.13.2-${{ matrix.java }}-target
path: target

- name: Download target directory 'withTarget/target' (2.13.2)
uses: actions/download-artifact@v1
with:
name: target-${{ matrix.os }}-2.13.2-${{ matrix.java }}-withTarget_target
path: withTarget/target

- name: Download target directory 'project/target'
uses: actions/download-artifact@v1
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-project_target
path: project/target

- name: Publish project
run: sbt ++${{ matrix.scala }} +publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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
run: |
# Customize those three lines with your repository and credentials:
REPO=https://api.github.com/repos/$1
# A shortcut to call GitHub API.
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }
# A temporary file which receives HTTP response headers.
TMPFILE=/tmp/tmp.$$
# 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
25 changes: 25 additions & 0 deletions src/sbt-test/sbtghactions/non-existent-target/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
organization := "com.codecommit"
version := "0.0.1"

ThisBuild / crossScalaVersions := Seq("2.13.2")
ThisBuild / scalaVersion := crossScalaVersions.value.head

// explicitly don't build `withoutTarget`
ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("withTarget/compile")))

def withoutTargetPredicate(step: WorkflowStep): Boolean = step match {
case step: WorkflowStep.Use => step.params("path").startsWith("withoutTarget")
case _ => false
}

ThisBuild / githubWorkflowGeneratedUploadSteps :=
(ThisBuild / githubWorkflowGeneratedUploadSteps).value.filterNot(withoutTargetPredicate)

ThisBuild / githubWorkflowGeneratedDownloadSteps :=
(ThisBuild / githubWorkflowGeneratedDownloadSteps).value.filterNot(withoutTargetPredicate)

lazy val root = project.in(file(".")).aggregate(withTarget, withoutTarget)

lazy val withTarget = project.in(file("withTarget"))

lazy val withoutTarget = project.in(file("withoutTarget"))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.3.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.codecommit" % "sbt-github-actions" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
1 change: 1 addition & 0 deletions src/sbt-test/sbtghactions/non-existent-target/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> githubWorkflowCheck

0 comments on commit 3c40ebb

Please sign in to comment.