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

Bring in sbt-gh-actions #62

Merged
merged 5 commits into from
Jan 16, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ jobs:
- run: sbt ++${{ matrix.scala }} '${{ matrix.ci }}'

- name: Make target directories
run: mkdir -p github/target kernel/target versioning/target ci-release/target target .js/target ci-signing/target mima/target .jvm/target .native/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target project/target
run: mkdir -p github/target github-actions/target kernel/target versioning/target ci-release/target target .js/target ci-signing/target mima/target .jvm/target .native/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target project/target

- name: Compress target directories
run: tar cf targets.tar github/target kernel/target versioning/target ci-release/target target .js/target ci-signing/target mima/target .jvm/target .native/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target project/target
run: tar cf targets.tar github/target github-actions/target kernel/target versioning/target ci-release/target target .js/target ci-signing/target mima/target .jvm/target .native/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
Expand Down
13 changes: 11 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ lazy val root = tlCrossRootProject.aggregate(
noPublish,
settings,
github,
githubActions,
versioning,
mima,
sonatype,
Expand Down Expand Up @@ -54,6 +55,13 @@ lazy val github = project
)
.dependsOn(kernel)

lazy val githubActions = project
.in(file("github-actions"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-typelevel-github-actions"
)

lazy val versioning = project
.in(file("versioning"))
.enablePlugins(SbtPlugin)
Expand Down Expand Up @@ -84,22 +92,23 @@ lazy val ciSigning = project
.settings(
name := "sbt-typelevel-ci-signing"
)
.dependsOn(githubActions)

lazy val sonatypeCiRelease = project
.in(file("sonatype-ci-release"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-typelevel-sonatype-ci-release"
)
.dependsOn(sonatype)
.dependsOn(sonatype, githubActions)

lazy val ci = project
.in(file("ci"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-typelevel-ci"
)
.dependsOn(noPublish, kernel)
.dependsOn(noPublish, kernel, githubActions)

lazy val ciRelease = project
.in(file("ci-release"))
Expand Down
1 change: 0 additions & 1 deletion ci-signing/build.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.14.2")
addSbtPlugin("io.crashbox" % "sbt-gpg" % "0.2.1")
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package org.typelevel.sbt

import io.crashbox.gpg.SbtGpg
import sbt._, Keys._
import sbtghactions.GenerativePlugin
import sbtghactions.GitHubActionsPlugin
import sbtghactions.GenerativePlugin.autoImport._
import org.typelevel.sbt.gha.GenerativePlugin
import org.typelevel.sbt.gha.GitHubActionsPlugin
import org.typelevel.sbt.gha.GenerativePlugin.autoImport._

object TypelevelCiSigningPlugin extends AutoPlugin {

Expand Down
1 change: 0 additions & 1 deletion ci/build.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.14.2")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")
2 changes: 1 addition & 1 deletion ci/src/main/scala/org/typelevel/sbt/CrossRootProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.typelevel.sbt

import sbt._
import sbtghactions.GenerativePlugin.autoImport._
import org.typelevel.sbt.gha.GenerativePlugin.autoImport._
import TypelevelCiPlugin.ciCommands
import TypelevelKernelPlugin.mkCommand

Expand Down
6 changes: 3 additions & 3 deletions ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package org.typelevel.sbt

import sbt._
import sbtghactions.GenerativePlugin
import sbtghactions.GitHubActionsPlugin
import sbtghactions.GenerativePlugin.autoImport._
import org.typelevel.sbt.gha.GenerativePlugin
import org.typelevel.sbt.gha.GitHubActionsPlugin
import org.typelevel.sbt.gha.GenerativePlugin.autoImport._
import com.typesafe.tools.mima.plugin.MimaPlugin
import TypelevelKernelPlugin.mkCommand

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.typelevel.sbt

import sbt._, Keys._
import sbtghactions.GenerativePlugin
import sbtghactions.GitHubActionsPlugin
import org.typelevel.sbt.gha.GenerativePlugin
import org.typelevel.sbt.gha.GitHubActionsPlugin
import de.heikoseeberger.sbtheader.AutomateHeaderPlugin
import TypelevelCiPlugin.ciCommands
import TypelevelKernelPlugin.mkCommand
Expand Down
1 change: 1 addition & 0 deletions github-actions/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libraryDependencies += "org.yaml" % "snakeyaml" % "1.29"
59 changes: 59 additions & 0 deletions github-actions/src/main/resources/clean.yml
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=${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=/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
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2022 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.sbt.gha

import sbt._

trait GenerativeKeys {

lazy val githubWorkflowGenerate = taskKey[Unit](
"Generates (and overwrites if extant) a ci.yml and clean.yml actions description according to configuration")
lazy val githubWorkflowCheck = taskKey[Unit](
"Checks to see if the ci.yml and clean.yml files are equivalent to what would be generated and errors if otherwise")

lazy val githubWorkflowGeneratedCI = settingKey[Seq[WorkflowJob]](
"The sequence of jobs which will make up the generated ci workflow (ci.yml)")
lazy val githubWorkflowGeneratedUploadSteps = settingKey[Seq[WorkflowStep]](
"The sequence of steps used to upload intermediate build artifacts for an adjacent job")
lazy val githubWorkflowGeneratedDownloadSteps = settingKey[Seq[WorkflowStep]](
"The sequence of steps used to download intermediate build artifacts published by an adjacent job")
lazy val githubWorkflowGeneratedCacheSteps = settingKey[Seq[WorkflowStep]](
"The sequence of steps used to configure caching for ivy, sbt, and coursier")

lazy val githubWorkflowSbtCommand =
settingKey[String]("The command which invokes sbt (default: sbt)")
lazy val githubWorkflowUseSbtThinClient = settingKey[Boolean](
"Whether to use sbt's native thin client, default is false since this can cause issues (see https://github.com/sbt/sbt/issues/6468)")
lazy val githubWorkflowIncludeClean =
settingKey[Boolean]("Whether to include the clean.yml file (default: true)")

lazy val githubWorkflowBuildMatrixFailFast = settingKey[Option[Boolean]](
"Whether or not to enable the fail-fast strategy (default: None/Enabled)")
lazy val githubWorkflowBuildMatrixAdditions = settingKey[Map[String, List[String]]](
"A map of additional matrix dimensions for the build job. Each list should be non-empty. (default: {})")
lazy val githubWorkflowBuildMatrixInclusions =
settingKey[Seq[MatrixInclude]]("A list of matrix inclusions (default: [])")
lazy val githubWorkflowBuildMatrixExclusions =
settingKey[Seq[MatrixExclude]]("A list of matrix exclusions (default: [])")
lazy val githubWorkflowBuildRunsOnExtraLabels = settingKey[Seq[String]](
"A list of additional labels to append to each run of the matrix executions")

lazy val githubWorkflowBuildPreamble = settingKey[Seq[WorkflowStep]](
"A list of steps to insert after base setup but before compiling and testing (default: [])")
lazy val githubWorkflowBuildPostamble = settingKey[Seq[WorkflowStep]](
"A list of steps to insert after comping and testing but before the end of the build job (default: [])")
lazy val githubWorkflowBuild = settingKey[Seq[WorkflowStep]](
"A sequence of workflow steps which compile and test the project (default: [Sbt(List(\"test\"))])")

lazy val githubWorkflowPublishPreamble = settingKey[Seq[WorkflowStep]](
"A list of steps to insert after base setup but before publishing (default: [])")
lazy val githubWorkflowPublishPostamble = settingKey[Seq[WorkflowStep]](
"A list of steps to insert after publication but before the end of the publish job (default: [])")
lazy val githubWorkflowPublish = settingKey[Seq[WorkflowStep]](
"A sequence workflow steps which publishes the project (default: [Sbt(List(\"+publish\"))])")
lazy val githubWorkflowPublishTargetBranches = settingKey[Seq[RefPredicate]](
"A set of branch predicates which will be applied to determine whether the current branch gets a publication stage; if empty, publish will be skipped entirely (default: [== main])")
lazy val githubWorkflowPublishCond = settingKey[Option[String]](
"A set of conditionals to apply to the publish job to further restrict its run (default: [])")

lazy val githubWorkflowJavaVersions = settingKey[Seq[JavaSpec]](
"A list of Java versions to be used for the build job. The publish job will use the *first* of these versions. (default: [temurin@11])")
lazy val githubWorkflowScalaVersions = settingKey[Seq[String]](
"A list of Scala versions on which to build the project (default: crossScalaVersions.value)")
lazy val githubWorkflowOSes =
settingKey[Seq[String]]("A list of OS names (default: [ubuntu-latest])")

lazy val githubWorkflowDependencyPatterns = settingKey[Seq[String]](
"A list of file globes within the project which affect dependency information (default: [**/*.sbt, project/build.properties])")
lazy val githubWorkflowTargetBranches = settingKey[Seq[String]](
"A list of branch patterns on which to trigger push and PR builds (default: [*])")
lazy val githubWorkflowTargetTags = settingKey[Seq[String]](
"A list of tag patterns on which to trigger push builds (default: [])")
lazy val githubWorkflowTargetPaths = settingKey[Paths](
"Paths which will match modified files for `push` and `pull_request` event types to trigger the workflow. May be `Paths.None`, `Paths.Include(patterns)`, or `Paths.Ignore(patterns)`. `Paths.Include` may include negative patterns. Defaults to `Paths.None`.")
lazy val githubWorkflowPREventTypes = settingKey[Seq[PREventType]](
"A list of pull request event types which will be used to trigger builds (default: [opened, synchronize, reopened])")

lazy val githubWorkflowArtifactUpload = settingKey[Boolean](
"Controls whether or not to upload target directories in the event that multiple jobs are running sequentially. Can be set on a per-project basis (default: true)")
lazy val githubWorkflowJobSetup = settingKey[Seq[WorkflowStep]](
"The automatically-generated checkout, setup, and cache steps which are common to all jobs which touch the build (default: autogenerated)")

lazy val githubWorkflowEnv = settingKey[Map[String, String]](
s"A map of static environment variable assignments global to the workflow (default: { GITHUB_TOKEN: $${{ secrets.GITHUB_TOKEN }} })")
lazy val githubWorkflowAddedJobs = settingKey[Seq[WorkflowJob]](
"A list of additional jobs to add to the CI workflow (default: [])")
}

object GenerativeKeys extends GenerativeKeys
Loading