diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml new file mode 100644 index 0000000..d4aa0f2 --- /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: 'temurin' + 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 --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 5ce945a..7fa0fe9 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -4,63 +4,42 @@ on: workflow_dispatch: 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' java-version: 17 - - - name: Get Release Version - 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 + - 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 versions" || echo "No changes to commit" - + 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 - 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 + GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} + BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} 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 }} - + run: | + ./gradlew release -Prelease.useAutomaticVersion=true + ./gradlew -Pversion=${VERSION} publish -x test -PpublishToCentral=true - name: GitHub Release and Release Sync PR env: GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 4e357f4..b9da182 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -13,17 +13,16 @@ 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: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} - WORKING_DIR: ./copybook-cli run: | - ./gradlew build --stacktrace --console=plain + ./gradlew build --stacktrace --scan --console=plain --no-daemon - name: Generate Codecov Report - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v4 windows-build: @@ -34,12 +33,11 @@ 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: 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/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' + } +}