Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudshiftchris committed Jul 16, 2023
1 parent 814774e commit ea736e1
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ workflow(
gradleVersion = "wrapper",
gradleHomeCacheCleanup = true,
gradleHomeCacheIncludes = listOf("jdks", "caches", "notifications"),
arguments = "build publish --info --stacktrace"
arguments = "build --info --stacktrace"
))
}
}.writeToFile()
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/publish.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env kotlin

@file:DependsOn("io.github.typesafegithub:github-workflows-kt:0.47.0")

import io.github.typesafegithub.workflows.actions.actions.CheckoutV3
import io.github.typesafegithub.workflows.actions.gradle.GradleBuildActionV2
import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest
import io.github.typesafegithub.workflows.domain.triggers.PullRequest
import io.github.typesafegithub.workflows.domain.triggers.Push
import io.github.typesafegithub.workflows.dsl.expressions.expr
import io.github.typesafegithub.workflows.dsl.workflow
import io.github.typesafegithub.workflows.yaml.writeToFile

workflow(
name = "Publish Kotlin AWS CDK DSL to Maven Central",
on = listOf(Push(tags = listOf("*"))),
sourceFile = __FILE__.toPath(),
env = linkedMapOf(
"ORG_GRADLE_PROJECT_signingKey" to expr("secrets.SIGNING_KEY"),
"ORG_GRADLE_PROJECT_signingPassword" to expr("secrets.SIGNING_PASSWORD"),
"ORG_GRADLE_PROJECT_sonatypeUsername" to expr("secrets.SONATYPEUSERNAME"),
"ORG_GRADLE_PROJECT_sonatypePassword" to expr("secrets.SONATYPEPASSWORD"),
),
) {
job(id = "build", runsOn = UbuntuLatest) {
uses(name = "checkout", action = CheckoutV3())
uses(name = "build", action = GradleBuildActionV2(
gradleVersion = "wrapper",
gradleHomeCacheCleanup = true,
gradleHomeCacheIncludes = listOf("jdks", "caches", "notifications"),
arguments = "publishToSonatype --info --stacktrace"
))
}
}.writeToFile()

47 changes: 47 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This file was generated using Kotlin DSL (.github/workflows/publish.main.kts).
# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file.
# Generated with https://github.com/typesafegithub/github-workflows-kt

name: 'Publish Kotlin AWS CDK DSL to Maven Central'
on:
push:
tags:
- '*'
env:
ORG_GRADLE_PROJECT_signingKey: '${{ secrets.SIGNING_KEY }}'
ORG_GRADLE_PROJECT_signingPassword: '${{ secrets.SIGNING_PASSWORD }}'
ORG_GRADLE_PROJECT_sonatypeUsername: '${{ secrets.SONATYPEUSERNAME }}'
ORG_GRADLE_PROJECT_sonatypePassword: '${{ secrets.SONATYPEPASSWORD }}'
jobs:
check_yaml_consistency:
name: '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/publish.yaml'' && ''.github/workflows/publish.main.kts'''
- id: 'step-2'
name: 'Consistency check'
run: 'git diff --exit-code ''.github/workflows/publish.yaml'''
build:
runs-on: 'ubuntu-latest'
needs:
- 'check_yaml_consistency'
steps:
- id: 'step-0'
name: 'checkout'
uses: 'actions/checkout@v3'
- id: 'step-1'
name: 'build'
uses: 'gradle/gradle-build-action@v2'
with:
gradle-version: 'wrapper'
gradle-home-cache-includes: |-
jdks
caches
notifications
arguments: 'publishToSonatype --info --stacktrace'
gradle-home-cache-cleanup: 'true'
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cloudshift.awscdkdsl.build

plugins {
`maven-publish`
signing
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])

pom {
name.set("awscdk-dsl-kotlin")
description.set("Kotlin DSL for AWS CDK")
url.set("https://github.com/cloudshiftinc/awscdk-dsl-kotlin")

licenses {
license {
name.set("Apache License, version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}

scm {
connection.set("scm:git:git://github.com/cloudshiftinc/awscdk-dsl-kotlin.git/")
developerConnection.set("scm:git:ssh://github.com:cloudshiftinc/awscdk-dsl-kotlin.git")
url.set("https://github.com/cloudshiftinc/awscdk-dsl-kotlin")
}

developers {
developer {
id.set("cloudshiftchris")
name.set("Chris Lee")
email.set("[email protected]")
}
}
}
}
}
}

signing {
val signingKey : String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications["mavenJava"])
}

10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import cloudshift.awscdkdsl.build.dsl.GenerateDslTask

plugins {
id("cloudshift.awscdkdsl.build.base")
id("io.github.gradle-nexus.publish-plugin") version("2.0.0-rc-1")
}

nexusPublishing {
repositories {
sonatype { //only for users registered in Sonatype after 24 Feb 2021
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}
}

val awscdk: Configuration by configurations.creating
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

plugins {
id("cloudshift.awscdkdsl.build.kotlin-library")
id("cloudshift.awscdkdsl.build.library-publishing")
}


Expand Down
1 change: 1 addition & 0 deletions dsl-extensions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

plugins {
id("cloudshift.awscdkdsl.build.kotlin-library")
id("cloudshift.awscdkdsl.build.library-publishing")
}


Expand Down
2 changes: 2 additions & 0 deletions dsl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("cloudshift.awscdkdsl.build.kotlin-library")
id("cloudshift.awscdkdsl.build.library-publishing")
}

