Skip to content

Commit cc6a179

Browse files
committed
Refer to actions by commit hash
Some organizations have a policy of always referring to GitHub actions by commit hash rather than tag, as tags can be moved without review. This explores what this would look like for `sbt-github-actions`. Of course the main downside would be that updating the hashes creates churn.
1 parent 3705053 commit cc6a179

File tree

5 files changed

+80
-41
lines changed

5 files changed

+80
-41
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@ jobs:
3434

3535
- name: Configure pagefile for Windows
3636
if: contains(runner.os, 'windows')
37-
uses: al-cheb/[email protected]
37+
uses: al-cheb/configure-pagefile-action@a3b6ebd6b634da88790d9c58d4b37a7f4a7b8708 # v1.4
3838
with:
3939
minimum-size: 2GB
4040
maximum-size: 8GB
4141
disk-root: 'C:'
4242

4343
- name: Checkout current branch (full)
44-
uses: actions/checkout@v4
44+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4545
with:
4646
fetch-depth: 0
4747

4848
- name: Setup Java (zulu@8)
4949
if: matrix.java == 'zulu@8'
50-
uses: actions/setup-java@v4
50+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
5151
with:
5252
distribution: zulu
5353
java-version: 8
5454
cache: sbt
5555

5656
- name: Setup GraalVM (graal_graalvm@17)
5757
if: matrix.java == 'graal_graalvm@17'
58-
uses: graalvm/setup-graalvm@v1
58+
uses: graalvm/setup-graalvm@01ed653ac833fe80569f1ef9f25585ba2811baab # v1.3.3
5959
with:
6060
java-version: 17
6161
distribution: graalvm
@@ -65,14 +65,14 @@ jobs:
6565

6666
- name: Setup Java (corretto@17)
6767
if: matrix.java == 'corretto@17'
68-
uses: actions/setup-java@v4
68+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
6969
with:
7070
distribution: corretto
7171
java-version: 17
7272
cache: sbt
7373

7474
- name: Setup sbt
75-
uses: sbt/setup-sbt@v1
75+
uses: sbt/setup-sbt@6c68d2fe8dfbc0a0534d70101baa2e0420e1a506 # v1.1.9
7676

7777
- name: Check that workflows are up to date
7878
shell: bash
@@ -90,7 +90,7 @@ jobs:
9090
run: tar cf targets.tar target project/target
9191

9292
- name: Upload target directories
93-
uses: actions/upload-artifact@v4
93+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
9494
with:
9595
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
9696
path: targets.tar
@@ -112,28 +112,28 @@ jobs:
112112

113113
- name: Configure pagefile for Windows
114114
if: contains(runner.os, 'windows')
115-
uses: al-cheb/[email protected]
115+
uses: al-cheb/configure-pagefile-action@a3b6ebd6b634da88790d9c58d4b37a7f4a7b8708 # v1.4
116116
with:
117117
minimum-size: 2GB
118118
maximum-size: 8GB
119119
disk-root: 'C:'
120120

121121
- name: Checkout current branch (full)
122-
uses: actions/checkout@v4
122+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
123123
with:
124124
fetch-depth: 0
125125

126126
- name: Setup Java (zulu@8)
127127
if: matrix.java == 'zulu@8'
128-
uses: actions/setup-java@v4
128+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
129129
with:
130130
distribution: zulu
131131
java-version: 8
132132
cache: sbt
133133

134134
- name: Setup GraalVM (graal_graalvm@17)
135135
if: matrix.java == 'graal_graalvm@17'
136-
uses: graalvm/setup-graalvm@v1
136+
uses: graalvm/setup-graalvm@01ed653ac833fe80569f1ef9f25585ba2811baab # v1.3.3
137137
with:
138138
java-version: 17
139139
distribution: graalvm
@@ -143,17 +143,17 @@ jobs:
143143

144144
- name: Setup Java (corretto@17)
145145
if: matrix.java == 'corretto@17'
146-
uses: actions/setup-java@v4
146+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
147147
with:
148148
distribution: corretto
149149
java-version: 17
150150
cache: sbt
151151

152152
- name: Setup sbt
153-
uses: sbt/setup-sbt@v1
153+
uses: sbt/setup-sbt@6c68d2fe8dfbc0a0534d70101baa2e0420e1a506 # v1.1.9
154154

