Skip to content

Commit

Permalink
Only run test jobs if the cache restore was successful
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Jan 26, 2023
1 parent 43068d5 commit 1833593
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 314 deletions.
99 changes: 36 additions & 63 deletions .github/workflows/test.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import it.krzeminski.githubactions.actions.vampire.SetupWslV1
import it.krzeminski.githubactions.actions.vampire.SetupWslV1.Distribution
import it.krzeminski.githubactions.domain.CommandStep
import it.krzeminski.githubactions.domain.ExternalActionStepWithOutputs
import it.krzeminski.githubactions.domain.JobOutputs.EMPTY
import it.krzeminski.githubactions.domain.RunnerType
import it.krzeminski.githubactions.domain.RunnerType.WindowsLatest
import it.krzeminski.githubactions.domain.Shell
Expand All @@ -35,6 +36,7 @@ import it.krzeminski.githubactions.domain.triggers.PullRequest
import it.krzeminski.githubactions.domain.triggers.Push
import it.krzeminski.githubactions.domain.triggers.Schedule
import it.krzeminski.githubactions.dsl.JobBuilder
import it.krzeminski.githubactions.dsl.WorkflowBuilder
import it.krzeminski.githubactions.dsl.expressions.expr

val environments = listOf(
Expand Down Expand Up @@ -170,11 +172,34 @@ workflowWithCopyright(
)
}