dependencies {
Expand All @@ -13,6 +14,7 @@ dependencies {

tasks.withType<KotlinCompile>().configureEach {
onlyIf {
// don't compile DSL code when in IntelliJ as it's large and takes considerable time
when {
System.getenv("XPC_SERVICE_NAME")?.contains("intellij") ?: false -> false
System.getenv("IDEA_INITIAL_DIRECTORY") != null -> false
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group = cloudshift.awscdk
group = io.cloudshiftdev.awscdk-dsl-kotlin
version=0.1.0-SNAPSHOT

# lots of generated Kotlin drives memory requirement
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
122 changes: 11 additions & 111 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -133,26 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down Expand Up @@ -240,109 +244,5 @@ eval "set -- $(
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
#!/bin/sh
#
# Start of CloudShift Gradle distribution download snippet
#
# This is added into ./gradlew
#

# uncomment for diagnostics
#set -x

#
# CloudShift custom Gradle distribution download
#
# Download custom distribution securely from S3 before executing wrapper (if not already installed)
# The wrapper will complete the installation (unzip, verification, marker file) and then execute the wrapper
#
GRADLE_HOME=$HOME/.gradle
GRADLE_WRAPPER_PROPERTIES_FILE=gradle/wrapper/gradle-wrapper.properties

# extract distribution path from gradle properties
DIST_PATH=$(grep "^distributionPath" <$GRADLE_WRAPPER_PROPERTIES_FILE | cut -d'=' -f2)

# extract distribution URL from gradle properties file (and unescape it - ':' is escaped as '\:' in properties files)
DIST_URL=$(grep "^distributionUrl" <$GRADLE_WRAPPER_PROPERTIES_FILE | cut -d'=' -f2 | sed -e 's/\\//g')

# Distribution ZIP is filename of URL
DIST_ZIP=${DIST_URL##*/}

MANIFEST_FILE="$DIST_ZIP".manifest.json

# Distribution name is ZIP w/o extension
DIST_NAME=${DIST_ZIP%*.zip}

DIST_HASH=$(printf '%s' "$DIST_URL" | $MD5)

case "$( uname )" in
Darwin* ) DIST_HASH=$(printf '%s' "$DIST_URL" | md5) ;;
*) DIST_HASH=$(printf '%s' "$DIST_URL" | md5sum | sed -e 's/\s.*//g') ;;
esac

DIST_BASE="$GRADLE_HOME/$DIST_PATH/$DIST_NAME"
DIST_INST_DIR="$DIST_BASE/$DIST_HASH"
DIST_MARKER_FILE="$DIST_INST_DIR"/"$DIST_ZIP".ok

if case $DIST_NAME in *SNAPSHOT) true;; *) false;; esac; then
# remove SNAPSHOT versions of our Gradle distribution so they'll be downloaded again
# i.e. don't cache SNAPSHOT versions

# remove the expanded distribution and marker file, while retaining downloaded ZIP
# we do this to prevent re-downloading if the ZIP hasn't changed
echo "Removing cached distribution snapshot: ${DIST_NAME}"

# remove expanded distribution
rm -rf "${DIST_INST_DIR:?}/$DIST_NAME" 2>/dev/null || true

# remove marker file
rm -f "$DIST_MARKER_FILE" 2>/dev/null || true
fi

# check if marker file exists; it won't if this distribution is not installed
if [ ! -f "$DIST_MARKER_FILE" ]; then
#
# Distribution not installed; download the zip and let the wrapper install it
#
AWS=aws
if [ "${CI:-false}" = "false" ]; then
# for local builds use aws-vault
AWS="aws-vault exec ${GRADLEW_AWS_PROFILE:-cloudshift-devtools} -- aws"
fi

echo "$DIST_NAME not found; installing from $DIST_URL"
mkdir -p "$DIST_INST_DIR" 2>/dev/null || true
$AWS s3 sync "${DIST_URL%/*}/" "$DIST_INST_DIR" --exclude "*" --include "$DIST_ZIP" --include "$MANIFEST_FILE" --quiet || die "Failed to download Gradle distribution from $DIST_URL"

if [ ! -f "$DIST_INST_DIR"/"$DIST_ZIP" ]; then
die "$DIST_URL not found"
fi

# terminate running Gradle daemons for this distribution as we may have removed/replaced the underlying installation...
pkill -f "$DIST_NAME.*GradleDaemon" || true
fi

# NOTE: due to oddness in the Gradle wrapper code it's challenging to determine the intermediate
# directory name here as it's a convoluted MD5 hash of the URL (treated as a number which omits leading zeros,
# and oddly in base 36). See org.gradle.wrapper.PathAssembler.getHash for the implementation, if you dare...
#
# So instead we create a manifest when the distribution is published and pull the hash from there

# create a symlink from the funky-Gradle-hash dir to our install dir
DIST_URL_HASH=$(jq '.distributionUrlHash' -r <"$DIST_INST_DIR/$MANIFEST_FILE" || die "Manifest file not found")
rm -rf "${DIST_BASE:?}/$DIST_URL_HASH" 2>/dev/null || true
ln -s "$DIST_INST_DIR" "$DIST_BASE/$DIST_URL_HASH" || die "Failed to install Gradle distribution"

# remove symlink on CI to prevent double-caching
if [ "${CI}" = "true" ]; then
"$JAVACMD" "$@"
EXIT=$?
rm -f "${DIST_BASE:?}/$DIST_URL_HASH" 2>/dev/null || true
exit $EXIT
else
exec "$JAVACMD" "$@"
fi

#
# End of CloudShift Gradle distribution download snippet
#
exec "$JAVACMD" "$@"
Loading

0 comments on commit ea736e1

Please sign in to comment.