Skip to content

Commit

Permalink
feat(ci): periodically check for new action versions and create issues (
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfayard authored Apr 12, 2022
1 parent b8b5122 commit a3a24a3
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/_GenerateWorkflows.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@file:Import("check-if-wrappers-up-to-date.main.kts")
@file:Import("gradle-wrapper-validation.main.kts")
@file:Import("update-gradle-wrapper.main.kts")
@file:Import("actions-versions.main.kts")

import it.krzeminski.githubactions.yaml.writeToFile

Expand All @@ -13,4 +14,5 @@ listOf(
checkIfWrappersUpToDateWorkflow,
gradleWrapperValidationWorkflow,
updateGradleWrapperWorkflow,
checkIfNewActionVersionsWorkflow,
).forEach { it.writeToFile() }
55 changes: 55 additions & 0 deletions .github/workflows/actions-versions.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@file:DependsOn("it.krzeminski:github-actions-kotlin-dsl:0.12.0")

import it.krzeminski.githubactions.actions.CustomAction
import it.krzeminski.githubactions.actions.actions.CheckoutV3
import it.krzeminski.githubactions.actions.actions.SetupJavaV2
import it.krzeminski.githubactions.actions.gradle.GradleBuildActionV2
import it.krzeminski.githubactions.domain.RunnerType.UbuntuLatest
import it.krzeminski.githubactions.domain.triggers.Cron
import it.krzeminski.githubactions.domain.triggers.Schedule
import it.krzeminski.githubactions.domain.triggers.WorkflowDispatch
import it.krzeminski.githubactions.dsl.expr
import it.krzeminski.githubactions.dsl.workflow
import java.nio.file.Paths

val checkIfNewActionVersionsWorkflow = workflow(
name = "Updates available",
on = listOf(
Schedule(listOf(
Cron(dayWeek = "4", hour = "7", minute = "0")
)),
WorkflowDispatch(),
),
sourceFile = Paths.get(".github/workflows/_GenerateWorkflows.main.kts"),
targetFile = Paths.get(".github/workflows/actions-versions.yml"),
) {
job(
id = "updates-available",
runsOn = UbuntuLatest,
) {
uses(CheckoutV3())
uses(
name = "Set up JDK",
action = SetupJavaV2(
javaVersion = "11",
distribution = SetupJavaV2.Distribution.Adopt,
)
)
uses(
name = "Run suggestVersions",
env = linkedMapOf("GITHUB_TOKEN" to expr("secrets.GITHUB_TOKEN")),
action = GradleBuildActionV2(
arguments = "suggestVersions",
)
)
uses(
name = "Create issue",
action = CustomAction(
"peter-evans", "create-issue-from-file", "v4",
inputs = mapOf(
"title" to "Updates available",
"content-filepath" to "wrapper-generator/build/suggestVersions.md",
))
)
}
}
50 changes: 50 additions & 0 deletions .github/workflows/actions-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This file was generated using Kotlin DSL (.github/workflows/_GenerateWorkflows.main.kts).
# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file.
# Generated with https://github.com/krzema12/github-actions-kotlin-dsl

name: Updates available

on:
schedule:
- cron: '0 7 * * 4'
workflow_dispatch:

jobs:
"check_yaml_consistency":
runs-on: "ubuntu-latest"
steps:
- id: step-0
name: Check out
uses: actions/checkout@v3
- id: step-1
name: Execute script
run: rm '.github/workflows/actions-versions.yml' && '.github/workflows/_GenerateWorkflows.main.kts'
- id: step-2
name: Consistency check
run: git diff --exit-code '.github/workflows/actions-versions.yml'
"updates-available":
runs-on: "ubuntu-latest"
needs:
- "check_yaml_consistency"
steps:
- id: step-0
uses: actions/checkout@v3
- id: step-1
name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: 11
distribution: adopt
- id: step-2
name: Run suggestVersions
uses: gradle/gradle-build-action@v2
with:
arguments: suggestVersions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: step-3
name: Create issue
uses: peter-evans/create-issue-from-file@v4
with:
title: Updates available
content-filepath: wrapper-generator/build/suggestVersions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package it.krzeminski.githubactions.wrappergenerator.versions
import it.krzeminski.githubactions.wrappergenerator.domain.ActionCoords
import it.krzeminski.githubactions.wrappergenerator.metadata.prettyPrint
import it.krzeminski.githubactions.wrappergenerator.wrappersToGenerate
import java.io.File

/**
* Suggest newer versions for the wrapper generator
Expand All @@ -19,6 +20,7 @@ import it.krzeminski.githubactions.wrappergenerator.wrappersToGenerate
* ```
*/
fun main() {
var output: String = ""
val githubAuthorization = System.getenv("GITHUB_TOKEN")
?: error(
"""
Expand All @@ -37,9 +39,14 @@ fun main() {
for ((coords, existingVersions) in actionsMap) {
val available = coords.fetchAvailableVersions(githubAuthorization)
suggestNewerVersion(existingVersions, available)?.let { message ->
println("$message for ${coords.prettyPrint}")
output += "$message for ${coords.prettyPrint}\n"
}
}
println(output)
File("build/suggestVersions.md").let { file ->
println("Updated ${file.absolutePath}")
file.writeText(output)
}
}

fun List<GithubTag>.versions(): List<Version> =
Expand Down

0 comments on commit a3a24a3

Please sign in to comment.