10000 feat: add a JSON schema including test infrastructure (#82) by Vampire · Pull Request #243 · typesafegithub/github-actions-typing · GitHub
[go: up one dir, main page]

Skip to content

feat: add a JSON schema including test infrastructure (#82) #243

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

Merged
merged 3 commits into from
Jan 29, 2025
Merged
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
21 changes: 19 additions & 2 deletions .github/workflows/build.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,25 @@ workflow(
id = "build",
runsOn = RunnerType.UbuntuLatest,
) {
uses(action = Checkout())
uses(action = GradleBuildAction(arguments = "build"))
uses(
name = "Checkout github-actions-typing",
action = Checkout(
path = "github-actions-typing"
)
)
uses(
name = "Checkout github-actions-typing-catalog",
action = Checkout(
repository = "typesafegithub/github-actions-typing-catalog",
path = "github-actions-typing-catalog"
)
)
uses(
action = GradleBuildAction(
buildRootDirectory = "github-actions-typing",
arguments = "build"
)
)
}

job(
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ jobs:
- 'check_yaml_consistency'
steps:
- id: 'step-0'
name: 'Checkout github-actions-typing'
uses: 'actions/checkout@v4'
with:
path: 'github-actions-typing'
- id: 'step-1'
name: 'Checkout github-actions-typing-catalog'
uses: 'actions/checkout@v4'
with:
repository: 'typesafegithub/github-actions-typing-catalog'
path: 'github-actions-typing-catalog'
- id: 'step-2'
uses: 'gradle/gradle-build-action@v3'
with:
arguments: 'build'
build-root-directory: 'github-actions-typing'
validate-types:
runs-on: 'ubuntu-latest'
needs:
Expand Down
27 changes: 24 additions & 3 deletions .github/workflows/release.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,39 @@ workflow(
id = "release",
runsOn = RunnerType.UbuntuLatest,
) {
uses(action = Checkout())
uses(
name = "Checkout github-actions-typing",
action = Checkout(
path = "github-actions-typing"
)
)
uses(
name = "Checkout github-actions-typing-catalog",
action = Checkout(
repository = "typesafegithub/github-actions-typing-catalog",
path = "github-actions-typing-catalog"
)
)
uses(action = ActionsSetupGradle())
run(command = "./gradlew build")
run(
workingDirectory = "github-actions-typing",
command = "./gradlew build"
)

run(
name = "Regenerate the contents of dist directory",
workingDirectory = "github-actions-typing",
command = """
set -euxo pipefail

rm -rf dist
unzip -qq build/distributions/github-actions-typing.zip -d dist
rm -rf dist/github-actions-typing/bin
""".trimIndent()
)

run(
name = "Configure git",
workingDirectory = "github-actions-typing",
command = """
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
Expand All @@ -66,6 +82,7 @@ workflow(

run(
name = "Commit changes",
workingDirectory = "github-actions-typing",
command = """
git checkout -b $tempBranchName
git add .
Expand All @@ -75,13 +92,15 @@ workflow(

run(
name = "Push commit",
workingDirectory = "github-actions-typing",
command = "git push --set-upstream origin $tempBranchName",
)

val versionExpr = expr { "github.event.inputs.version" }

run(
name = "Create and push a patch version tag",
workingDirectory = "github-actions-typing",
command = """
git tag -a "$versionExpr" -m "Release version $versionExpr"
git push origin "$versionExpr"
Expand All @@ -108,6 +127,7 @@ workflow(

run(
name = "Create or update a major version branch",
workingDirectory = "github-actions-typing",
command = """
git branch -D "$majorVersionExpr" || true
git checkout -b "$majorVersionExpr"
Expand All @@ -117,6 +137,7 @@ workflow(

run(
name = "Delete temp branch",
workingDirectory = "github-actions-typing",
command = "git push origin --delete $tempBranchName"
)
}
Expand Down
44 changes: 30 additions & 14 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,64 @@ jobs:
- 'check_yaml_consistency'
steps:
- id: 'step-0'
name: 'Checkout github-actions-typing'
uses: 'actions/checkout@v4'
with:
path: 'github-actions-typing'
- id: 'step-1'
uses: 'gradle/actions/setup-gradle@v4'
name: 'Checkout github-actions-typing-catalog'
uses: 'actions/checkout@v4'
with:
repository: 'typesafegithub/github-actions-typing-catalog'
path: 'github-actions-typing-catalog'
- id: 'step-2'
run: './gradlew build'
uses: 'gradle/actions/setup-gradle@v4'
- id: 'step-3'
working-directory: 'github-actions-typing'
run: './gradlew build'
- id: 'step-4'
name: 'Regenerate the contents of dist directory'
working-directory: 'github-actions-typing'
run: |-
set -euxo pipefail

rm -rf dist
unzip -qq build/distributions/github-actions-typing.zip -d dist
rm -rf dist/github-actions-typing/bin
- id: 'step-4'
- id: 'step-5'
name: 'Configure git'
working-directory: 'github-actions-typing'
run: |-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
- id: 'step-5'
- id: 'step-6'
name: 'Commit changes'
working-directory: 'github-actions-typing'
run: |-
git checkout -b temp-branch-for-release
git add .
git commit -m "Update dist"
- id: 'step-6'
- id: 'step-7'
name: 'Push commit'
working-directory: 'github-actions-typing'
run: 'git push --set-upstream origin temp-branch-for-release'
- id: 'step-7'
- id: 'step-8'
name: 'Create and push a patch version tag'
working-directory: 'github-actions-typing'
run: |-
git tag -a "${{ github.event.inputs.version }}" -m "Release version ${{ github.event.inputs.version }}"
git push origin "${{ github.event.inputs.version }}"
- id: 'step-8'
- id: 'step-9'
env:
GHWKT_GITHUB_CONTEXT_JSON: '${{ toJSON(github) }}'
run: 'GHWKT_RUN_STEP=''release:step-8'' ''.github/workflows/release.main.kts'''
- id: 'step-9'
run: 'GHWKT_RUN_STEP=''release:step-9'' ''.github/workflows/release.main.kts'''
- id: 'step-10'
name: 'Create or update a major version branch'
working-directory: 'github-actions-typing'
run: |-
git branch -D "${{ steps.step-8.outputs.majorVersion }}" || true
git checkout -b "${{ steps.step-8.outputs.majorVersion }}"
git push origin "${{ steps.step-8.outputs.majorVersion }}" -f
- id: 'step-10'
git branch -D "${{ steps.step-9.outputs.majorVersion }}" || true
git checkout -b "${{ steps.step-9.outputs.majorVersion }}"
git push origin "${{ steps.step-9.outputs.majorVersion }}" -f
- id: 'step-11'
name: 'Delete temp branch'
working-directory: 'github-actions-typing'
run: 'git push origin --delete temp-branch-for-release'
116 changes: 116 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
import org.gradle.api.tasks.PathSensitivity.NAME_ONLY
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.Companion.kotlinNodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.yarn.yarn

plugins {
kotlin("multiplatform") version "2.1.10"
kotlin("plugin.serialization") version "2.1.10"
id("io.kotest.multiplatform") version "6.0.0.M1"
distribution
}

val collectCatalogTypings by tasks.registering(Sync::class) {
from("../github-actions-typing-catalog/typings")
include("**/action-types.yml")
into(layout.buildDirectory.dir("catalog-typings"))
eachFile {
relativePath = RelativePath(
relativePath.isFile,
relativePath
.segments
.joinToString("_")
.replace("_action-types", "")
)
}
includeEmptyDirs = false
}

val collectExternalTypings by tasks.registering(Sync::class) {
mapOf(
"Vampire_setup-wsl_v4.yml" to "Vampire/setup-wsl/refs/heads/v4/action-types.yml",
"Vampire_setup-wsl_master.yml" to "Vampire/setup-wsl/refs/heads/master/action-types.yml",
"typesafegithub_github-actions-typing_v1.yml" to "typesafegithub/github-actions-typing/refs/heads/v1/action-types.yml",
"typesafegithub_github-actions-typing_main.yml" to "typesafegithub/github-actions-typing/refs/heads/main/action-types.yml",
).forEach { (name, location) ->
from(resources.text.fromUri("https://raw.githubusercontent.com/$location")) {
rename { name }
}
}
into(layout.buildDirectory.dir("external-typings"))
}

val schemaFile = file("src/main/schema/github-actions-typing.schema.json")
val goodDir = file("src/test/resources/good-typings")
val badDir = file("src/test/resources/bad-typings")

kotlin {
jvmToolchain(21)
Expand All @@ -17,6 +53,26 @@ kotlin {
val test by testRuns.existing {
executionTask {
useJUnitPlatform()< 10000 /td>
configureInputsForSchemaTest()
systemProperty("schemaFile", schemaFile.absolutePath)
systemProperty("catalogDir", collectCatalogTypings.get().destinationDir.absolutePath)
systemProperty("externalDir", collectExternalTypings.get().destinationDir.absolutePath)
systemProperty("goodDir", goodDir.absolutePath)
systemProperty("badDir", badDir.absolutePath)
}
}
}

js {
useEsModules()
nodejs {
testTask {
configureInputsForSchemaTest()
environment("schemaFile", schemaFile.absolutePath)
environment("catalogDir", collectCatalogTypings.get().destinationDir.absolutePath)
environment("externalDir", collectExternalTypings.get().destinationDir.absolutePath)
environment("goodDir", goodDir.absolutePath)
environment("badDir", badDir.absolutePath)
}
}
}
Expand All @@ -34,12 +90,40 @@ kotlin {
implementation(dependencies.platform("io.kotest:kotest-bom:5.9.1"))
runtimeOnly("io.kotest:kotest-runner-junit5")
implementation("io.kotest:kotest-framework-api")
implementation("io.kotest:kotest-framework-datatest")
implementation("io.kotest:kotest-assertions-core")

implementation("it.krzeminski:snakeyaml-engine-kmp:3.1.0")
implementation("io.github.optimumcode:json-schema-validator:0.3.1")
}
}

jsTest {
dependencies {
implementation(dependencies.platform("io.kotest:kotest-bom:5.9.1"))
implementation("io.kotest:kotest-framework-engine")
implementation("io.kotest:kotest-framework-api")
implementation("io.kotest:kotest-framework-datatest")
implementation("io.kotest:kotest-assertions-core")

implementation(kotlinWrappers.js)
implementation(kotlinWrappers.node)
implementation(kotlinWrappers.ajv)
implementation(kotlinWrappers.yaml)
implementation(kotlinWrappers.prantlf.jsonlint)
}
}
}
}

kotlinNodeJsRootExtension.version = "20.18.1"

// disable the KMP plugin adding custom repositories which is bad practice
// and promotes supply chain attacks
// instead we define the repositories ourselves in the settings script
kotlinNodeJsRootExtension.downloadBaseUrl = null
yarn.downloadBaseUrl = null

distributions {
main {
contents {
Expand All @@ -52,3 +136,35 @@ distributions {
}
}
}

fun AbstractTestTask.configureInputsForSchemaTest() {
inputs
.file(schemaFile)
.withPropertyName("schemaFile")
.normalizeLineEndings()
.withPathSensitivity(NAME_ONLY)

inputs
.files(collectCatalogTypings)
.withPropertyName("catalogDir")
.normalizeLineEndings()
.withPathSensitivity(NAME_ONLY)

inputs
.files(collectExternalTypings)
.withPropertyName("externalDir")
.normalizeLineEndings()
.withPathSensitivity(NAME_ONLY)

inputs
.dir(goodDir)
.withPropertyName("goodDir")
.normalizeLineEndings()
.withPathSensitivity(NAME_ONLY)

inputs
.dir(badDir)
.withPropertyName("badDir")
.normalizeLineEndings()
.withPathSensitivity(NAME_ONLY)
}
Loading
Loading
0