Skip to content

Commit

Permalink
Merge pull request #16 from ballerina-platform/build-scripts-fix
Browse files Browse the repository at this point in the history
Update the Build and Workflow Scripts
  • Loading branch information
ThisaruGuruge authored May 20, 2024
2 parents 01e2506 + 6126eb5 commit a0c6573
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 84 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build-timestamped-master.yml
Original file line number Diff line number Diff line change
@@ -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
86 changes: 86 additions & 0 deletions .github/workflows/central-publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
51 changes: 15 additions & 36 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
58 changes: 21 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
}
}
2 changes: 1 addition & 1 deletion copybook-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ plugins{
id 'java-library'
id 'checkstyle'
id 'com.github.spotbugs'
id 'jacoco'
}

dependencies {
Expand Down Expand Up @@ -69,7 +70,6 @@ jacocoTestReport {
additionalClassDirs(classFiles)
reports {
xml.required = true
html.required = true
}
}

Expand Down
16 changes: 14 additions & 2 deletions copybook-tool/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

0 comments on commit a0c6573

Please sign in to comment.