155155
- name: Download target directories (2.12.20)
156-
uses: actions/download-artifact@v4
156+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
157157
with:
158158
name: target-${{ matrix.os }}-2.12.20-${{ matrix.java }}
159159

src/main/scala/sbtghactions/GenerativePlugin.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ ${indent(rendered.mkString("\n"), 1)}"""
301301
import use.{ref, params}
302302

303303
val decl = ref match {
304-
case UseRef.Public(owner, repo, ref) =>
305-
s"uses: $owner/$repo@$ref"
304+
case UseRef.Public(owner, repo, rev, ref) =>
305+
s"uses: $owner/$repo@$rev # $ref"
306306

307307
case UseRef.Local(path) =>
308308
val cleaned = if (path.startsWith("./"))
@@ -640,7 +640,8 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
640640
UseRef.Public(
641641
"actions",
642642
"upload-artifact",
643-
"v4"),
643+
"ea165f8d65b6e75b540449e92b4886f43607fa02",
644+
"v4.6.2"),
644645
name = Some(s"Upload target directories"),
645646
params = Map(
646647
"name" -> s"target-$${{ matrix.os }}-$${{ matrix.scala }}-$${{ matrix.java }}",
@@ -661,7 +662,8 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
661662
UseRef.Public(
662663
"actions",
663664
"download-artifact",
664-
"v4"),
665+
"d3f86a106a0bac45b974a628896c90dbdf5c8093",
666+
"v4.3.0"),
665667
name = Some(s"Download target directories ($v)"),
666668
params = Map(
667669
"name" -> s"target-$${{ matrix.os }}-$v-$${{ matrix.java }}"))
@@ -686,7 +688,11 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
686688
val optionalPagefileFix = githubWorkflowWindowsPagefileFix.value.map(pageFileFix =>
687689
WorkflowStep.Use(
688690
name = Some("Configure pagefile for Windows"),
689-
ref = UseRef.Public("al-cheb", "configure-pagefile-action", "v1.4"),
691+
ref = UseRef.Public(
692+
"al-cheb",
693+
"configure-pagefile-action",
694+
"a3b6ebd6b634da88790d9c58d4b37a7f4a7b8708",
695+
"v1.4"),
690696
params = Map(
691697
"minimum-size" -> s"${pageFileFix.minSize}",
692698
"maximum-size" -> s"${pageFileFix.maxSize}"

src/main/scala/sbtghactions/UseRef.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package sbtghactions
1919
sealed trait UseRef extends Product with Serializable
2020

2121
object UseRef {
22-
final case class Public(owner: String, repo: String, ref: String) extends UseRef
22+
final case class Public(owner: String, repo: String, rev: String, ref: String) extends UseRef
2323
final case class Local(path: String) extends UseRef
2424
final case class Docker(image: String, tag: String, host: Option[String] = None) extends UseRef
2525
}

src/main/scala/sbtghactions/WorkflowStep.scala

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,31 @@ object WorkflowStep {
3333
val DefaultSbtStepPreamble: List[String] = List(s"++ $${{ matrix.scala }}")
3434

3535
val CheckoutFull: WorkflowStep = Use(
36-
UseRef.Public("actions", "checkout", "v4"),
36+
UseRef.Public(
37+
"actions",
38+
"checkout",
39+
"11bd71901bbe5b1630ceea73d27597364c9af683",
40+
"v4.2.2"),
3741
name = Some("Checkout current branch (full)"),
3842
params = Map("fetch-depth" -> "0"))
3943

40-
val Checkout: WorkflowStep = Use(UseRef.Public("actions", "checkout", "v4"), name = Some("Checkout current branch (fast)"))
44+
val Checkout: WorkflowStep = Use(
45+
UseRef.Public(
46+
"actions",
47+
"checkout",
48+
"11bd71901bbe5b1630ceea73d27597364c9af683",
49+
"v4.2.2"),
50+
name = Some("Checkout current branch (fast)"))
4151

4252
def SetupJava(versions: List[JavaSpec]): List[WorkflowStep] =
4353
versions map {
4454
case jv @ JavaSpec(JavaSpec.Distribution.GraalVM(Graalvm.Version(graalVersion)), version) =>
4555
WorkflowStep.Use(
46-
UseRef.Public("graalvm", "setup-graalvm", "v1"),
56+
UseRef.Public(
57+
"graalvm",
58+
"setup-graalvm",
59+
"01ed653ac833fe80569f1ef9f25585ba2811baab",
60+
"v1.3.3"),
4761
name = Some(s"Setup GraalVM (${jv.render})"),
4862
cond = Some(s"matrix.java == '${jv.render}'"),
4963
params = ListMap(
@@ -54,7 +68,11 @@ object WorkflowStep {
5468
"cache" -> "sbt"))
5569
case jv @ JavaSpec(JavaSpec.Distribution.GraalVM(Graalvm.Distribution(distribution)), version) =>
5670
WorkflowStep.Use(
57-
UseRef.Public("graalvm", "setup-graalvm", "v1"),
71+
UseRef.Public(
72+
"graalvm",
73+
"setup-graalvm",
74+
"01ed653ac833fe80569f1ef9f25585ba2811baab",
75+
"v1.3.3"),
5876
name = Some(s"Setup GraalVM (${jv.render})"),
5977
cond = Some(s"matrix.java == '${jv.render}'"),
6078
params = ListMap(
@@ -65,7 +83,11 @@ object WorkflowStep {
6583
"cache" -> "sbt"))
6684
case jv @ JavaSpec(dist, version) =>
6785
WorkflowStep.Use(
68-
UseRef.Public("actions", "setup-java", "v4"),
86+
UseRef.Public(
87+
"actions",
88+
"setup-java",
89+
"c5195efecf7bdfc987ee8bae7a71cb8b11521c00",
90+
"v4.7.1"),
6991
name = Some(s"Setup Java (${jv.render})"),
7092
cond = Some(s"matrix.java == '${jv.render}'"),
7193
params = ListMap(
@@ -76,15 +98,24 @@ object WorkflowStep {
7698

7799
def SetupSbt(runnerVersion: Option[String] = None): WorkflowStep =
78100
Use(
79-
ref = UseRef.Public("sbt", "setup-sbt", "v1"),
101+
ref = UseRef.Public(
102+
"sbt",
103+
"setup-sbt",
104+
"6c68d2fe8dfbc0a0534d70101baa2e0420e1a506",
105+
"v1.1.9"),
80106
params = runnerVersion match {
81107
case Some(v) => Map("sbt-runner-version" -> v)
82108
case None => Map()
83109
},
84110
name = Some("Setup sbt"),
85111
)
86112

87-
val Tmate: WorkflowStep = Use(UseRef.Public("mxschmitt", "action-tmate", "v2"), name = Some("Setup tmate session"))
113+
val Tmate: WorkflowStep = Use(
114+
UseRef.Public(
115+
"mxschmitt",
116+
"action-tmate",
117+
"ece3d66d6d54a01594acd0ee2e79d1bfb2df136d",
118+
"v2"), name = Some("Setup tmate session"))
88119

89120
def ComputeVar(name: String, cmd: String): WorkflowStep =
90121
Run(

src/test/scala/sbtghactions/GenerativePluginSpec.scala

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -363,18 +363,19 @@ class GenerativePluginSpec extends Specification {
363363
UseRef.Public(
364364
"repo",
365365
"slug",
366+
"rev",
366367
"v0")),
367368
"",
368369
Nil,
369-
declareShell = true) mustEqual "- uses: repo/slug@v0"
370+
declareShell = true) mustEqual "- uses: repo/slug@rev # v0"
370371
}
371372

372373
"preserve wonky version in Use" in {
373-
compileStep(Use(UseRef.Public("hello", "world", "v4.0.0")), "", Nil, declareShell = true) mustEqual "- uses: hello/[email protected]"
374+
compileStep(Use(UseRef.Public("hello", "world", "rev", "v4.0.0")), "", Nil, declareShell = true) mustEqual "- uses: hello/world@rev # v4.0.0"
374375
}
375376

376377
"drop Use version prefix on anything that doesn't start with a number" in {
377-
compileStep(Use(UseRef.Public("hello", "world", "main")), "", Nil, declareShell = true) mustEqual "- uses: hello/world@main"
378+
compileStep(Use(UseRef.Public("hello", "world", "rev", "main")), "", Nil, declareShell = true) mustEqual "- uses: hello/world@rev # main"
378379
}
379380

380381
"compile sbt using the command provided" in {
@@ -402,8 +403,8 @@ class GenerativePluginSpec extends Specification {
402403
"compile use without parameters" in {
403404
"public" >> {
404405
compileStep(
405-
Use(UseRef.Public("olafurpg", "setup-scala", "v13")),
406-
"") mustEqual "- uses: olafurpg/setup-scala@v13"
406+
Use(UseRef.Public("olafurpg", "setup-scala", "rev", "v13")),
407+
"") mustEqual "- uses: olafurpg/setup-scala@rev # v13"
407408
}
408409

409410
"directory" >> {
@@ -435,8 +436,8 @@ class GenerativePluginSpec extends Specification {
435436

436437
"compile use with two parameters" in {
437438
compileStep(
438-
Use(UseRef.Public("olafurpg", "setup-scala", "v13"), params = Map("abc" -> "def", "cafe" -> "@42")),
439-
"") mustEqual "- uses: olafurpg/setup-scala@v13\n with:\n abc: def\n cafe: '@42'"
439+
Use(UseRef.Public("olafurpg", "setup-scala", "rev", "v13"), params = Map("abc" -> "def", "cafe" -> "@42")),
440+
"") mustEqual "- uses: olafurpg/setup-scala@rev # v13\n with:\n abc: def\n cafe: '@42'"
440441
}
441442

442443
"compile use with two parameters and environment variables" in {
@@ -445,10 +446,11 @@ class GenerativePluginSpec extends Specification {
445446
UseRef.Public(
446447
"derp",
447448
"nope",
449+
"rev",
448450
"v0"),
449451
params = Map("teh" -> "schizzle", "think" -> "positive"),
450452
env = Map("hi" -> "there")),
451-
"") mustEqual "- env:\n hi: there\n uses: derp/nope@v0\n with:\n teh: schizzle\n think: positive"
453+
"") mustEqual "- env:\n hi: there\n uses: derp/nope@rev # v0\n with:\n teh: schizzle\n think: positive"
452454
}
453455

454456
"compile a run step with multiple commands" in {
@@ -516,7 +518,7 @@ class GenerativePluginSpec extends Specification {
516518
- run: echo hello
517519

518520
- name: Checkout current branch (fast)
519-
uses: actions/checkout@v4"""
521+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2"""
520522
}
521523

522524
"compile a job with one step and three oses" in {
@@ -565,15 +567,15 @@ class GenerativePluginSpec extends Specification {
565567
steps:
566568
- name: Setup Java (temurin@17)
567569
if: matrix.java == 'temurin@17'
568-
uses: actions/setup-java@v4
570+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
569571
with:
570572
distribution: temurin
571573
java-version: 17
572574
cache: sbt
573575

574576
- name: Setup GraalVM (graal_22.3.0@11)
575577
if: matrix.java == 'graal_22.3.0@11'
576-
uses: graalvm/setup-graalvm@v1
578+
uses: graalvm/setup-graalvm@01ed653ac833fe80569f1ef9f25585ba2811baab # v1.3.3
577579
with:
578580
version: 22.3.0
579581
java-version: 11
@@ -605,7 +607,7 @@ class GenerativePluginSpec extends Specification {
605607
steps:
606608
- name: Setup GraalVM (graal_graalvm@17)
607609
if: matrix.java == 'graal_graalvm@17'
608-
uses: graalvm/setup-graalvm@v1
610+
uses: graalvm/setup-graalvm@01ed653ac833fe80569f1ef9f25585ba2811baab # v1.3.3
609611
with:
610612
java-version: 17
611613
distribution: graalvm
@@ -777,7 +779,7 @@ class GenerativePluginSpec extends Specification {
777779
- run: echo $${{ matrix.test }}
778780

779781
- name: Checkout current branch (fast)
780-
uses: actions/checkout@v4"""
782+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2"""
781783
}
782784

783785
"compile a job with extra runs-on labels" in {
@@ -1000,7 +1002,7 @@ class GenerativePluginSpec extends Specification {
10001002
- run: echo hello
10011003

10021004
- name: Checkout current branch (fast)
1003-
uses: actions/checkout@v4"""
1005+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2"""
10041006
}
10051007
}
10061008

0 commit comments

Comments
 (0)