From 7194cc4c9ad659bea508b09d084acbfe94be8e5b Mon Sep 17 00:00:00 2001 From: Thisaru Guruge Date: Mon, 23 Oct 2023 18:16:05 +0530 Subject: [PATCH 1/3] Migrate to Gradle build and update workflows --- .github/issue_template.md | 18 --- .github/pull_request_template.md | 56 +------ .../workflows/build-with-bal-test-native.yml | 80 ++-------- .github/workflows/ci.yml | 100 ++---------- .github/workflows/daily-build.yml | 97 +----------- .github/workflows/dev-stg-release.yml | 81 ++-------- .github/workflows/pull-request.yml | 88 ++--------- .github/workflows/release.yml | 71 ++------- .github/workflows/trivy-scan.yml | 29 ++-- .gitignore | 7 +- ballerina/Ballerina.toml | 15 +- ballerina/Dependencies.toml | 146 ++++++++++++++++++ ballerina/build.gradle | 83 ++++++---- build-config/resources/Ballerina.toml | 15 +- build.gradle | 43 +++--- changelog.md | 11 ++ gradle.properties | 19 ++- native/build.gradle | 50 ++---- settings.gradle | 25 ++- 19 files changed, 379 insertions(+), 655 deletions(-) delete mode 100644 .github/issue_template.md create mode 100644 ballerina/Dependencies.toml create mode 100644 changelog.md diff --git a/.github/issue_template.md b/.github/issue_template.md deleted file mode 100644 index f275c800..00000000 --- a/.github/issue_template.md +++ /dev/null @@ -1,18 +0,0 @@ -**Description:** - - -**Suggested Labels:** - - -**Suggested Assignees:** - - -**Affected Product Version:** - -**OS, DB, other environment details and versions:** - -**Steps to reproduce:** - - -**Related Issues:** - \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 2b991607..96b073c5 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,52 +1,12 @@ ## Purpose -> Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc. -## Goals -> Describe the solutions that this feature/fix will introduce to resolve the problems described above +Fixes: -## Approach -> Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here. +## Examples -## User stories -> Summary of user stories addressed by this change> - -## Release note -> Brief description of the new feature or bug fix as it will appear in the release notes - -## Documentation -> Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact - -## Training -> Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable - -## Certification -> Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why. - -## Marketing -> Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable - -## Automation tests - - Unit tests - > Code coverage information - - Integration tests - > Details about the test cases and coverage - -## Security checks - - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no - - Ran FindSecurityBugs plugin and verified report? yes/no - - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no - -## Samples -> Provide high-level details about the samples related to this feature - -## Related PRs -> List any other related PRs - -## Migrations (if applicable) -> Describe migration steps and platforms on which migration has been tested - -## Test environment -> List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested - -## Learning -> Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem. \ No newline at end of file +## Checklist +- [ ] Linked to an issue +- [ ] Updated the changelog +- [ ] Added tests +- [ ] Updated the spec +- [ ] Checked native-image compatibility diff --git a/.github/workflows/build-with-bal-test-native.yml b/.github/workflows/build-with-bal-test-native.yml index 0d25eb56..a319c46f 100644 --- a/.github/workflows/build-with-bal-test-native.yml +++ b/.github/workflows/build-with-bal-test-native.yml @@ -2,76 +2,16 @@ name: GraalVM Check on: schedule: - - cron: '30 18 * * *' + - cron: "30 18 * * *" workflow_dispatch: -jobs: - build: - runs-on: ubuntu-latest - services: - mongodb: - image: mongo:4.2.0 - env: - # Following credentials are only used during testing in docker container - MONGO_INITDB_ROOT_USERNAME: admin - MONGO_INITDB_ROOT_PASSWORD: admin - ports: - - 27011:27017 - mongodb-ssl: - image: rzhilkibaev/mongo-x509-auth-ssl:latest - ports: - - 27012:27017 - - steps: - - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17.0.7 - - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: latest - - - name: Grant execute permission for gradlew - run: chmod +x gradlew +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: true - - name: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test - - - name: Set up GraalVM - uses: graalvm/setup-graalvm@v1 - with: - java-version: '17' - distribution: 'graalvm-community' - github-token: ${{ secrets.GITHUB_TOKEN }} - set-java-home: 'false' - - - name: Check GraalVM installation - run: | - echo "GRAALVM_HOME: ${{ env.GRAALVM_HOME }}" - echo "JAVA_HOME: ${{ env.JAVA_HOME }}" - native-image --version - - - name: Run Ballerina tests(MongoDB-SSL) using the native executable - run: bal test --graalvm --groups mongodb-ssl ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin - - - name: Run Ballerina tests(MongoDB) using the native executable - run: bal test --graalvm --groups mongodb ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_USER: admin - MONGODB_PASSWORD: admin +jobs: + call_stdlib_workflow: + name: Run StdLib Workflow + if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-with-bal-test-graalvm-connector-template.yml@main + secrets: inherit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 396c01e2..867399c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,100 +1,18 @@ name: CI + on: push: branches: - master - 2201.[0-9]+.x repository_dispatch: - types: - check_connector_for_breaking_changes + types: check_connector_for_breaking_changes jobs: - build: - runs-on: ubuntu-latest - services: - mongodb: - image: mongo:4.2.0 - env: - # Following credentials are only used during testing in docker container - MONGO_INITDB_ROOT_USERNAME: admin - MONGO_INITDB_ROOT_PASSWORD: admin - ports: - - 27011:27017 - mongodb-ssl: - image: rzhilkibaev/mongo-x509-auth-ssl:latest - ports: - - 27012:27017 - - steps: - - uses: actions/checkout@v3 - - # Set up Java Environment - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17.0.7 - - # Setup Ballerina Environment - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: latest - - # Grant execute permission to the gradlew script - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - # Build the project with Gradle - - name: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test - - # Build Ballerina Project - - name: Ballerina Build - run: bal pack ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - - # Test Ballerina MongoDB-SSL - - name: SSL Tests - run: bal test --groups mongodb-ssl --test-report --code-coverage --coverage-format=xml ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin - - - name: Upload SSL test coverage reports to Codecov - uses: codecov/codecov-action@v3 - - # Test Ballerina MongoDB - - name: MongoDB Test - run: bal test --groups mongodb --test-report --code-coverage --coverage-format=xml ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_USER: admin - MONGODB_PASSWORD: admin - - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 - - - name: Alert notifier on failure - if: failure() && (github.event.action == 'check_connector_for_breaking_changes') - run: | - curl -X POST \ - 'https://api.github.com/repos/ballerina-platform/ballerina-release/dispatches' \ - --header 'Accept: application/vnd.github.v3+json' \ - --header 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \ - --data-raw '{ - "event_type": "notify-ballerinax-connector-build-failure", - "client_payload": { - "repoName": "module-ballerinax-mongodb", - "workflow": "CI" - } - }' + call_workflow: + name: Run Connector Build Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-connector-template.yml@main + secrets: inherit + with: + repo-name: module-ballerinax-mongodb diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index 498ae49a..899b15c9 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -2,94 +2,13 @@ name: Daily build on: schedule: - - cron: '30 2 * * *' + - cron: "30 2 * * *" jobs: - build: - runs-on: ubuntu-latest - services: - mongodb: - image: mongo:4.2.0 - env: - # Following credentials are only used during testing in docker container - MONGO_INITDB_ROOT_USERNAME: admin - MONGO_INITDB_ROOT_PASSWORD: admin - ports: - - 27011:27017 - mongodb-ssl: - image: rzhilkibaev/mongo-x509-auth-ssl:latest - ports: - - 27012:27017 - - steps: - - uses: actions/checkout@v3 - - # Set up Java Environment - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17.0.7 - - # Setup Ballerina Environment - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: latest - - # Grant execute permission to the gradlew script - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - # Build the project with Gradle - - name: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test - - # Build Ballerina Project - - name: Ballerina Build - run: bal pack ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - - # Test Ballerina MongoDB-SSL - - name: SSL Tests - run: bal test --groups mongodb-ssl --test-report --code-coverage --coverage-format=xml ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin - - - name: Upload SSL test coverage reports to Codecov - uses: codecov/codecov-action@v3 - - # Test Ballerina MongoDB - - name: MongoDB Test - run: bal test --groups mongodb --test-report --code-coverage --coverage-format=xml ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_USER: admin - MONGODB_PASSWORD: admin - - - name: Upload MongoDB test coverage reports to Codecov - uses: codecov/codecov-action@v3 - - # Send notification when build fails - - name: Notify failure - if: ${{ failure() }} - run: | - curl -X POST \ - 'https://api.github.com/repos/ballerina-platform/ballerina-release/dispatches' \ - -H 'Accept: application/vnd.github.v3+json' \ - -H 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \ - --data "{ - \"event_type\": \"notify-build-failure\", - \"client_payload\": { - \"repoName\": \"module-ballerinax-mongodb\" - } - }" + call_workflow: + name: Run Daily Build Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/daily-build-connector-template.yml@main + secrets: inherit + with: + repo-name: module-ballerinax-mongodb diff --git a/.github/workflows/dev-stg-release.yml b/.github/workflows/dev-stg-release.yml index 95e23dbb..49d6f529 100644 --- a/.github/workflows/dev-stg-release.yml +++ b/.github/workflows/dev-stg-release.yml @@ -1,76 +1,21 @@ -name: Dev/Staging BCentral Release +name: Publish to the Ballerina Dev\Stage Central on: workflow_dispatch: inputs: - bal_central_environment: - description: Ballerina Central Environment + environment: type: choice - options: - - STAGE - - DEV + description: Select Environment required: true + options: + - DEV CENTRAL + - STAGE CENTRAL jobs: - release: - runs-on: ubuntu-latest - env: - BALLERINA_${{ github.event.inputs.bal_central_environment }}_CENTRAL: true - - steps: - - uses: actions/checkout@v3 - - # Set up Java Environment - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17.0.7 - - # Setup Ballerina Environment - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: 2201.7.0 - - # Grant execute permission to the gradlew script - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - # Build the project with Gradle - - name: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test -x :mongodb-examples:build - - # Perform Trivy scan - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - scan-type: 'rootfs' - scan-ref: '.' - skip-dirs: 'gradle/' - format: 'table' - timeout: '10m0s' - exit-code: '1' - - # Push to Ballerina Staging Central - - name: Push to Staging - if: github.event.inputs.bal_central_environment == 'STAGE' - run: bal push - working-directory: ./ballerina - env: - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }} - JAVA_HOME: /usr/lib/jvm/default-jvm - - # Push to Ballerina Dev Central - - name: Push to Dev - if: github.event.inputs.bal_central_environment == 'DEV' - run: bal push - working-directory: ./ballerina - env: - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} - JAVA_HOME: /usr/lib/jvm/default-jvm + call_workflow: + name: Run Dev\Stage Central Publish Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/dev-stage-central-publish-connector-template.yml@main + secrets: inherit + with: + environment: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index ad8a64c5..bcbb743f 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,78 +1,16 @@ -name: Pull Request +name: PR Build -on: [ pull_request ] +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: true -jobs: - build: - runs-on: ubuntu-latest - services: - mongodb: - image: mongo:4.2.0 - env: - # Following credentials are only used during testing in docker container - MONGO_INITDB_ROOT_USERNAME: admin - MONGO_INITDB_ROOT_PASSWORD: admin - ports: - - 27011:27017 - mongodb-ssl: - image: rzhilkibaev/mongo-x509-auth-ssl:latest - ports: - - 27012:27017 - - steps: - - uses: actions/checkout@v3 - - # Set up Java Environment - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 17.0.7 - - # Setup Ballerina Environment - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: latest - - # Grant execute permission to the gradlew script - - name: Grant execute permission for gradlew - run: chmod +x gradlew +on: pull_request - # Build the project with Gradle - - name: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test - - - name: Ballerina Build - run: bal pack ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - - # Test Ballerina MongoDB-SSL - - name: SSL Tests - run: bal test --groups mongodb-ssl --test-report --code-coverage --coverage-format=xml ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin - - - name: Upload SSL test coverage reports to Codecov - uses: codecov/codecov-action@v3 - - # Test Ballerina MongoDB - - name: MongoDB Test - run: bal test --groups mongodb --test-report --code-coverage --coverage-format=xml ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_USER: admin - MONGODB_PASSWORD: admin - - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 +jobs: + call_workflow: + name: Run PR Build Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/pr-build-connector-template.yml@main + secrets: inherit + with: + additional-test-flags: ${{ github.event.pull_request.head.repo.full_name != github.repository && '-x test' || ''}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6348056d..23cff0ac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,63 +1,16 @@ -name: Deployment +name: Publish Release on: - release: - types: [ published ] + workflow_dispatch: + repository_dispatch: + types: [ stdlib-release-pipeline ] jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - # Set up Java Environment - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17.0.7 - - # Setup Ballerina Environment - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: 2201.7.0 - - # Grant execute permission to the gradlew script - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - # Build the project with Gradle - - name: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - run: | - ./gradlew build -x test -x :mongodb-examples:build - - # Perform Trivy scan - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - scan-type: 'rootfs' - scan-ref: '.' - skip-dirs: 'gradle/' - format: 'table' - timeout: '10m0s' - exit-code: '1' - - # Build Ballerina Project - - name: Ballerina Build - run: bal pack ./ballerina - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - - # Push to Ballerina Central - - name: Ballerina Push - run: bal push - working-directory: ./ballerina - env: - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} - JAVA_HOME: /usr/lib/jvm/default-jvm + call_workflow: + name: Run Release Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/release-package-template.yml@main + secrets: inherit + with: + package-name: mongodb + package-org: ballerinax diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 182dbd26..af3cbfa1 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -1,40 +1,35 @@ name: Trivy on: - workflow_dispatch: - schedule: - - cron: '30 20 * * *' + workflow_call: jobs: ubuntu-build: name: Build on Ubuntu 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' + distribution: "temurin" java-version: 17.0.7 - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1.1.0 - with: - version: latest - - name: Build with Gradle env: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew build -x check -x test -x :mongodb-examples:build + run: ./gradlew build -x check -x test + + - name: Create lib directory if not exists + run: mkdir -p ballerina/lib - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master with: - scan-type: 'rootfs' - scan-ref: '.' - skip-dirs: 'gradle/' - format: 'table' - timeout: '10m0s' - exit-code: '1' + scan-type: "rootfs" + scan-ref: "/github/workspace/ballerina/lib" + format: "table" + timeout: "10m0s" + exit-code: "1" diff --git a/.gitignore b/.gitignore index 16df0dba..8845f4b7 100644 --- a/.gitignore +++ b/.gitignore @@ -36,10 +36,7 @@ target *.ipr *.iws .gradle -*/build build -mongo-utils/dependency-reduced-pom.xml -/mongodb/resources/*.json - -Ballerina.lock +# Environment files +*.env diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index e02f5ba1..a69468c9 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -9,26 +9,29 @@ keywords = ["IT Operations/Databases", "Cost/Freemium"] icon = "icon.png" repository = "https://github.com/ballerina-platform/module-ballerinax-mongodb" -[platform.java11] +[platform.java17] graalvmCompatible = true -[[platform.java11.dependency]] +[[platform.java17.dependency]] path = "../native/build/libs/mongodb-native-4.3.0.jar" groupId = "org.ballerinalang" artifactId = "mongodb-native" version = "4.3.0" -[[platform.java11.dependency]] +[[platform.java17.dependency]] groupId = "com.fasterxml.jackson.core" artifactId = "jackson-core" -version = "2.13.5" +version = "2.15.2" +path = "./lib/jackson-core-2.15.2.jar" [[platform.java11.dependency]] groupId = "com.fasterxml.jackson.core" artifactId = "jackson-annotations" -version = "2.13.5" +version = "2.15.2" +path = "./lib/jackson-annotations-2.15.2.jar" [[platform.java11.dependency]] groupId = "com.fasterxml.jackson.core" artifactId = "jackson-databind" -version = "2.13.5" +version = "2.15.2" +path = "./lib/jackson-databind-2.15.2.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml new file mode 100644 index 00000000..a8288221 --- /dev/null +++ b/ballerina/Dependencies.toml @@ -0,0 +1,146 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.8.0-20230830-220400-8a7556d8" + +[[package]] +org = "ballerina" +name = "crypto" +version = "2.5.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "time"} +] +modules = [ + {org = "ballerina", packageName = "crypto", moduleName = "crypto"} +] + +[[package]] +org = "ballerina" +name = "file" +version = "1.9.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "os"}, + {org = "ballerina", name = "time"} +] +modules = [ + {org = "ballerina", packageName = "file", moduleName = "file"} +] + +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +modules = [ + {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "log" +version = "2.9.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerina", packageName = "log", moduleName = "log"} +] + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "os" +version = "1.8.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "os", moduleName = "os"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + +[[package]] +org = "ballerina" +name = "time" +version = "2.4.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinax" +name = "mongodb" +version = "4.3.0" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "file"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "os"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerinax", packageName = "mongodb", moduleName = "mongodb"} +] + diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 171d90ca..455e0d91 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -16,10 +16,17 @@ * under the License. */ +import org.apache.tools.ant.taskdefs.condition.Os + +plugins { + id 'io.ballerina.plugin' +} + description = 'Ballerina - Mongodb Ballerina Connector' +def packageName = "mongodb" +def packageOrg = "ballerinax" def tomlVersion = stripBallerinaExtensionVersion("${project.version}") - def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml") def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") @@ -33,47 +40,59 @@ def stripBallerinaExtensionVersion(String extVersion) { return extVersion } } else { - return extVersion.replace("${project.ext.snapshotVersion}", '') + return extVersion.replace("${project.ext.snapshotVersion}", "") } } -task updateTomlFiles { - doLast { - def newConfig = ballerinaTomlFilePlaceHolder.text.replace('@project.version@', project.version.toString()) - newConfig = newConfig.replace('@toml.version@', tomlVersion) - ballerinaTomlFile.text = newConfig - } +ballerina { + packageOrganization = packageOrg + module = packageName + testCoverageParam = "--code-coverage --coverage-format=xml" + buildOnDockerImage = "nightly" } -task build { - dependsOn ":${packageName}-native:build" - dependsOn updateTomlFiles - doLast { - executeBalCommand ("build", "${project.projectDir}") - executeBalCommand ("pack", "${project.projectDir}") - //TODO: Disabled due to the void of examples - // executeBalCommand ("push --repository=local", "${project.projectDir}") - - // def centralDir = file("${System.getProperty('user.home')}/.ballerina/repositories/central.ballerina.io/") - // def cacheDirs = centralDir.listFiles().findAll { it.isDirectory() && it.name.startsWith('cache-') } - // delete cacheDirs +configurations { + externalJars +} - // def destinationDir = new File("${System.getProperty('user.home')}/.ballerina/repositories/central.ballerina.io/bala/ballerinax/${project.balPackageName}") - // if (destinationDir.exists()) { - // delete destinationDir; - // } +dependencies { + externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: "${jacksonVersion}") { + transitive = false + } + externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: "${jacksonVersion}") { + transitive = false + } + externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jacksonVersion}") { + transitive = false + } +} - // copy { - // from "${System.getProperty('user.home')}/.ballerina/repositories/local/bala/ballerinax/${project.balPackageName}" - // into destinationDir - // } +task updateTomlFiles { + doLast { + def newBallerinaToml = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) + newBallerinaToml = newBallerinaToml.replace("@toml.version@", tomlVersion) + newBallerinaToml = newBallerinaToml.replace("@jackson.version@", jacksonVersion) + ballerinaTomlFile.text = newBallerinaToml } } -task test { - dependsOn ":${packageName}-native:build" - dependsOn updateTomlFiles +task commitTomlFiles { doLast { - executeBalCommand ("test", "${project.projectDir}") + project.exec { + ignoreExitValue true + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "git commit -m \"[Automated] Update the toml files\" Ballerina.toml Dependencies.toml" + } else { + commandLine 'sh', '-c', "git commit -m '[Automated] Update the toml files' Ballerina.toml Dependencies.toml" + } + } } } + +clean { + delete 'build' +} + +build.dependsOn copyToLib +build.dependsOn ":${packageName}-native:build" +test.dependsOn ":${packageName}-native:build" diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index b9254b40..6935580b 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -9,26 +9,29 @@ keywords = ["IT Operations/Databases", "Cost/Freemium"] icon = "icon.png" repository = "https://github.com/ballerina-platform/module-ballerinax-mongodb" -[platform.java11] +[platform.java17] graalvmCompatible = true -[[platform.java11.dependency]] +[[platform.java17.dependency]] path = "../native/build/libs/mongodb-native-@project.version@.jar" groupId = "org.ballerinalang" artifactId = "mongodb-native" version = "@project.version@" -[[platform.java11.dependency]] +[[platform.java17.dependency]] groupId = "com.fasterxml.jackson.core" artifactId = "jackson-core" -version = "2.13.5" +version = "@jackson.version@" +path = "./lib/jackson-core-@jackson.version@.jar" [[platform.java11.dependency]] groupId = "com.fasterxml.jackson.core" artifactId = "jackson-annotations" -version = "2.13.5" +version = "@jackson.version@" +path = "./lib/jackson-annotations-@jackson.version@.jar" [[platform.java11.dependency]] groupId = "com.fasterxml.jackson.core" artifactId = "jackson-databind" -version = "2.13.5" +version = "@jackson.version@" +path = "./lib/jackson-databind-@jackson.version@.jar" diff --git a/build.gradle b/build.gradle index 72416f19..31b1d2d9 100644 --- a/build.gradle +++ b/build.gradle @@ -18,10 +18,10 @@ import org.apache.tools.ant.taskdefs.condition.Os plugins { - id "com.github.spotbugs" version "${githubSpotbugsVersion}" - id "com.github.johnrengelman.shadow" version "${githubJohnrengelmanShadowVersion}" - id "de.undercouch.download" version "${underCouchDownloadVersion}" - id "net.researchgate.release" version "${researchgateReleaseVersion}" + id "com.github.spotbugs-base" + id "com.github.johnrengelman.shadow" + id "de.undercouch.download" + id "net.researchgate.release" } description = 'Ballerina - Mongodb' @@ -54,30 +54,25 @@ allprojects { } ext { - snapshotVersion= '-SNAPSHOT' + snapshotVersion = '-SNAPSHOT' timestampedVersionRegex = '.*-\\d{8}-\\d{6}-\\w.*\$' - packageName ='mongodb' - balPackageName = 'mongodb' } } -def executeBalCommand(String command, String dir) { - try { - exec { - workingDir dir - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "bal.bat ${command} && exit %%ERRORLEVEL%%" - } else { - commandLine 'sh', '-c', "bal ${command}" - } - } - } catch (Exception e) { - println("bal command failed. " + e.message) - throw e - } +task build { + dependsOn(":mongodb-native:build") + dependsOn(":mongodb-ballerina:build") } -task build { - dependsOn("${project.packageName}-native:build") - dependsOn("${project.packageName}-ballerina:build") +def moduleVersion = project.version.replace("-SNAPSHOT", "") + +release { + buildTasks = ['build'] + failOnSnapshotDependencies = true + versionPropertyFile = 'gradle.properties' + tagTemplate = 'v${version}' + git { + requireBranch = "release-${moduleVersion}" + pushToRemote = 'origin' + } } diff --git a/changelog.md b/changelog.md new file mode 100644 index 00000000..302cf6cf --- /dev/null +++ b/changelog.md @@ -0,0 +1,11 @@ +# Change Log +This file contains all the notable changes done to the Ballerina GraphQL package through the releases. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to +[Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Changed + +- [[#5073] Migrate to Gradle Build](https://github.com/ballerina-platform/ballerina-standard-library/issues/5073) diff --git a/gradle.properties b/gradle.properties index 08d8bfa7..463e40e9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,16 @@ org.gradle.caching=true group=org.ballerinalang.mongodb version=4.3.0 +ballerinaLangVersion=2201.8.2 -puppycrawlCheckstyleVersion=10.12.1 -checkstyleToolVersion=10.12.1 -githubSpotbugsVersion=5.0.14 -githubJohnrengelmanShadowVersion=8.1.1 -underCouchDownloadVersion=5.4.0 -researchgateReleaseVersion=2.8.0 -testngVersion=7.6.1 +checkstylePluginVersion=10.12.0 +spotbugsPluginVersion=5.0.14 +shadowJarPluginVersion=8.1.1 +downloadPluginVersion=5.4.0 +releasePluginVersion=2.8.0 +ballerinaGradlePluginVersion=2.1.5 +jacocoVersion=0.8.10 -ballerinaLangVersion=2201.8.0-20230830-220400-8a7556d8 +slf4jVersion=1.7.21 +jacksonVersion=2.15.2 +mongoJavaDriverVersion=3.12.14 diff --git a/native/build.gradle b/native/build.gradle index e4e63532..13850404 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -17,46 +17,38 @@ */ plugins { - id 'java-library' - id 'com.github.spotbugs' + id 'java' id 'checkstyle' - id 'jacoco' + id 'com.github.spotbugs' } description = 'Ballerina - Mongodb Native' configurations { - jacocoRuntime dist { transitive true } } dependencies { - jacocoRuntime "org.jacoco:org.jacoco.agent:${jacoco.toolVersion}:runtime" - checkstyle project(":checkstyle") - checkstyle "com.puppycrawl.tools:checkstyle:${puppycrawlCheckstyleVersion}" + checkstyle "com.puppycrawl.tools:checkstyle:${checkstylePluginVersion}" implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}" - implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21' - implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: project.ballerinaLangVersion - implementation group: 'org.ballerinalang', name: 'value', version: project.ballerinaLangVersion - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.15.2' - implementation group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.14' - dist group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.14' + implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}" + implementation group: 'org.ballerinalang', name: 'value', version: "${ballerinaLangVersion}" + + implementation group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jVersion}" + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jacksonVersion}" + implementation group: 'org.mongodb', name: 'mongo-java-driver', version: "${mongoJavaDriverVersion}" + + dist group: 'org.mongodb', name: 'mongo-java-driver', version: "${mongoJavaDriverVersion}" } tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } -sourceCompatibility = JavaVersion.VERSION_17 - -jacoco { - toolVersion = "0.8.10" -} - test { testLogging { showStackTraces = true @@ -89,30 +81,16 @@ spotbugsTest { enabled = false } -task validateSpotbugs() { - doLast { - if (spotbugsMain.reports.size() > 0 && - spotbugsMain.reports[0].destination.exists() && - spotbugsMain.reports[0].destination.text.readLines().size() > 0) { - spotbugsMain.reports[0].destination?.eachLine { - println 'Failure: ' + it - } - throw new GradleException("Spotbugs rule violations were found."); - } - } +tasks.withType(Checkstyle) { + exclude '**/module-info.java' } checkstyle { - toolVersion "${checkstyleToolVersion}" + toolVersion "${checkstylePluginVersion}" configFile file("${rootDir}/build-config/checkstyle/build/checkstyle.xml") configProperties = ["suppressionFile": file("${rootDir}/build-config/checkstyle/build/suppressions.xml")] } -tasks.withType(Checkstyle) { - exclude '**/module-info.java' -} - -spotbugsMain.finalizedBy validateSpotbugs checkstyleMain.dependsOn ':checkstyle:downloadCheckstyleRuleFiles' jar { diff --git a/settings.gradle b/settings.gradle index 7b1b7969..572e09f0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,22 +16,41 @@ * under the License. */ +pluginManagement { + plugins { + id "com.github.spotbugs-base" version "${spotbugsPluginVersion}" + id "com.github.johnrengelman.shadow" version "${shadowJarPluginVersion}" + id "de.undercouch.download" version "${downloadPluginVersion}" + id "net.researchgate.release" version "${releasePluginVersion}" + id "io.ballerina.plugin" version "${ballerinaGradlePluginVersion}" + } + + repositories { + gradlePluginPortal() + maven { + url = 'https://maven.pkg.github.com/ballerina-platform/*' + credentials { + username System.getenv("packageUser") + password System.getenv("packagePAT") + } + } + } +} + plugins { id "com.gradle.enterprise" version "3.13.2" } def projectName = 'mongodb' -rootProject.name = "ballerinax-${projectName}" +rootProject.name = "ballerinax ${projectName}" include ":checkstyle" include ":${projectName}-native" include ":${projectName}-ballerina" -include ":${projectName}-examples" project(':checkstyle').projectDir = file("build-config${File.separator}checkstyle") project(":${projectName}-native").projectDir = file('native') project(":${projectName}-ballerina").projectDir = file('ballerina') -project(":${projectName}-examples").projectDir = file('examples') gradleEnterprise { buildScan { From c3737a421b7b6af047a7e8ff035b0f5a9bb71953 Mon Sep 17 00:00:00 2001 From: Thisaru Guruge Date: Mon, 23 Oct 2023 18:20:14 +0530 Subject: [PATCH 2/3] Update the code owners --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c7a7c77a..89641008 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4,4 +4,4 @@ # See: https://help.github.com/articles/about-codeowners/ # These owners will be the default owners for everything in the repo. -* @indikasampath2000 @abeykoon @kasthuriraajan +* @ThisaruGuruge From 91aca74ff7e8b9c62e5381e266cffb5b1f63e68b Mon Sep 17 00:00:00 2001 From: Thisaru Guruge Date: Mon, 23 Oct 2023 19:53:40 +0530 Subject: [PATCH 3/3] Apply suggestions from review --- .github/workflows/build-with-bal-test-native.yml | 4 ++-- .github/workflows/release.yml | 2 +- ballerina/tests/main_test.bal | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-with-bal-test-native.yml b/.github/workflows/build-with-bal-test-native.yml index a319c46f..a00897f0 100644 --- a/.github/workflows/build-with-bal-test-native.yml +++ b/.github/workflows/build-with-bal-test-native.yml @@ -10,8 +10,8 @@ concurrency: cancel-in-progress: true jobs: - call_stdlib_workflow: - name: Run StdLib Workflow + call_workflow_template: + name: Run Workflow Template if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-with-bal-test-graalvm-connector-template.yml@main secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 23cff0ac..343484cb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: Publish Release on: workflow_dispatch: repository_dispatch: - types: [ stdlib-release-pipeline ] + types: [ connector-release-pipeline ] jobs: call_workflow: diff --git a/ballerina/tests/main_test.bal b/ballerina/tests/main_test.bal index 9007e792..187ff7b4 100644 --- a/ballerina/tests/main_test.bal +++ b/ballerina/tests/main_test.bal @@ -163,7 +163,6 @@ public function testFindData() returns error? { stream result = check mongoClient->find(COLLECTION_NAME,filter = findDoc); check result.forEach(function(Movie data){ log:printInfo(data.year.toString()); - test:assertTrue(data is Movie); test:assertEquals(data.year,"2019","Querying year 2019 filter failed"); }); log:printInfo("Querying year 2019 filter tested successfully");