Skip to content

Commit

Permalink
move update readme job to an independent section
Browse files Browse the repository at this point in the history
  • Loading branch information
khajavi committed Mar 25, 2023
1 parent fc9f5cb commit 27e9a22
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 94 deletions.
85 changes: 41 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,47 @@ jobs:
fetch-depth: '0'
- name: Test
run: sbt ${{ matrix.scala-project }}/test
generate-readme:
name: Generate README
runs-on: ubuntu-latest
continue-on-error: false
if: ${{ (github.event_name == 'push') || ((github.event_name == 'release') && (github.event.action == 'published')) }}
steps:
- name: Git Checkout
uses: actions/checkout@v3.3.0
with:
fetch-depth: '0'
- name: Install libuv
run: sudo apt-get update && sudo apt-get install -y libuv1-dev
- name: Setup Scala
uses: actions/setup-java@v3.10.0
with:
distribution: temurin
java-version: '8'
check-latest: true
- name: Cache Dependencies
uses: coursier/cache-action@v6
- name: Generate Readme
run: sbt docs/generateReadme
- name: Commit Changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add README.md
git commit -m "Update README.md" || echo "No changes to commit"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4.2.4
with:
body: |-
Autogenerated changes after running the `sbt docs/generateReadme` command of the [zio-sbt-website](https://zio.dev/zio-sbt) plugin.
I will automatically update the README.md file whenever there is new change for README.md, e.g.
- After each release, I will update the version in the installation section.
- After any changes to the "docs/index.md" file, I will update the README.md file accordingly.
branch: zio-sbt-website/update-readme
commit-message: Update README.md
delete-branch: true
title: Update README.md
ci:
name: ci
runs-on: ubuntu-latest
Expand Down Expand Up @@ -167,50 +208,6 @@ jobs:
run: sbt docs/publishToNpm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
generate-readme:
name: Generate README
runs-on: ubuntu-latest
continue-on-error: false
needs:
- release
if: ${{ (github.event_name == 'push') || ((github.event_name == 'release') && (github.event.action == 'published')) }}
steps:
- name: Git Checkout
uses: actions/checkout@v3.3.0
with:
ref: ${{ github.head_ref }}
fetch-depth: '0'
- name: Install libuv
run: sudo apt-get update && sudo apt-get install -y libuv1-dev
- name: Setup Scala
uses: actions/setup-java@v3.10.0
with:
distribution: temurin
java-version: '8'
check-latest: true
- name: Cache Dependencies
uses: coursier/cache-action@v6
- name: Generate Readme
run: sbt docs/generateReadme
- name: Commit Changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add README.md
git commit -m "Update README.md" || echo "No changes to commit"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5-beta
with:
body: |-
Autogenerated changes after running the `sbt docs/generateReadme` command of the [zio-sbt-website](https://zio.dev/zio-sbt) plugin.
I will automatically update the README.md file whenever there is new change for README.md, e.g.
- After each release, I will update the version in the installation section.
- After any changes to the "docs/index.md" file, I will update the README.md file accordingly.
branch: zio-sbt-website/update-readme
commit-message: Update README.md
delete-branch: true
title: Update README.md
docs-release-notification:
name: Docs Release Notification
runs-on: ubuntu-latest
Expand Down
108 changes: 58 additions & 50 deletions zio-sbt-ci/src/main/scala/zio/sbt/ZioSbtCiPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
val ciBuildJobs: SettingKey[Seq[Job]] = settingKey[Seq[Job]]("CI Build Jobs")
val ciLintJobs: SettingKey[Seq[Job]] = settingKey[Seq[Job]]("CI Lint Jobs")
val ciTestJobs: SettingKey[Seq[Job]] = settingKey[Seq[Job]]("CI Test Jobs")
val ciUpdateReadmeJobs: SettingKey[Seq[Job]] = settingKey[Seq[Job]]("CI Update Readme Jobs")
val ciReleaseJobs: SettingKey[Seq[Job]] = settingKey[Seq[Job]]("CI Release Jobs")
val ciPostReleaseJobs: SettingKey[Seq[Job]] = settingKey[Seq[Job]]("CI Post Release Jobs")

Expand Down Expand Up @@ -307,6 +308,59 @@ object ZioSbtCiPlugin extends AutoPlugin {
)
}

lazy val updateReadmeJobs: Def.Initialize[Seq[Job]] = Def.setting {
val swapSizeGB = ciSwapSizeGB.value
val setSwapSpace = SetSwapSpace.value
val checkout = Checkout.value
val javaVersion = ciDefaultTargetJavaVersion.value
val updateReadmeCondition = autoImport.ciUpdateReadmeCondition.value
val generateReadme = GenerateReadme.value

Seq(
Job(
id = "generate-readme",
name = "Generate README",
condition = updateReadmeCondition orElse Some(
Condition.Expression("github.event_name == 'push'") ||
Condition.Expression("github.event_name == 'release'") &&
Condition.Expression("github.event.action == 'published'")
),
steps = (if (swapSizeGB > 0) Seq(setSwapSpace) else Seq.empty) ++
Seq(
checkout,
SetupLibuv,
SetupJava(javaVersion),
CacheDependencies,
generateReadme,
Step.SingleStep(
name = "Commit Changes",
run = Some("""|git config --local user.email "github-actions[bot]@users.noreply.github.com"
|git config --local user.name "github-actions[bot]"
|git add README.md
|git commit -m "Update README.md" || echo "No changes to commit"
|""".stripMargin)
),
Step.SingleStep(
name = "Create Pull Request",
uses = Some(ActionRef("peter-evans/create-pull-request@v4.2.4")),
parameters = Map(
"title" -> "Update README.md".asJson,
"commit-message" -> "Update README.md".asJson,
"branch" -> "zio-sbt-website/update-readme".asJson,
"delete-branch" -> true.asJson,
"body" ->
"""|Autogenerated changes after running the `sbt docs/generateReadme` command of the [zio-sbt-website](https://zio.dev/zio-sbt) plugin.
|
|I will automatically update the README.md file whenever there is new change for README.md, e.g.
| - After each release, I will update the version in the installation section.
| - After any changes to the "docs/index.md" file, I will update the README.md file accordingly.""".stripMargin.asJson
)
)
)
)
)
}

lazy val releaseJobs: Def.Initialize[Seq[Job]] = Def.setting {
val swapSizeGB = ciSwapSizeGB.value
val setSwapSpace = SetSwapSpace.value
Expand Down Expand Up @@ -367,55 +421,6 @@ object ZioSbtCiPlugin extends AutoPlugin {
)
)
),
Job(
id = "generate-readme",
name = "Generate README",
need = Seq("release"),
condition = updateReadmeCondition orElse Some(
Condition.Expression("github.event_name == 'push'") ||
Condition.Expression("github.event_name == 'release'") &&
Condition.Expression("github.event.action == 'published'")
),
steps = (if (swapSizeGB > 0) Seq(setSwapSpace) else Seq.empty) ++
Seq(
Step.SingleStep(
name = "Git Checkout",
uses = Some(ActionRef("actions/checkout@v3.3.0")),
parameters = Map(
"ref" -> "${{ github.head_ref }}".asJson,
"fetch-depth" -> "0".asJson
)
),
SetupLibuv,
SetupJava(javaVersion),
CacheDependencies,
generateReadme,
Step.SingleStep(
name = "Commit Changes",
run = Some("""|git config --local user.email "github-actions[bot]@users.noreply.github.com"
|git config --local user.name "github-actions[bot]"
|git add README.md
|git commit -m "Update README.md" || echo "No changes to commit"
|""".stripMargin)
),
Step.SingleStep(
name = "Create Pull Request",
uses = Some(ActionRef("peter-evans/create-pull-request@v5-beta")),
parameters = Map(
"title" -> "Update README.md".asJson,
"commit-message" -> "Update README.md".asJson,
"branch" -> "zio-sbt-website/update-readme".asJson,
"delete-branch" -> true.asJson,
"body" ->
"""|Autogenerated changes after running the `sbt docs/generateReadme` command of the [zio-sbt-website](https://zio.dev/zio-sbt) plugin.
|
|I will automatically update the README.md file whenever there is new change for README.md, e.g.
| - After each release, I will update the version in the installation section.
| - After any changes to the "docs/index.md" file, I will update the README.md file accordingly.""".stripMargin.asJson
)
)
)
),
Job(
id = "docs-release-notification",
name = "Docs Release Notification",
Expand Down Expand Up @@ -457,6 +462,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
val lintJobs = ciLintJobs.value
val testJobs = ciTestJobs.value
val reportSuccessful = reportSuccessfulJobs.value
val updateReadmeJobs = ciUpdateReadmeJobs.value
val releaseJobs = ciReleaseJobs.value
val postReleaseJobs = ciPostReleaseJobs.value
val jvmOptions = Seq("-XX:+PrintCommandLineFlags") ++ ciJvmOptions.value
Expand Down Expand Up @@ -489,7 +495,8 @@ object ZioSbtCiPlugin extends AutoPlugin {
Trigger.Push(branches = enabledBranches.map(Branch.Named)),
Trigger.PullRequest()
),
jobs = buildJobs ++ lintJobs ++ testJobs ++ reportSuccessful ++ releaseJobs ++ postReleaseJobs
jobs =
buildJobs ++ lintJobs ++ testJobs ++ updateReadmeJobs ++ reportSuccessful ++ releaseJobs ++ postReleaseJobs
).asJson
)

Expand Down Expand Up @@ -547,6 +554,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
ciBuildJobs := buildJobs.value,
ciLintJobs := lintJobs.value,
ciTestJobs := testJobs.value,
ciUpdateReadmeJobs := updateReadmeJobs.value,
ciReleaseJobs := releaseJobs.value,
ciPostReleaseJobs := postReleaseJobs.value,
ciPullRequestApprovalJobs := Seq("lint", "test", "build"),
Expand Down

0 comments on commit 27e9a22

Please sign in to comment.