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

Feature/workflow support #65

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
10c5b24
Fix typo
987Nabil May 31, 2021
b27937b
Use simple generic workflow for internal workflow compilation
987Nabil Jun 1, 2021
f9ba5c6
Merge remote-tracking branch 'upstream/main' into feature/workflow-su…
987Nabil Jun 2, 2021
ba3975b
Separate files for Workflow, TriggerEvent and common RenderFunctions
987Nabil Jun 2, 2021
67e746f
Impl. ManualEvents
987Nabil Jun 3, 2021
df528f3
Impl. WebhookEvents
987Nabil Jun 7, 2021
d827cca
Generate custom workflows
987Nabil Jun 7, 2021
c228a3d
Do not use tags for pull request in ci workflow
987Nabil Jun 7, 2021
99c15d6
Docu for custom workflows
987Nabil Jun 8, 2021
c6f0a65
Paths for Push and PullRequest events
987Nabil Jun 8, 2021
153bb2d
Make Workflow jobs compile without oses
987Nabil Jun 14, 2021
33d6ee7
Introduce generation targets to adjust which workflows will be generated
987Nabil Jun 20, 2021
0ca4784
Merge remote-tracking branch 'upstream/main' into feature/workflow-su…
987Nabil Jul 19, 2021
132e807
Merge remote-tracking branch 'upstream/main' into feature/workflow-su…
987Nabil Aug 12, 2021
0ca1ced
Fix test expectation for path only rendering of pull request events
987Nabil Aug 12, 2021
f7d7603
Fix rendering in case of empty scalas
987Nabil Dec 29, 2021
c46d1cb
Support rendering without strategy/matrix
987Nabil Jan 11, 2022
1842373
Merge remote-tracking branch 'upstream/main' into feature/workflow-su…
987Nabil Jan 11, 2022
85702f8
Migrate custom workflows with main changes
987Nabil Jan 11, 2022
9c8bad7
Support for reusable workflows
987Nabil Jan 11, 2022
9fa66df
Check githubWorkflowIncludeClean to generate clean workflow as well
987Nabil Jan 11, 2022
fe9cacc
Fix reusable workflow rendering
987Nabil Jan 12, 2022
d09b0d7
Make reusable workflow jobs another class
987Nabil Jan 12, 2022
a945784
Merge remote-tracking branch 'upstream/main' into feature/workflow-su…
987Nabil Feb 3, 2023
7c90b65
Integrate permissions into the workflow DSL
987Nabil Feb 3, 2023
cf4f7ae
Regenerate workflows
987Nabil Feb 3, 2023
2a5dc1f
Adjust test expectations
987Nabil Feb 3, 2023
55e748d
Add GitHub doc links to Workflow DSL
987Nabil Feb 25, 2023
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
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ on:
push:
branches: ['**']
tags: [v*]

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

