Skip to content

Commit

Permalink
Add workflow to auto-update codegen
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Jul 3, 2024
1 parent a8aa97b commit 78c2e18
Show file tree
Hide file tree
Showing 5 changed files with 1,029 additions and 925 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/code-generation.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Code Generation

on: [pull_request]
on:
pull_request:
schedule:
- cron: '0 0 * * 1' # 00:00 UTC Weekly on Mondays

jobs:
up_to_date:
Expand All @@ -17,18 +20,27 @@ jobs:
distribution: 'temurin'
cache: 'gradle'

- name: Download Latest Spec
# if: github.event_name == 'schedule'
run: ./gradlew :java-codegen:downloadLatestSpec

- name: Run Code Generator
run: ./gradlew clean :java-codegen:run
run: ./gradlew :java-codegen:run

- name: Check Has No Changes
- name: Git Status
id: git_status
shell: bash -eo pipefail {0}
run: |
output=$(git status --porcelain)
if [ -z "$output" ]; then
echo "Clean working directory"
exit 0
echo "clean=true" >> $GITHUB_OUTPUT
else
echo "Dirty working directory"
echo "$output"
exit 1
fi
echo "clean=false" >> $GITHUB_OUTPUT
fi
- name: Fail On Uncommitted Changes
if: github.event_name != 'schedule' && steps.git_status.outputs.clean != 'true'
run: exit 1
11 changes: 10 additions & 1 deletion java-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.github.jk1.license.ProjectData
import com.github.jk1.license.render.ReportRenderer
import de.undercouch.gradle.tasks.download.Download
import java.io.FileWriter

buildscript {
Expand All @@ -32,6 +33,7 @@ plugins {
id("com.github.jk1.dependency-license-report") version "2.8"
id("org.owasp.dependencycheck") version "9.2.0"
id("com.diffplug.spotless") version "6.25.0"
id("de.undercouch.download") version "5.6.0"
}
apply(plugin = "opensearch.repositories")
apply(plugin = "org.owasp.dependencycheck")
Expand Down Expand Up @@ -66,9 +68,16 @@ application {
)
}

val localSpecification = "$projectDir/opensearch-openapi.yaml"

tasks.create<Download>("downloadLatestSpec") {
src("https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml")
dest(localSpecification)
}

tasks.named<JavaExec>("run") {
args = listOf(
"--input", "$projectDir/opensearch-openapi.yaml",
"--input", localSpecification,
"--eclipse-config", "$rootDir/buildSrc/formatterConfig-generated.xml",
"--output", "${project(":java-client").projectDir}/src/generated/java/"
)
Expand Down
Loading

0 comments on commit 78c2e18

Please sign in to comment.