From 15b82bc8614f2d8d19bcd480e19992c54da45436 Mon Sep 17 00:00:00 2001 From: Milad Khajavi Date: Fri, 6 Jan 2023 12:56:31 +0330 Subject: [PATCH] Update checkout action (#82) * update checkout action. * update checkout action version. * update checkout action. * fix. --- .github/workflows/ci.yml | 6 +- .github/workflows/site.yml | 6 +- .../src/main/scala/zio/sbt/WebsiteUtils.scala | 140 +++++++++--------- 3 files changed, 80 insertions(+), 72 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db27832f..080978a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: fail-fast: false steps: - name: Checkout current branch - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 with: fetch-depth: 0 - name: Setup Scala and Java @@ -40,7 +40,7 @@ jobs: java: ['adopt@1.8', 'adopt@1.11'] scala: ['2.12.17'] steps: - - uses: actions/checkout@v3.2.0 + - uses: actions/checkout@v3.3.0 - uses: olafurpg/setup-scala@v13 with: java-version: ${{ matrix.java }} @@ -55,7 +55,7 @@ jobs: needs: [build,lint] if: github.event_name != 'pull_request' steps: - - uses: actions/checkout@v3.2.0 + - uses: actions/checkout@v3.3.0 with: fetch-depth: 0 - uses: olafurpg/setup-scala@v13 diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index 4511af02..cbf8e208 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -18,7 +18,7 @@ jobs: if: ${{ github.event_name == 'pull_request' }} steps: - name: Git Checkout - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 with: fetch-depth: '0' - name: Setup Scala @@ -37,7 +37,7 @@ jobs: if: ${{ ((github.event_name == 'release') && (github.event.action == 'published')) || (github.event_name == 'workflow_dispatch') }} steps: - name: Git Checkout - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 with: fetch-depth: '0' - name: Setup Scala @@ -61,7 +61,7 @@ jobs: if: ${{ github.event_name == 'push' }} steps: - name: Git Checkout - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 with: ref: ${{ github.head_ref }} fetch-depth: '0' diff --git a/zio-sbt-website/src/main/scala/zio/sbt/WebsiteUtils.scala b/zio-sbt-website/src/main/scala/zio/sbt/WebsiteUtils.scala index d63d7a4a..ecb1e8e0 100644 --- a/zio-sbt-website/src/main/scala/zio/sbt/WebsiteUtils.scala +++ b/zio-sbt-website/src/main/scala/zio/sbt/WebsiteUtils.scala @@ -173,7 +173,68 @@ object WebsiteUtils { docsPublishBranch: String, sbtBuildOptions: List[String] = List.empty, versioning: DocsVersioning = SemanticVersioning - ): String = + ): String = { + object Actions { + val checkout: ActionRef = ActionRef("actions/checkout@v3.3.0") + val `setup-java`: ActionRef = ActionRef("actions/setup-java@v3.9.0") + val `setup-node`: ActionRef = ActionRef("actions/setup-node@v3") + } + + import Actions.* + + object Steps { + val Checkout: Step.SingleStep = Step.SingleStep( + name = "Git Checkout", + uses = Some(checkout), + parameters = Map("fetch-depth" -> "0".asJson) + ) + + val SetupJava: Step.SingleStep = Step.SingleStep( + name = "Setup Scala", + uses = Some(`setup-java`), + parameters = Map( + "distribution" -> "temurin".asJson, + "java-version" -> 17.asJson, + "check-latest" -> true.asJson + ) + ) + + val SetupNodeJs: Step.SingleStep = Step.SingleStep( + name = "Setup NodeJs", + uses = Some(`setup-node`), + parameters = Map( + "node-version" -> "16.x".asJson, + "registry-url" -> "https://registry.npmjs.org".asJson + ) + ) + + val GenerateReadme: Step.SingleStep = Step.SingleStep( + name = "Generate Readme", + run = Some(s"sbt ${sbtBuildOptions.mkString(" ")} docs/generateReadme") + ) + + val CheckWebsiteBuildProcess: Step.SingleStep = Step.SingleStep( + name = "Check website build process", + run = Some(s"sbt ${sbtBuildOptions.mkString(" ")} docs/buildWebsite") + ) + + val CheckGithubWorkflow: Step.SingleStep = Step.SingleStep( + name = "Check that site workflow is up to date", + run = Some(s"sbt ${sbtBuildOptions.mkString(" ")} docs/checkGithubWorkflow") + ) + + val PublishToNpmRegistry: Step.SingleStep = + Step.SingleStep( + name = "Publish Docs to NPM Registry", + run = Some(s"sbt ${sbtBuildOptions.mkString(" ")} docs/${versioning.npmCommand}"), + env = Map( + "NODE_AUTH_TOKEN" -> "${{ secrets.NPM_TOKEN }}" + ) + ) + } + + import Steps.* + io.circe.yaml .Printer( preserveOrder = true, @@ -201,28 +262,10 @@ object WebsiteUtils { steps = Seq( Step.StepSequence( Seq( - Step.SingleStep( - name = "Git Checkout", - uses = Some(ActionRef("actions/checkout@v3.2.0")), - parameters = Map("fetch-depth" -> "0".asJson) - ), - Step.SingleStep( - name = "Setup Scala", - uses = Some(ActionRef("actions/setup-java@v3.9.0")), - parameters = Map( - "distribution" -> "temurin".asJson, - "java-version" -> 17.asJson, - "check-latest" -> true.asJson - ) - ), - Step.SingleStep( - name = "Check that site workflow is up to date", - run = Some(s"sbt ${sbtBuildOptions.mkString(" ")} docs/checkGithubWorkflow") - ), - Step.SingleStep( - name = "Check website build process", - run = Some(s"sbt ${sbtBuildOptions.mkString(" ")} docs/buildWebsite") - ) + Checkout, + SetupJava, + CheckGithubWorkflow, + CheckWebsiteBuildProcess ) ) ) @@ -239,35 +282,10 @@ object WebsiteUtils { steps = Seq( Step.StepSequence( Seq( - Step.SingleStep( - name = "Git Checkout", - uses = Some(ActionRef("actions/checkout@v3.2.0")), - parameters = Map("fetch-depth" -> "0".asJson) - ), - Step.SingleStep( - name = "Setup Scala", - uses = Some(ActionRef("actions/setup-java@v3.9.0")), - parameters = Map( - "distribution" -> "temurin".asJson, - "java-version" -> 17.asJson, - "check-latest" -> true.asJson - ) - ), - Step.SingleStep( - name = "Setup NodeJs", - uses = Some(ActionRef("actions/setup-node@v3")), - parameters = Map( - "node-version" -> "16.x".asJson, - "registry-url" -> "https://registry.npmjs.org".asJson - ) - ), - Step.SingleStep( - name = "Publish Docs to NPM Registry", - run = Some(s"sbt ${sbtBuildOptions.mkString(" ")} docs/${versioning.npmCommand}"), - env = Map( - "NODE_AUTH_TOKEN" -> "${{ secrets.NPM_TOKEN }}" - ) - ) + Checkout, + SetupJava, + SetupNodeJs, + PublishToNpmRegistry ) ) ) @@ -279,25 +297,14 @@ object WebsiteUtils { steps = Seq( Step.SingleStep( name = "Git Checkout", - uses = Some(ActionRef("actions/checkout@v3.2.0")), + uses = Some(checkout), parameters = Map( "ref" -> "${{ github.head_ref }}".asJson, "fetch-depth" -> "0".asJson ) ), - Step.SingleStep( - name = "Setup Scala", - uses = Some(ActionRef("actions/setup-java@v3.9.0")), - parameters = Map( - "distribution" -> "temurin".asJson, - "java-version" -> 17.asJson, - "check-latest" -> true.asJson - ) - ), - Step.SingleStep( - name = "Generate Readme", - run = Some(s"sbt ${sbtBuildOptions.mkString(" ")} docs/generateReadme") - ), + SetupJava, + GenerateReadme, Step.SingleStep( name = "Commit Changes", run = Some("""|git config --local user.email "github-actions[bot]@users.noreply.github.com" @@ -327,6 +334,7 @@ object WebsiteUtils { ) ).asJson ) + } def releaseVersion(logger: String => Unit): Option[String] = try "git tag --sort=committerdate".!!.split("\n").filter(_.startsWith("v")).lastOption.map(_.tail)