Skip to content

Commit e161253

Browse files
committed
Review Feedback Vol. 2
1 parent 2cbfbfc commit e161253

File tree

7 files changed

+67
-19
lines changed

7 files changed

+67
-19
lines changed

.github/workflows/test-script-consuming-jit-bindings.main.do-not-compile.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env kotlin
22
@file:Repository("https://repo.maven.apache.org/maven2/")
33
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.13.0")
4+
@file:DependsOn("io.kotest:kotest-assertions-core:5.9.1")
45

56
@file:Repository("http://localhost:8080")
67

@@ -13,14 +14,21 @@
1314
// Using specific version.
1415
@file:DependsOn("actions:cache:v3.3.3")
1516

17+
// Using version ranges.
18+
@file:DependsOn("gradle:actions__dependency-submission___major:[v3.3.1,v4-alpha)")
19+
@file:DependsOn("gradle:actions__wrapper-validation___minor:[v4.2.1,v4.3-alpha)")
20+
1621
// Always untyped action.
1722
@file:DependsOn("typesafegithub:always-untyped-action-for-tests:v1")
1823

1924
import io.github.typesafegithub.workflows.actions.actions.Cache
2025
import io.github.typesafegithub.workflows.actions.actions.Checkout
2126
import io.github.typesafegithub.workflows.actions.actions.Checkout_Untyped
2227
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
28+
import io.github.typesafegithub.workflows.actions.gradle.ActionsDependencySubmission_Untyped
29+
import io.github.typesafegithub.workflows.actions.gradle.ActionsWrapperValidation
2330
import io.github.typesafegithub.workflows.actions.typesafegithub.AlwaysUntypedActionForTests_Untyped
31+
import io.kotest.matchers.shouldBe
2432

2533
println(Checkout_Untyped(fetchTags_Untyped = "false"))
2634
println(Checkout(fetchTags = false))
@@ -29,5 +37,8 @@ println(AlwaysUntypedActionForTests_Untyped(foobar_Untyped = "baz"))
2937
println(ActionsSetupGradle())
3038
println(Cache(path = listOf("some-path"), key = "some-key"))
3139

40+
ActionsDependencySubmission_Untyped().actionVersion shouldBe "v3"
41+
ActionsWrapperValidation().actionVersion shouldBe "v4.2"
42+
3243
// Ensure that 'copy(...)' method is exposed.
3344
Checkout(fetchTags = false).copy(fetchTags = true)

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/domain/ActionCoords.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ public data class ActionCoords(
66
val owner: String,
77
val name: String,
88
val version: String,
9+
10+
/**
11+
* The version part that is significant when generating the YAML output,
12+
* i.e. whether to write the full version, only the major version or major and minor version.
13+
* This is used to enable usage of Maven ranges without needing to specify a custom version
14+
* each time instantiating an action.
15+
* The value of this property is part of the Maven coordinates as a suffix for the [name] property.
16+
*/
917
val significantVersion: SignificantVersion = FULL,
1018
val path: String? = null,
1119
)

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/domain/SignificantVersion.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
package io.github.typesafegithub.workflows.actionbindinggenerator.domain
22

