From 33be80eb21c58fdb6fc8f356e9d8709e32ee22af Mon Sep 17 00:00:00 2001 From: Thisaru Guruge Date: Tue, 28 Nov 2023 16:53:42 +0530 Subject: [PATCH 1/4] [Automated] Update the native jar versions --- copybook-tool/Ballerina.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/copybook-tool/Ballerina.toml b/copybook-tool/Ballerina.toml index 85f22d7..2226548 100644 --- a/copybook-tool/Ballerina.toml +++ b/copybook-tool/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "copybook" -version = "0.1.0" +version = "0.1.1" authors = ["Ballerina"] keywords = ["copybook", "copybook tool"] license = ["Apache-2.0"] From de4d01e4027fc2b923e14f34723cf3dd68336eae Mon Sep 17 00:00:00 2001 From: Thisaru Guruge Date: Mon, 20 May 2024 16:52:06 +0530 Subject: [PATCH 2/4] Update build and workflow scripts --- .../workflows/build-timestamped-master.yml | 36 +++++++ .github/workflows/central-publish.yml | 86 +++++++++++++++++ .github/workflows/publish-release.yml | 96 ++++++------------- .github/workflows/pull-request.yml | 8 +- build.gradle | 58 ++++------- copybook-cli/build.gradle | 2 +- copybook-tool/BalTool.toml | 2 +- copybook-tool/build.gradle | 16 +++- settings.gradle | 15 ++- 9 files changed, 205 insertions(+), 114 deletions(-) create mode 100644 .github/workflows/build-timestamped-master.yml create mode 100644 .github/workflows/central-publish.yml diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml new file mode 100644 index 0000000..27b6db1 --- /dev/null +++ b/.github/workflows/build-timestamped-master.yml @@ -0,0 +1,36 @@ +name: Publish timestamp build +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + if: github.repository_owner == 'ballerina-platform' + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: 17.0.7 + - name: Change to Timestamped Version + run: | + startTime=$(TZ="Asia/Kolkata" date +'%Y%m%d-%H%M00') + latestCommit=$(git log -n 1 --pretty=format:"%h") + VERSION=$((grep -w 'version' | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev) + updatedVersion=$VERSION-$startTime-$latestCommit + echo $updatedVersion + sed -i "s/version=\(.*\)/version=$updatedVersion/g" gradle.properties + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + env: + packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} + packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} + run: | + ./gradlew clean build publish codeCoverageReport --stacktrace --scan --console=plain + - name: Generate CodeCov Report + uses: codecov/codecov-action@v4 diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml new file mode 100644 index 0000000..165f4c2 --- /dev/null +++ b/.github/workflows/central-publish.yml @@ -0,0 +1,86 @@ +name: Central Publish + +on: + workflow_dispatch: + inputs: + environment: + type: choice + description: Select environment + required: true + options: + - CENTRAL + - DEV CENTRAL + - STAGE CENTRAL + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 17 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: | + sed -i 's/version=\(.*\)-SNAPSHOT/version=\1/g' gradle.properties + ./gradlew clean build + env: + packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} + packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} + + - name: Build the final Copybook tools package using Ballerina + uses: ballerina-platform/ballerina-action/@2201.8.0 + with: + args: pack ./copybook-tool + env: + JAVA_HOME: /usr/lib/jvm/default-jvm + + - name: Ballerina Central Push + if: ${{ inputs.environment == 'CENTRAL' }} + uses: ballerina-platform/ballerina-action/@2201.8.0 + with: + args: push + env: + WORKING_DIR: ./copybook-tool + BALLERINA_DEV_CENTRAL: false + BALLERINA_STAGE_CENTRAL: false + packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} + packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} + JAVA_HOME: /usr/lib/jvm/default-jvm + BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} + + - name: Ballerina Central Stage Push + if: ${{ inputs.environment == 'STAGE CENTRAL' }} + uses: ballerina-platform/ballerina-action/@2201.8.0 + with: + args: push + env: + WORKING_DIR: ./copybook-tool + BALLERINA_DEV_CENTRAL: false + BALLERINA_STAGE_CENTRAL: true + packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} + packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} + JAVA_HOME: /usr/lib/jvm/default-jvm + BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }} + + - name: Ballerina Central Dev Push + if: ${{ inputs.environment == 'DEV CENTRAL' }} + uses: ballerina-platform/ballerina-action/@2201.8.0 + with: + args: push + env: + WORKING_DIR: ./copybook-tool + BALLERINA_DEV_CENTRAL: true + BALLERINA_STAGE_CENTRAL: false + packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} + packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} + JAVA_HOME: /usr/lib/jvm/default-jvm + BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 165f4c2..75472f2 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,86 +1,48 @@ -name: Central Publish +name: Publish release on: workflow_dispatch: - inputs: - environment: - type: choice - description: Select environment - required: true - options: - - CENTRAL - - DEV CENTRAL - - STAGE CENTRAL jobs: - build: + publish-release: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v3 - - name: Set up JDK 17 uses: actions/setup-java@v3 with: - distribution: 'temurin' + distribution: 'adopt' java-version: 17 - + - name: Set version env variable + run: echo "VERSION=$((grep -w "version" | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev)" >> $GITHUB_ENV + - name: Pre release dependency version update + env: + GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} + run: | + echo "Version: ${VERSION}" + git config user.name ${{ secrets.BALLERINA_BOT_USERNAME }} + git config user.email ${{ secrets.BALLERINA_BOT_EMAIL }} + git checkout -b release-${VERSION} + sed -i 's/ballerinaLangVersion=\(.*\)-SNAPSHOT/ballerinaLangVersion=\1/g' gradle.properties + sed -i 's/ballerinaLangVersion=\(.*\)-[0-9]\{8\}-[0-9]\{6\}-.*$/ballerinaLangVersion=\1/g' gradle.properties + sed -i 's/stdlib\(.*\)=\(.*\)-SNAPSHOT/stdlib\1=\2/g' gradle.properties + sed -i 's/stdlib\(.*\)=\(.*\)-[0-9]\{8\}-[0-9]\{6\}-.*$/stdlib\1=\2/g' gradle.properties + git add gradle.properties + git commit -m "Move dependencies to stable version" || echo "No changes to commit" - name: Grant execute permission for gradlew run: chmod +x gradlew - - - name: Build with Gradle - run: | - sed -i 's/version=\(.*\)-SNAPSHOT/version=\1/g' gradle.properties - ./gradlew clean build - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - - - name: Build the final Copybook tools package using Ballerina - uses: ballerina-platform/ballerina-action/@2201.8.0 - with: - args: pack ./copybook-tool - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - - - name: Ballerina Central Push - if: ${{ inputs.environment == 'CENTRAL' }} - uses: ballerina-platform/ballerina-action/@2201.8.0 - with: - args: push + - name: Publish artifact env: - WORKING_DIR: ./copybook-tool - BALLERINA_DEV_CENTRAL: false - BALLERINA_STAGE_CENTRAL: false - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_HOME: /usr/lib/jvm/default-jvm + GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} - - - name: Ballerina Central Stage Push - if: ${{ inputs.environment == 'STAGE CENTRAL' }} - uses: ballerina-platform/ballerina-action/@2201.8.0 - with: - args: push - env: - WORKING_DIR: ./copybook-tool - BALLERINA_DEV_CENTRAL: false - BALLERINA_STAGE_CENTRAL: true packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_HOME: /usr/lib/jvm/default-jvm - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }} - - - name: Ballerina Central Dev Push - if: ${{ inputs.environment == 'DEV CENTRAL' }} - uses: ballerina-platform/ballerina-action/@2201.8.0 - with: - args: push + run: | + ./gradlew release -Prelease.useAutomaticVersion=true + ./gradlew -Pversion=${VERSION} publish -x test -PpublishToCentral=true + - name: GitHub Release and Release Sync PR env: - WORKING_DIR: ./copybook-tool - BALLERINA_DEV_CENTRAL: true - BALLERINA_STAGE_CENTRAL: false - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_HOME: /usr/lib/jvm/default-jvm - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} + run: | + gh release create v$VERSION --title "copybook-tools-v$VERSION" + gh pr create --base main --title "[Automated] Sync main after $VERSION release" --body "Sync main after $VERSION release" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 4e357f4..463db85 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -19,11 +19,10 @@ jobs: env: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} - WORKING_DIR: ./copybook-cli run: | - ./gradlew build --stacktrace --console=plain + ./gradlew build codeCoverageReport --stacktrace --scan --console=plain --no-daemon - name: Generate Codecov Report - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v4 windows-build: @@ -40,6 +39,5 @@ jobs: env: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} - WORKING_DIR: ./copybook-cli JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 - run: ./gradlew.bat build --stacktrace --scan --console=plain + run: ./gradlew.bat build -Pdisable=invalid_permission --stacktrace --scan --console=plain --no-daemon diff --git a/build.gradle b/build.gradle index f553f07..0980b07 100644 --- a/build.gradle +++ b/build.gradle @@ -16,10 +16,17 @@ * under the License. */ +plugins { + id 'com.github.spotbugs' + id 'de.undercouch.download' + id 'net.researchgate.release' + id 'jacoco' +} + allprojects { - group = 'io.ballerina' + group = project.group version = project.version - apply plugin: 'checkstyle' + apply plugin: 'maven-publish' apply plugin: 'java-library' apply plugin: 'jacoco' @@ -47,44 +54,21 @@ allprojects { } } -def stripBallerinaExtensionVersion(String extVersion) { - if (extVersion.matches(project.ext.timestampedVersionRegex)) { - def splitVersion = extVersion.split('-') - if (splitVersion.length > 3) { - def strippedValues = splitVersion[0..-4] - return strippedValues.join('-') - } else { - return extVersion - } - } else { - return extVersion.replace("${project.ext.snapshotVersion}", "") - } +build { + dependsOn(":copybook-cli:build") + dependsOn(":copybook-tool:build") } -tasks.register('codeCoverageReport', JacocoReport) { - dependsOn = subprojects.test - - executionData fileTree(project.rootDir.absolutePath).include("**/build/coverage-reports/*.exec") +def moduleVersion = project.version.replace("-SNAPSHOT", "") - subprojects.each { - sourceSets it.sourceSets.main - } - reports { - xml.required = true - html.required = true - csv.required = true - xml.destination(new File("${buildDir}/reports/jacoco/report.xml")) - html.destination(new File("${buildDir}/reports/jacoco/report.html")) - csv.destination(new File("${buildDir}/reports/jacoco/report.csv")) - } - - onlyIf = { - true - } -} +release { + buildTasks = ['build'] + failOnSnapshotDependencies = true + versionPropertyFile = 'gradle.properties' + tagTemplate = 'v${version}' -subprojects { - configurations { - ballerinaStdLibs + git { + requireBranch = "release-${moduleVersion}" + pushToRemote = 'origin' } } diff --git a/copybook-cli/build.gradle b/copybook-cli/build.gradle index e92599a..d063114 100644 --- a/copybook-cli/build.gradle +++ b/copybook-cli/build.gradle @@ -20,6 +20,7 @@ plugins{ id 'java-library' id 'checkstyle' id 'com.github.spotbugs' + id 'jacoco' } dependencies { @@ -69,7 +70,6 @@ jacocoTestReport { additionalClassDirs(classFiles) reports { xml.required = true - html.required = true } } diff --git a/copybook-tool/BalTool.toml b/copybook-tool/BalTool.toml index 7222e77..4ef86e1 100644 --- a/copybook-tool/BalTool.toml +++ b/copybook-tool/BalTool.toml @@ -2,7 +2,7 @@ id = "copybook" [[dependency]] -path = "build/libs/copybook-cli-0.1.0-SNAPSHOT.jar" +path = "build/libs/copybook-cli-0.1.1-SNAPSHOT.jar" [[dependency]] path = "build/libs/antlr4-runtime-4.13.1.jar" diff --git a/copybook-tool/build.gradle b/copybook-tool/build.gradle index 205b46b..f436f38 100644 --- a/copybook-tool/build.gradle +++ b/copybook-tool/build.gradle @@ -18,14 +18,26 @@ import org.apache.tools.ant.taskdefs.condition.Os description = 'Ballerina - Copybook tool package' -def packageName = "copybook" -def packageOrg = "ballerina" def tomlVersion = stripBallerinaExtensionVersion("${project.version}") def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/package/Ballerina.toml") def balToolTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/package/BalTool.toml") def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") def balToolTomlFile = new File("$project.projectDir/BalTool.toml") +def stripBallerinaExtensionVersion(String extVersion) { + if (extVersion.matches(project.ext.timestampedVersionRegex)) { + def splitVersion = extVersion.split('-') + if (splitVersion.length > 3) { + def strippedValues = splitVersion[0..-4] + return strippedValues.join('-') + } else { + return extVersion + } + } else { + return extVersion.replace("${project.ext.snapshotVersion}", "") + } +} + tasks.register('updateTomlFiles') { doLast { def newConfig = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) diff --git a/settings.gradle b/settings.gradle index d7ba7df..4018a9b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,9 +23,22 @@ pluginManagement { id "de.undercouch.download" version "${downloadPluginVersion}" } } + +plugins { + id "com.gradle.enterprise" version "3.13.2" +} + rootProject.name = 'copybook-tools' -include('copybook-cli') + include('checkstyle') +include('copybook-cli') include('copybook-tool') project(':checkstyle').projectDir = file("build-config${File.separator}checkstyle") + +gradleEnterprise { + buildScan { + termsOfServiceUrl = 'https://gradle.com/terms-of-service' + termsOfServiceAgree = 'yes' + } +} From 7adf7e29932339645d5e99dd33141fe4dd2700a4 Mon Sep 17 00:00:00 2001 From: Thisaru Guruge Date: Mon, 20 May 2024 16:59:20 +0530 Subject: [PATCH 3/4] Remove unncessary gradle task --- .github/workflows/build-timestamped-master.yml | 2 +- .github/workflows/pull-request.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 27b6db1..f1757a5 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -31,6 +31,6 @@ jobs: packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} run: | - ./gradlew clean build publish codeCoverageReport --stacktrace --scan --console=plain + ./gradlew clean build publish --stacktrace --scan --console=plain - name: Generate CodeCov Report uses: codecov/codecov-action@v4 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 463db85..9442087 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -20,7 +20,7 @@ jobs: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} run: | - ./gradlew build codeCoverageReport --stacktrace --scan --console=plain --no-daemon + ./gradlew build --stacktrace --scan --console=plain --no-daemon - name: Generate Codecov Report uses: codecov/codecov-action@v4 From 6126eb5e75c6cf0388778f1f95fabe6b823c7ab5 Mon Sep 17 00:00:00 2001 From: Thisaru Guruge Date: Mon, 20 May 2024 17:13:55 +0530 Subject: [PATCH 4/4] Change the JDK to temurin --- .github/workflows/build-timestamped-master.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/pull-request.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index f1757a5..d4aa0f2 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -14,7 +14,7 @@ jobs: - name: Set up JDK 17 uses: actions/setup-java@v3 with: - distribution: 'adopt' + distribution: 'temurin' java-version: 17.0.7 - name: Change to Timestamped Version run: | diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 75472f2..7fa0fe9 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -11,7 +11,7 @@ jobs: - name: Set up JDK 17 uses: actions/setup-java@v3 with: - distribution: 'adopt' + distribution: 'temurin' java-version: 17 - name: Set version env variable run: echo "VERSION=$((grep -w "version" | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev)" >> $GITHUB_ENV diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9442087..b9da182 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -13,7 +13,7 @@ jobs: - name: Set up JDK 17 uses: actions/setup-java@v3 with: - distribution: 'adopt' + distribution: 'temurin' java-version: 17.0.7 - name: Build with Gradle env: @@ -33,7 +33,7 @@ jobs: - name: Set up JDK 17 uses: actions/setup-java@v3 with: - distribution: 'adopt' + distribution: 'temurin' java-version: 17.0.7 - name: Build with Gradle env: