Skip to content

Add GitHub token to checkout step #112

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ jobs:
run: git config --global core.autocrlf false

- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down Expand Up @@ -95,9 +96,10 @@ jobs:
run: git config --global core.autocrlf false

- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/sbtghactions/GenerativeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ trait GenerativeKeys {

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: [])")

lazy val githubWorkflowToken = settingKey[String]("A token for checkout step (default: $${{ secrets.GITHUB_TOKEN }} )")
}

object GenerativeKeys extends GenerativeKeys
7 changes: 5 additions & 2 deletions src/main/scala/sbtghactions/GenerativePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
githubWorkflowTargetPaths := Paths.None,

githubWorkflowEnv := Map("GITHUB_TOKEN" -> s"$${{ secrets.GITHUB_TOKEN }}"),
githubWorkflowAddedJobs := Seq())
githubWorkflowAddedJobs := Seq(),

githubWorkflowToken := s"$${{ secrets.GITHUB_TOKEN }}"
)

private lazy val internalTargetAggregation = settingKey[Seq[File]]("Aggregates target directories from all subprojects")

Expand Down Expand Up @@ -630,7 +633,7 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
}

autoCrlfOpt :::
List(WorkflowStep.CheckoutFull) :::
List(WorkflowStep.CheckoutFull(githubWorkflowToken.value)) :::
WorkflowStep.SetupJava(githubWorkflowJavaVersions.value.toList) :::
githubWorkflowGeneratedCacheSteps.value.toList
},
Expand Down
16 changes: 11 additions & 5 deletions src/main/scala/sbtghactions/WorkflowStep.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ sealed trait WorkflowStep extends Product with Serializable {

object WorkflowStep {

val CheckoutFull: WorkflowStep = Use(
UseRef.Public("actions", "checkout", "v2"),
name = Some("Checkout current branch (full)"),
params = Map("fetch-depth" -> "0"))
def CheckoutFull(token: String): WorkflowStep = {
Use(
UseRef.Public("actions", "checkout", "v3"),
name = Some("Checkout current branch (full)"),
params = Map(
"fetch-depth" -> "0",
"token" -> token
)
)
}

val Checkout: WorkflowStep = Use(UseRef.Public("actions", "checkout", "v2"), name = Some("Checkout current branch (fast)"))
val Checkout: WorkflowStep = Use(UseRef.Public("actions", "checkout", "v3"), name = Some("Checkout current branch (fast)"))

def SetupJava(versions: List[JavaSpec]): List[WorkflowStep] =
versions map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down Expand Up @@ -94,9 +95,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down
6 changes: 4 additions & 2 deletions src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down Expand Up @@ -77,9 +78,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down Expand Up @@ -76,9 +77,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down Expand Up @@ -93,9 +94,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down Expand Up @@ -78,9 +79,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/sbtghactions/GenerativePluginSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ class GenerativePluginSpec extends Specification {
- run: echo hello

- name: Checkout current branch (fast)
uses: actions/checkout@v2"""
uses: actions/checkout@v3"""
}

"compile a job with one step and three oses" in {
Expand Down Expand Up @@ -639,7 +639,7 @@ class GenerativePluginSpec extends Specification {
- run: echo $${{ matrix.test }}

- name: Checkout current branch (fast)
uses: actions/checkout@v2"""
uses: actions/checkout@v3"""
}

"compile a job with extra runs-on labels" in {
Expand Down Expand Up @@ -838,7 +838,7 @@ class GenerativePluginSpec extends Specification {
- run: echo hello

- name: Checkout current branch (fast)
uses: actions/checkout@v2"""
uses: actions/checkout@v3"""
}
}

Expand Down