3+
/**
4+
* The version part that is significant when generating the YAML output.
5+
* This is used to enable usage of Maven ranges without needing to specify a custom version
6+
* each time instantiating an action.
7+
*/
38
public enum class SignificantVersion {
9+
/**
10+
* Only write the major version to the generated YAML.
11+
*/
412
MAJOR,
13+
14+
/**
15+
* Only write the major and minor version to the generated YAML.
16+
*/
517
MINOR,
18+
19+
/**
20+
* Write the full version to the generated YAML.
21+
*/
622
FULL,
723
;
824

docs/user-guide/using-actions.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,35 @@ To add a dependency on an action:
2020
`gradle/actions/setup-gradle@v3`, replace the slashes in the action name with `__`, so in this case it would be
2121
`@file:DependsOn("gradle:actions__setup-gradle:v3")`.
2222

23-
Additionally, the name part can have the suffix `___major` or `___minor`. Without these suffixes if you request
24-
a version `v1.2.3`, the generated YAML will also use exactly `v1.2.3` unless you use a custom version override.
25-
with the `___major` suffix, it would only write `v1` to the generated YAML, with the `___minor` suffix `v1.2`.
26-
27-
This is especially useful when combined with a version range. The problem with using `v1` or `v1.2` is, that for
28-
GitHub actions these are changing tags or changing branches and not static releases. But in the Maven world
29-
a version that does not end in `-SNAPSHOT` is considered immutable and is not expected to change. This means that
30-
if a new version of the action is released that adds a new input, you cannot use it easily as you still have the old
31-
`v1` artifact in your Maven cache and it will not be updated usually, even though the binding server provides a new
32-
binding including the added input.
33-
34-
To mitigate this problem you can for example use a dependency like `gradle/actions/setup-gradle___major@[v3,v4)`.
35-
This will resolve to the latest `v3.x.y` version and thus include any newly added inputs, but still only write `v3`
36-
to the YAML. Without the `___major` suffix or a not semantically matching range like `[v3,v5)` or even `[v3,v4]` you
37-
will get problems with the consistency check as then the YAML output changes as soon as a new version is released.
38-
For a minor version you would accordingly use the `___minor` suffix together with a range like `[v4.0,v4.1)` to get
39-
the latest `v4.0` release if the action in question provides such a tag or branch.
23+
??? tip "Dealing with stale Maven cache, a.k.a. using version ranges"
24+
Additionally, the name part can have the suffix `___major` or `___minor` (three leading underscores).
25+
Without these suffixes if you request a version `v1.2.3`, the generated YAML will also use exactly
26+
`v1.2.3` unless you use a custom version override. With the `___major` suffix, it would only write `v1`
27+
to the generated YAML, with the `___minor` suffix - `v1.2`.
28+
29+
This is especially useful when combined with a version range. The problem with using `v1` or `v1.2` is that for
30+
GitHub Actions, these are changing tags or changing branches and not static releases. In the Maven world,
31+
however, a version that does not end in `-SNAPSHOT` is considered immutable and is not expected to change.
32+
This means that if a new version of the action is released that adds a new input, you cannot use it easily
33+
as you still have the old `v1` artifact in your Maven cache and it will not be updated usually,
34+
even though the binding server provides a new binding including the added input. And even if you remove the
35+
old version from the Maven cache and get a new version from the bindings server, other people might also have
36+
this outdated version in their Maven cache and then fail compilation with your changes.
37+
38+
To mitigate this problem, you can for example use a dependency like
39+
`gradle:actions__setup-gradle___major:[v3,v4)`. This will resolve to the latest `v3.x.y` version and thus
40+
include any newly added inputs, but still only write `v3` to the YAML. Without the `___major` suffix
41+
or a not semantically matching range like `[v3,v5)` or even `[v3,v4]`, you will get problems with the
42+
consistency check as then the YAML output changes as soon as a new version is released. For a minor version
43+
you would accordingly use the `___minor` suffix together with a range like `[v4.0,v4.1)` to get
44+
the latest `v4.0` release if the action in question provides such a tag or branch.
45+
46+
!!! info
47+
If an action maintainer provides pre-releases that follow certain naming conventions as documented in the
48+
[Maven Documentation](https://maven.apache.org/pom.html#Version_Order_Specification), you might need to
49+
adjust the upper bound. For exmple a version `v4.0-beta` is less than `v4` and thus part of the range
50+
`[v3,v4)`. In such a case - or always, to be on the safe side - you might want to change the range to
51+
`[v3,v4-alpha)`, as the `alpha` version is the lowest possible version in Maven semantics.
4052

4153
3. Use the action by importing a class like `io.github.typesafegithub.workflows.actions.actions.Checkout`.
4254

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoords.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fun Parameters.extractActionCoords(extractVersion: Boolean): ActionCoords {
1717
?.let { significantVersionString ->
1818
SignificantVersion
1919
.entries
20-
.find { it.name.lowercase() == significantVersionString }
20+
.find { "$it" == significantVersionString }
2121
} ?: FULL
2222
val nameAndPathParts = nameAndPath.split("__")
2323
val name = nameAndPathParts.first()

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ActionCoordsUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.Signific
55
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.subName
66

77
internal val ActionCoords.mavenName: String get() = "$name${subName.replace("/", "__")}${
8-
significantVersion.takeUnless { it == FULL }?.let { "___${it.name.lowercase()}" } ?: ""
8+
significantVersion.takeUnless { it == FULL }?.let { "___$it" } ?: ""
99
}"

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ theme:
2424
name: Switch to light mode
2525

2626
markdown_extensions:
27+
- pymdownx.details
2728
- pymdownx.magiclink
2829
- pymdownx.inlinehilite
2930
- pymdownx.superfences

0 commit comments

Comments
 (0)