jobs:
build:
name: Build and Test
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ThisBuild / githubWorkflowPublish := Seq(

### Generative

- `githubWorkflowGenerate` – Generates (and overwrites if extant) **ci.yml** and **clean.yml** workflows according to configuration within sbt. The **clean.yml** workflow is something that GitHub Actions should just do by default: it removes old build artifacts to prevent them from running up your storage usage (it has no effect on currently running builds). This workflow is unconfigurable and is simply drawn from the static contents of the **clean.yml** resource file within this repository.
- `githubWorkflowGenerate` – Generates (and overwrites if extant) **ci.yml**, **clean.yml** and all custom (see `githubWorkflowCustomWorkflows`) workflows according to configuration within sbt. The **clean.yml** workflow is something that GitHub Actions should just do by default: it removes old build artifacts to prevent them from running up your storage usage (it has no effect on currently running builds). This workflow is unconfigurable and is simply drawn from the static contents of the **clean.yml** resource file within this repository.
- `githubWorkflowCheck` – Checks to see if the **ci.yml** and **clean.yml** files are equivalent to what would be generated and errors if otherwise. This task is run from within the generated **ci.yml** to ensure that the build and the workflow are kept in sync. As a general rule, any time you change the workflow configuration within sbt, you should regenerate the **ci.yml** and commit the results, but inevitably people forget. This check fails the build if that happens. Note that if you *need* to manually fiddle with the **ci.yml** contents, for whatever reason, you will need to remove the call to this check from within the workflow, otherwise your build will simply fail.

## Settings
Expand All @@ -99,6 +99,7 @@ Any and all settings which affect the behavior of the generative plugin should b

#### General

- `githubWorkflowGenerationTargets` : `Set[GenerationTarget]` — A set of targets to be generated. Possible values are `CI`, `Clean` and `Custom`.
- `githubWorkflowGeneratedCI` : `Seq[WorkflowJob]` — Contains a description of the **ci.yml** jobs that will drive the generation if used. This setting can be overridden to customize the jobs (e.g. by adding additional jobs to the workflow).
- `githubWorkflowGeneratedUploadSteps` : `Seq[WorkflowStep]` – Contains a list of steps which are used to upload generated intermediate artifacts from the `build` job. This is mostly for reference and introspection purposes; one would not be expected to *change* this setting.
- `githubWorkflowGeneratedDownloadSteps` : `Seq[WorkflowStep]` – Contains a list of steps which are used to download generated intermediate artifacts from the `build` job. This is mostly for reference and introspection purposes; one would not be expected to *change* this setting. This setting is particularly useful in conjunction with `githubWorkflowAddedJobs`: if you're adding a job which needs access to intermediate artifacts, you should make sure these steps are part of the process.
Expand All @@ -115,6 +116,7 @@ Any and all settings which affect the behavior of the generative plugin should b
- `githubWorkflowJobSetup` : `Seq[WorkflowStep]` – The automatically-generated checkout, setup, and cache steps which are common to all jobs which touch the build (default: autogenerated)
- `githubWorkflowEnv` : `Map[String, String]` – An environment which is global to the entire **ci.yml** workflow. Defaults to `Map("GITHUB_TOKEN" -> "${{ secrets.GITHUB_TOKEN }}")` since it's so commonly needed.
- `githubWorkflowAddedJobs` : `Seq[WorkflowJob]` – A convenience mechanism for adding extra custom jobs to the **ci.yml** workflow (though you can also do this by modifying `githubWorkflowGeneratedCI`). Defaults to empty.
- `githubWorkflowCustomWorkflows`: `Map[String, Workflow]` - This is the place to define your custom workflows. The key represents the filename (**.yml** is added if not provided) the value the workflow definition. The settings of the generative plugin apply, as long as they are not part of the workflow trigger events. For example, the `githubWorkflowTargetBranches` setting has no influence on custom workflows, but `githubWorkflowScalaVersions` does.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about keys like githubWorkflowJavaVersions or githubWorkflowOSes? Is this supported (if not I suspect that this may be a case of feature creep but having the ability to interpolate these keys into custom workflows would be useful/beneficial if practical).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you have in mind, but this is now a very general API. It might be, that there is not even a java version needed for the workflow. Also GitHub has the feature of self hosted runners, that might not have the tags for the oses. So that might be confusing for the user. I guess using this keys should be up to the one defining the Workflows.

Copy link
Contributor

@mdedetrich mdedetrich Feb 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to put it differently, what I had is having the ability to use the githubWorkflowJavaVersions/githubWorkflowOSes values in a custom ReusableWorkflowJob. While its definitely true that it doesn't make sense in some cases, at least having access to those values can be useful for certain types of custom workflows which this PR implements as a feature.

What I had in mind is adjusting ReusableWorkflowJob so that it has the https://github.com/sbt/sbt-github-actions/pull/65/files#diff-535533c663b9848aff0c0b943149d3dd8b126b34aa463e507ada7e6011ce8288R38-R39 so that it has the scalas and javas variables.

See https://github.com/sbt/sbt-github-actions/pull/65/files#r1117907905.


#### `build` Job

Expand Down
28 changes: 28 additions & 0 deletions src/main/scala/sbtghactions/CheckRunEventType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020-2021 Daniel Spiewak
*
* 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 sbtghactions

987Nabil marked this conversation as resolved.
Show resolved Hide resolved
/**
* @see https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#check_run
*/
sealed trait CheckRunEventType extends EventType
mdedetrich marked this conversation as resolved.
Show resolved Hide resolved

object CheckRunEventType {
case object Created extends CheckRunEventType
case object Rerequested extends CheckRunEventType
case object Completed extends CheckRunEventType
}
28 changes: 28 additions & 0 deletions src/main/scala/sbtghactions/CheckSuiteEventType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020-2021 Daniel Spiewak
*
* 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 sbtghactions

987Nabil marked this conversation as resolved.
Show resolved Hide resolved
/**
* @see https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#check_run
*/
sealed trait CheckSuiteEventType extends EventType
mdedetrich marked this conversation as resolved.
Show resolved Hide resolved

object CheckSuiteEventType {
case object Completed extends CheckSuiteEventType
case object Requested extends CheckSuiteEventType
case object Rerequested extends CheckSuiteEventType
}
23 changes: 23 additions & 0 deletions src/main/scala/sbtghactions/EventType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2020-2021 Daniel Spiewak
*
* 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 sbtghactions

import sbtghactions.RenderFunctions.SnakeCase

trait EventType extends Product with Serializable {
def render: String = SnakeCase(productPrefix)
}
28 changes: 28 additions & 0 deletions src/main/scala/sbtghactions/GenerationTarget.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020-2021 Daniel Spiewak
*
* 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 sbtghactions

mdedetrich marked this conversation as resolved.
Show resolved Hide resolved

sealed trait GenerationTarget extends Product with Serializable

object GenerationTarget {
val all: Set[GenerationTarget] = Set(GenerationTarget.CI, GenerationTarget.Clean, GenerationTarget.Custom)

case object CI extends GenerationTarget
case object Clean extends GenerationTarget
case object Custom extends GenerationTarget
}
3 changes: 3 additions & 0 deletions src/main/scala/sbtghactions/GenerativeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ 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 githubWorkflowGenerationTargets = settingKey[Set[GenerationTarget]]("Configure targets to be generated. (CI, Clean or Custom)")
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 githubWorkflowCustomWorkflows = settingKey[Map[String, Workflow]]("Custom workflows, defined by a map of file name to Workflow.")

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)")
Expand Down
Loading