Skip to content

Commit 92fe249

Browse files
author
Matan Keidar
committed
Add GitHub token to checkout step
This commit adds `token` param to the checkout step. The reason for that is to support pushing to GitHub protected branches within CI flow. Updated checkout action to use 'v3'
1 parent 228964c commit 92fe249

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

.github/workflows/ci.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ jobs:
3232
run: git config --global core.autocrlf false
3333

3434
- name: Checkout current branch (full)
35-
uses: actions/checkout@v2
35+
uses: actions/checkout@v3
3636
with:
3737
fetch-depth: 0
38+
token: ${{ secrets.GITHUB_TOKEN }}
3839

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

9798
- name: Checkout current branch (full)
98-
uses: actions/checkout@v2
99+
uses: actions/checkout@v3
99100
with:
100101
fetch-depth: 0
102+
token: ${{ secrets.GITHUB_TOKEN }}
101103

102104
- name: Setup Java (temurin@11)
103105
if: matrix.java == 'temurin@11'

src/main/scala/sbtghactions/GenerativeKeys.scala

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ trait GenerativeKeys {
6363

6464
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 }} })")
6565
lazy val githubWorkflowAddedJobs = settingKey[Seq[WorkflowJob]]("A list of additional jobs to add to the CI workflow (default: [])")
66+
67+
lazy val githubWorkflowToken = settingKey[String]("A token for checkout step (default: $${{ secrets.GITHUB_TOKEN }} )")
6668
}
6769

6870
object GenerativeKeys extends GenerativeKeys

src/main/scala/sbtghactions/GenerativePlugin.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,10 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
504504
githubWorkflowTargetPaths := Paths.None,
505505

506506
githubWorkflowEnv := Map("GITHUB_TOKEN" -> s"$${{ secrets.GITHUB_TOKEN }}"),
507-
githubWorkflowAddedJobs := Seq())
507+
githubWorkflowAddedJobs := Seq(),
508+
509+
githubWorkflowToken := s"$${{ secrets.GITHUB_TOKEN }}"
510+
)
508511

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

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

632635
autoCrlfOpt :::
633-
List(WorkflowStep.CheckoutFull) :::
636+
List(WorkflowStep.CheckoutFull(githubWorkflowToken.value)) :::
634637
WorkflowStep.SetupJava(githubWorkflowJavaVersions.value.toList) :::
635638
githubWorkflowGeneratedCacheSteps.value.toList
636639
},

src/main/scala/sbtghactions/WorkflowStep.scala

+11-5
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ sealed trait WorkflowStep extends Product with Serializable {
2525

2626
object WorkflowStep {
2727

28-
val CheckoutFull: WorkflowStep = Use(
29-
UseRef.Public("actions", "checkout", "v2"),
30-
name = Some("Checkout current branch (full)"),
31-
params = Map("fetch-depth" -> "0"))
28+
def CheckoutFull(token: String): WorkflowStep = {
29+
Use(
30+
UseRef.Public("actions", "checkout", "v3"),
31+
name = Some("Checkout current branch (full)"),
32+
params = Map(
33+
"fetch-depth" -> "0",
34+
"token" -> token
35+
)
36+
)
37+
}
3238

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

3541
def SetupJava(versions: List[JavaSpec]): List[WorkflowStep] =
3642
versions map {

src/test/scala/sbtghactions/GenerativePluginSpec.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ class GenerativePluginSpec extends Specification {
475475
- run: echo hello
476476

477477
- name: Checkout current branch (fast)
478-
uses: actions/checkout@v2"""
478+
uses: actions/checkout@v3"""
479479
}
480480

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

641641
- name: Checkout current branch (fast)
642-
uses: actions/checkout@v2"""
642+
uses: actions/checkout@v3"""
643643
}
644644

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

840840
- name: Checkout current branch (fast)
841-
uses: actions/checkout@v2"""
841+
uses: actions/checkout@v3"""
842842
}
843843
}
844844

0 commit comments

Comments
 (0)