diff --git a/.github/workflows/build_pr.yml b/.github/workflows/build_pr.yml new file mode 100644 index 0000000..32ce651 --- /dev/null +++ b/.github/workflows/build_pr.yml @@ -0,0 +1,73 @@ +{ + "jobs": { + "build": { + "runs-on": "ubuntu-22.04", + "steps": [ + { + "name": "Setup Java", + "run": "echo \"JAVA_HOME=$JAVA_HOME_17_X64\" >> \"$GITHUB_ENV\"" + }, + { + "with": { + "fetch-depth": "0", + "persist-credentials": "false" + }, + "name": "Checkout", + "uses": "actions/checkout@v4" + }, + { + "name": "Validate Gradle Wrapper", + "uses": "gradle/actions/wrapper-validation@v3" + }, + { + "with": { + "path": "**/.gradle/loom-cache\n**/.gradle/quilt-loom-cache", + "key": "${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}", + "restore-keys": "${{ runner.os }}-gradle-" + }, + "name": "Cache", + "uses": "actions/cache/restore@v4" + }, + { + "with": { + "cache-read-only": true, + "gradle-home-cache-cleanup": true + }, + "name": "Setup Gradle", + "uses": "gradle/actions/setup-gradle@v3" + }, + { + "name": "Build", + "run": "./gradlew build", + "id": "build", + "env": { + "PR_NUMBER": "${{ github.event.pull_request.number }}" + } + }, + { + "name": "Publish", + "run": "./gradlew publish", + "id": "publish", + "env": { + "PR_NUMBER": "${{ github.event.pull_request.number }}" + } + }, + { + "with": { + "name": "artifacts", + "path": "build/repo" + }, + "name": "Archive Publishable Artifacts", + "uses": "actions/upload-artifact@v4" + } + ] + } + }, + "name": "Build PR", + "concurrency": "ci-${{ github.ref }}", + "on": { + "pull_request": { + + } + } +} \ No newline at end of file diff --git a/.github/workflows/publish_pr.yml b/.github/workflows/publish_pr.yml new file mode 100644 index 0000000..414e299 --- /dev/null +++ b/.github/workflows/publish_pr.yml @@ -0,0 +1,56 @@ +{ + "jobs": { + "publish": { + "runs-on": "ubuntu-22.04", + "steps": [ + { + "with": { + "repository": "lukebemish/artifact-sync", + "ref": "refs/heads/main", + "persist-credentials": false + }, + "name": "Checkout Artifact Sync", + "uses": "actions/checkout@v4" + }, + { + "run": "mkdir repo" + }, + { + "with": { + "script": "const pull_requests = ${{ toJSON(github.event.workflow_run.pull_requests) }};\nif (!pull_requests.length) {\n return core.error(\"This workflow doesn't match any pull requests!\");\n}\nlet allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({\n owner: context.repo.owner,\n repo: context.repo.repo,\n run_id: context.payload.workflow_run.id,\n});\nlet matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {\n return artifact.name == \"artifacts\"\n})[0];\nlet download = await github.rest.actions.downloadArtifact({\n owner: context.repo.owner,\n repo: context.repo.repo,\n artifact_id: matchArtifact.id,\n archive_format: 'zip',\n});\nlet fs = require('fs');\nfs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/repo.zip`, Buffer.from(download.data));" + }, + "name": "Download Artifacts", + "uses": "actions/github-script@v7" + }, + { + "name": "Unpack Artifacts", + "run": "unzip repo.zip -d repo" + }, + { + "name": "Publish Artifacts", + "run": "python3 run.py", + "env": { + "MAVEN_USER": "github", + "MAVEN_PASSWORD": "${{ secrets.PR_MAVEN_PASSWORD }}", + "MAVEN_URL": "https://maven.lukebemish.dev/pullrequests/", + "ALLOWED_VERSION": "*-pr${{ github.event.workflow_run.pull_requests[0].number }}", + "ALLOWED_PATHS": "dev/lukebemish/immaculate,dev/lukebemish/immaculate/*,dev/lukebemish/immaculate/wrapper/*" + } + } + ], + "if": "${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}" + } + }, + "name": "Publish PR", + "concurrency": "ci-${{ github.ref }}", + "on": { + "workflow_run": { + "types": [ + "completed" + ], + "workflows": [ + "Build PR" + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4597a9d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,215 @@ +{ + "jobs": { + "build": { + "outputs": { + "version": "${{ steps.record_version_capture_version.outputs.version }}" + }, + "runs-on": "ubuntu-22.04", + "permissions": { + "contents": "write" + }, + "steps": [ + { + "name": "Setup Java", + "run": "echo \"JAVA_HOME=$JAVA_HOME_17_X64\" >> \"$GITHUB_ENV\"" + }, + { + "with": { + "fetch-depth": "0" + }, + "name": "Checkout", + "uses": "actions/checkout@v4" + }, + { + "name": "Validate Gradle Wrapper", + "uses": "gradle/actions/wrapper-validation@v3" + }, + { + "with": { + "path": "**/.gradle/loom-cache\n**/.gradle/quilt-loom-cache", + "key": "${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}", + "restore-keys": "${{ runner.os }}-gradle-" + }, + "name": "Cache", + "uses": "actions/cache@v4" + }, + { + "with": { + "gradle-home-cache-cleanup": true + }, + "name": "Setup Gradle", + "uses": "gradle/actions/setup-gradle@v3" + }, + { + "uses": "fregante/setup-git-user@v2" + }, + { + "name": "Tag Release", + "run": "./gradlew tagRelease", + "id": "tag_release", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}" + } + }, + { + "name": "Build", + "run": "./gradlew build", + "id": "build", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}" + } + }, + { + "run": "git push && git push --tags" + }, + { + "name": "Submit Dependencies", + "uses": "gradle/actions/dependency-submission@v3", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}" + } + }, + { + "name": "Record Version", + "run": "./gradlew recordVersion", + "id": "record_version", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}" + } + }, + { + "name": "Capture Recorded Version", + "run": "echo version=$(cat build/recordVersion.txt) >> \"$GITHUB_OUTPUT\"", + "id": "record_version_capture_version" + } + ] + }, + "publishCentral": { + "needs": [ + "build" + ], + "runs-on": "ubuntu-22.04", + "steps": [ + { + "name": "Setup Java", + "run": "echo \"JAVA_HOME=$JAVA_HOME_17_X64\" >> \"$GITHUB_ENV\"" + }, + { + "with": { + "fetch-depth": "0", + "ref": "refs/tags/${{needs.build.outputs.version}}", + "persist-credentials": "false" + }, + "name": "Checkout", + "uses": "actions/checkout@v4" + }, + { + "name": "Validate Gradle Wrapper", + "uses": "gradle/actions/wrapper-validation@v3" + }, + { + "with": { + "path": "**/.gradle/loom-cache\n**/.gradle/quilt-loom-cache", + "key": "${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}", + "restore-keys": "${{ runner.os }}-gradle-" + }, + "name": "Cache", + "uses": "actions/cache/restore@v4" + }, + { + "with": { + "cache-read-only": true, + "gradle-home-cache-cleanup": true + }, + "name": "Setup Gradle", + "uses": "gradle/actions/setup-gradle@v3" + }, + { + "name": "Publish", + "run": "./gradlew publishCentral closeAndReleaseSonatypeStagingRepository", + "id": "publish", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}", + "GPG_KEY": "${{ secrets.GPG_KEY }}", + "GPG_PASSWORD": "${{ secrets.GPG_PASSWORD }}", + "SONATYPE_PASSWORD": "${{ secrets.SONATYPE_PASSWORD }}", + "SONATYPE_USER": "${{ secrets.SONATYPE_USER }}" + } + } + ] + }, + "publishPlugins": { + "needs": [ + "build" + ], + "runs-on": "ubuntu-22.04", + "steps": [ + { + "name": "Setup Java", + "run": "echo \"JAVA_HOME=$JAVA_HOME_17_X64\" >> \"$GITHUB_ENV\"" + }, + { + "with": { + "fetch-depth": "0", + "ref": "refs/tags/${{needs.build.outputs.version}}", + "persist-credentials": "false" + }, + "name": "Checkout", + "uses": "actions/checkout@v4" + }, + { + "name": "Validate Gradle Wrapper", + "uses": "gradle/actions/wrapper-validation@v3" + }, + { + "with": { + "path": "**/.gradle/loom-cache\n**/.gradle/quilt-loom-cache", + "key": "${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}", + "restore-keys": "${{ runner.os }}-gradle-" + }, + "name": "Cache", + "uses": "actions/cache/restore@v4" + }, + { + "with": { + "cache-read-only": true, + "gradle-home-cache-cleanup": true + }, + "name": "Setup Gradle", + "uses": "gradle/actions/setup-gradle@v3" + }, + { + "name": "Publish Plugins", + "run": "./gradlew publishPlugins", + "id": "publish_plugins", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}", + "GPG_KEY": "${{ secrets.GPG_KEY }}", + "GPG_PASSWORD": "${{ secrets.GPG_PASSWORD }}", + "GRADLE_PUBLISH_KEY": "${{ secrets.GRADLE_PLUGIN_KEY }}", + "GRADLE_PUBLISH_SECRET": "${{ secrets.GRADLE_PLUGIN_SECRET }}" + } + } + ] + } + }, + "name": "Release", + "concurrency": "ci-${{ github.ref }}", + "on": { + "workflow_dispatch": { + + } + } +} \ No newline at end of file diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml new file mode 100644 index 0000000..1d7386e --- /dev/null +++ b/.github/workflows/snapshot.yml @@ -0,0 +1,79 @@ +{ + "jobs": { + "build": { + "runs-on": "ubuntu-22.04", + "steps": [ + { + "name": "Setup Java", + "run": "echo \"JAVA_HOME=$JAVA_HOME_17_X64\" >> \"$GITHUB_ENV\"" + }, + { + "with": { + "fetch-depth": "0", + "persist-credentials": "false" + }, + "name": "Checkout", + "uses": "actions/checkout@v4" + }, + { + "name": "Validate Gradle Wrapper", + "uses": "gradle/actions/wrapper-validation@v3" + }, + { + "with": { + "path": "**/.gradle/loom-cache\n**/.gradle/quilt-loom-cache", + "key": "${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}", + "restore-keys": "${{ runner.os }}-gradle-" + }, + "name": "Cache", + "uses": "actions/cache@v4" + }, + { + "with": { + "gradle-home-cache-cleanup": true + }, + "name": "Setup Gradle", + "uses": "gradle/actions/setup-gradle@v3" + }, + { + "name": "Build", + "run": "./gradlew build", + "id": "build", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}", + "SNAPSHOT_MAVEN_PASSWORD": "${{ secrets.SNAPSHOT_MAVEN_PASSWORD }}", + "SNAPSHOT_MAVEN_USER": "github", + "SNAPSHOT_MAVEN_URL": "https://maven.lukebemish.dev/snapshots/" + } + }, + { + "name": "Publish", + "run": "./gradlew publish", + "id": "publish", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}", + "SNAPSHOT_MAVEN_PASSWORD": "${{ secrets.SNAPSHOT_MAVEN_PASSWORD }}", + "SNAPSHOT_MAVEN_USER": "github", + "SNAPSHOT_MAVEN_URL": "https://maven.lukebemish.dev/snapshots/" + } + } + ] + } + }, + "name": "Snapshot", + "concurrency": "ci-${{ github.ref }}", + "on": { + "workflow_dispatch": { + + }, + "push": { + "branches": [ + "main" + ] + } + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index f1889e7..83240d0 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ import org.gradle.api.attributes.plugin.GradlePluginApiVersion plugins { id 'java-gradle-plugin' + alias cLibs.plugins.gradlepublish } ['apiElements', 'runtimeElements'].each { @@ -22,10 +23,16 @@ dependencies { } gradlePlugin { + website = 'https://github.com/lukebemishprojects/Immaculate' + vcsUrl = 'https://github.com/lukebemishprojects/Immaculate.git' + plugins { immaculatePlugin { id = 'dev.lukebemish.immaculate' implementationClass = 'dev.lukebemish.immaculate.ImmaculatePlugin' + displayName = 'Immaculate' + description = 'A plugin for applying various code formatting' + tags.addAll(['format', 'style']) } } } @@ -41,3 +48,74 @@ jar { tasks.named('wrapper', Wrapper) { distributionType = Wrapper.DistributionType.ALL } + +managedVersioning { + gitHubActions { + release { + prettyName = 'Release' + workflowDispatch = true + gradleJob { + name.set 'build' + buildCache() + setupGitUser() + readOnly = false + gradlew 'Tag Release', 'tagRelease' + gradlew 'Build', 'build' + push() + dependencySubmission() + recordVersion 'Record Version', 'version' + } + gradleJob { + name.set 'publishCentral' + buildCache() + needs.add('build') + gradlew 'Publish', 'publishCentral', 'closeAndReleaseSonatypeStagingRepository' + tag.set('${{needs.build.outputs.version}}') + sign() + mavenCentral() + } + gradleJob { + name.set 'publishPlugins' + buildCache() + needs.add('build') + gradlew 'Publish Plugins', 'publishPlugins' + tag.set('${{needs.build.outputs.version}}') + sign() + pluginPortal() + } + } + snapshot { + prettyName.set 'Snapshot' + workflowDispatch.set(true) + onBranches.add 'main' + gradleJob { + name.set 'build' + buildCache() + cacheReadOnly = false + gradlew 'Build', 'build' + gradlew 'Publish', 'publish' + mavenSnapshot('github') + } + } + build_pr { + prettyName.set 'Build PR' + pullRequest.set(true) + gradleJob { + name.set 'build' + gradlew 'Build', 'build' + gradlew 'Publish', 'publish' + pullRequestArtifact() + } + } + publish_pr { + prettyName.set 'Publish PR' + publishPullRequestAction( + 'github', + "dev/lukebemish/immaculate,dev/lukebemish/immaculate/*,dev/lukebemish/immaculate/wrapper/*", + 'Build PR' + ) + } + } +} + +managedVersioning.publishing.mavenCentral() diff --git a/settings.gradle b/settings.gradle index f8fa2b3..a8d5f29 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,6 +16,7 @@ gradle.lifecycle.beforeProject { apply plugin: 'dev.lukebemish.managedversioning' apply plugin: 'java-library' apply plugin: 'maven-publish' + apply plugin: 'signing' managedVersioning { versionFile.set rootProject.isolated.projectDirectory.file('version.properties') @@ -24,12 +25,23 @@ gradle.lifecycle.beforeProject { } managedVersioning.apply() - - java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + managedVersioning.publishing.mavenSnapshot(publishing) + managedVersioning.publishing.mavenStaging(publishing) + managedVersioning.publishing.mavenPullRequest(publishing) + + java { + toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + withSourcesJar() + withJavadocJar() + } repositories { mavenCentral() } + + tasks.register('publishCentral') { + group = 'publishing' + } } rootProject.name = 'immaculate' diff --git a/wrapper/build.gradle b/wrapper/build.gradle new file mode 100644 index 0000000..4483b8e --- /dev/null +++ b/wrapper/build.gradle @@ -0,0 +1,17 @@ +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + managedVersioning.publishing.sign(signing, it) + managedVersioning.publishing.pom(it, 'Immaculate', 'BSD-3-Clause') + pom { + name = 'Immaculate -- Wrapper' + description = 'A wrapper for Immaculate to call external tools' + } + } + } +} + +tasks.named('publishCentral') { + dependsOn tasks.publish +} diff --git a/wrapper/eclipse-jdt/build.gradle b/wrapper/eclipse-jdt/build.gradle index 2ab694d..174127c 100644 --- a/wrapper/eclipse-jdt/build.gradle +++ b/wrapper/eclipse-jdt/build.gradle @@ -2,3 +2,21 @@ dependencies { compileOnly 'org.eclipse.jdt:org.eclipse.jdt.core:3.38.0' implementation project(':wrapper') } + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + managedVersioning.publishing.sign(signing, it) + managedVersioning.publishing.pom(it, 'Immaculate', 'BSD-3-Clause') + pom { + name = 'Immaculate -- Eclipse JDT Wrapper' + description = 'A wrapper around the Eclipse JDT formatter' + } + } + } +} + +tasks.named('publishCentral') { + dependsOn tasks.publish +} diff --git a/wrapper/google-java-format/build.gradle b/wrapper/google-java-format/build.gradle index 6b17a4c..83e7faf 100644 --- a/wrapper/google-java-format/build.gradle +++ b/wrapper/google-java-format/build.gradle @@ -2,3 +2,21 @@ dependencies { compileOnly 'com.google.googlejavaformat:google-java-format:1.22.0' implementation project(':wrapper') } + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + managedVersioning.publishing.sign(signing, it) + managedVersioning.publishing.pom(it, 'Immaculate', 'BSD-3-Clause') + pom { + name = 'Immaculate -- Google Java Format Wrapper' + description = 'A wrapper around the Google java formatter' + } + } + } +} + +tasks.named('publishCentral') { + dependsOn tasks.publish +}