job(
id = "test_invalid_distribution",
name = """Test "${expr("matrix.distribution.label")}" distribution on ${expr("matrix.environment")}""",
fun WorkflowBuilder.testJob(
id: String,
name: String,
_customArguments: Map<String, Any?> = mapOf(),
block: JobBuilder<EMPTY>.() -> Unit,
) = job(
id = id,
name = name,
needs = listOf(build),
runsOn = RunnerType.Custom(expr("matrix.environment")),
_customArguments = _customArguments
) {
val restoreBuildArtifacts = uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
run(
name = "Fail if cache could not be restored",
condition = "${restoreBuildArtifacts.outputs.cacheHit} == false",
shell = Cmd,
command = "exit 1"
)
block()
}

testJob(
id = "test_invalid_distribution",
name = """Test "${expr("matrix.distribution.label")}" distribution on ${expr("matrix.environment")}""",
_customArguments = mapOf(
"strategy" to mapOf(
"fail-fast" to false,
Expand All @@ -198,10 +223,6 @@ workflowWithCopyright(
)
)
) {
uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
executeActionStep = usesSelf(
action = executeAction,
continueOnError = true
Expand All @@ -213,11 +234,9 @@ workflowWithCopyright(
)
}

job(
testJob(
id = "test_default_distribution",
name = "Test default distribution on ${expr("matrix.environment")}",
needs = listOf(build),
runsOn = RunnerType.Custom(expr("matrix.environment")),
_customArguments = mapOf(
"strategy" to mapOf(
"fail-fast" to false,
Expand All @@ -228,10 +247,6 @@ workflowWithCopyright(
)
)
) {
uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
executeActionStep = usesSelf(
action = SetupWslV1(
update = true
Expand Down Expand Up @@ -260,11 +275,9 @@ workflowWithCopyright(
)
}

job(
testJob(
id = "test",
name = """Test "${expr("matrix.distribution.user-id")}" distribution on ${expr("matrix.environment")}""",
needs = listOf(build),
runsOn = RunnerType.Custom(expr("matrix.environment")),
_customArguments = mapOf(
"strategy" to mapOf(
"fail-fast" to false,
Expand All @@ -275,10 +288,6 @@ workflowWithCopyright(
)
)
) {
uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
executeActionStep = usesSelf(
action = executeAction.copy(
useCache = false
Expand Down Expand Up @@ -464,11 +473,9 @@ workflowWithCopyright(
)
}

job(
testJob(
id = "test_wsl-conf_on_initial_execution",
name = """Test /etc/wsl.conf handling on initial execution for "${expr("matrix.distribution.user-id")}" distribution on ${expr("matrix.environment")}""",
needs = listOf(build),
runsOn = RunnerType.Custom(expr("matrix.environment")),
_customArguments = mapOf(
"strategy" to mapOf(
"fail-fast" to false,
Expand All @@ -479,10 +486,6 @@ workflowWithCopyright(
)
)
) {
uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
executeActionStep = usesSelf(
action = executeAction.copy(
wslConf = """
Expand Down Expand Up @@ -515,11 +518,9 @@ workflowWithCopyright(
)
}

job(
testJob(
id = "test_wsl-conf_on_subsequent_execution",
name = """Test /etc/wsl.conf handling on subsequent execution for "${expr("matrix.distribution.user-id")}" distribution on ${expr("matrix.environment")}""",
needs = listOf(build),
runsOn = RunnerType.Custom(expr("matrix.environment")),
_customArguments = mapOf(
"strategy" to mapOf(
"fail-fast" to false,
Expand All @@ -530,10 +531,6 @@ workflowWithCopyright(
)
)
) {
uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
executeActionStep = usesSelf(
action = executeAction
)
Expand Down Expand Up @@ -587,11 +584,9 @@ workflowWithCopyright(
)
}

job(
testJob(
id = "test_additional_packages",
name = """Test additional packages for "${expr("matrix.distribution.user-id")}" distribution on ${expr("matrix.environment")}""",
needs = listOf(build),
runsOn = RunnerType.Custom(expr("matrix.environment")),
_customArguments = mapOf(
"strategy" to mapOf(
"fail-fast" to false,
Expand All @@ -602,10 +597,6 @@ workflowWithCopyright(
)
)
) {
uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
executeActionStep = usesSelf(
action = executeAction.copy(
additionalPackages = listOf(
Expand All @@ -624,7 +615,7 @@ workflowWithCopyright(
)
}

job(
testJob(
id = "test_multiple_usage_with_different_distributions",
name = """
Test multiple usage with different distributions
Expand All @@ -633,8 +624,6 @@ workflowWithCopyright(
/ "${expr("matrix.distributions.distribution3.user-id")}")
on ${expr("matrix.environment")}
""".trimIndent().replace("\n", " "),
needs = listOf(build),
runsOn = RunnerType.Custom(expr("matrix.environment")),
_customArguments = mapOf(
"strategy" to mapOf(
"fail-fast" to false,
Expand Down Expand Up @@ -676,10 +665,6 @@ workflowWithCopyright(
)
)
) {
uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
usesSelf(
name = "Execute action for ${expr("matrix.distributions.distribution1.user-id")}",
action = SetupWslV1(
Expand Down Expand Up @@ -722,11 +707,9 @@ workflowWithCopyright(
)
}

job(
testJob(
id = "test_multiple_usage_with_same_distribution",
name = """Test multiple usage with "${expr("matrix.distribution.user-id")}" distribution on ${expr("matrix.environment")}""",
needs = listOf(build),
runsOn = RunnerType.Custom(expr("matrix.environment")),
_customArguments = mapOf(
"strategy" to mapOf(
"fail-fast" to false,
Expand All @@ -752,10 +735,6 @@ workflowWithCopyright(
)
)
) {
uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
usesSelf(
action = executeAction.copy(
additionalPackages = listOf("bash")
Expand Down Expand Up @@ -808,11 +787,9 @@ workflowWithCopyright(
)
}

job(
testJob(
id = "test_distribution_specific_wsl_bash_scripts",
name = "Test distribution specific wsl-bash scripts on ${expr("matrix.environment")}",
needs = listOf(build),
runsOn = RunnerType.Custom(expr("matrix.environment")),
_customArguments = mapOf(
"strategy" to mapOf(
"fail-fast" to false,
Expand All @@ -834,10 +811,6 @@ workflowWithCopyright(
)
)
) {
uses(
name = "Restore built artifacts from cache",
action = builtArtifactsCache
)
(1 until distributions.size)
.associateWith {
usesSelf(
Expand Down
Loading

0 comments on commit 1833593

Please sign in to comment.