From 23efe04e02c66fec837c1dd00ca0e070fb13af3f Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Mon, 25 Sep 2023 13:41:45 +0530 Subject: [PATCH 1/4] Migrate workflows to reuse workflows from ballerina-standard-library repo --- .../workflows/build-timestamped-master.yml | 47 +++-------- .github/workflows/central-publish.yml | 73 ++--------------- .github/workflows/publish-release.yml | 78 +++---------------- .github/workflows/pull-request.yml | 52 +++---------- .github/workflows/trivy-scan.yml | 32 ++------ 5 files changed, 45 insertions(+), 237 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index bb07a4dd..b368115a 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -1,47 +1,20 @@ name: Build on: - workflow_dispatch: push: branches: - main - 2201.[0-9]+.x paths-ignore: - - '*.md' - - 'docs/**' - - 'load-tests/**' + - "*.md" + - "docs/**" + - "load-tests/**" + + 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: Build with Gradle - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - publishUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - publishPAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - run: | - ./gradlew publish --scan --no-daemon - - name: Generate Codecov Report - uses: codecov/codecov-action@v2 - - name: Upload Artifact - uses: actions/upload-artifact@v2 - with: - name: ballerina-runtime - path: target/ballerina-runtime/ + call_workflow: + name: Run Build Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-timestamp-master-template.yml@main + secrets: inherit diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 81db32b9..c0bd478b 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -5,74 +5,17 @@ on: inputs: environment: type: choice - description: Select environment + description: Select Environment required: true options: - - CENTRAL - DEV CENTRAL - STAGE CENTRAL jobs: - publish-release: - 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: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew build -x check -x test -x :mssql-examples:build - - 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: '/github/workspace/ballerina/lib' - format: 'table' - timeout: '10m0s' - exit-code: '1' - - - name: Ballerina Central Push - if: ${{ github.event.inputs.environment == 'CENTRAL' }} - env: - BALLERINA_DEV_CENTRAL: false - BALLERINA_STAGE_CENTRAL: false - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} - run: | - ./gradlew clean build -PpublishToCentral=true - - - name: Ballerina Central Dev Push - if: ${{ github.event.inputs.environment == 'DEV CENTRAL' }} - env: - BALLERINA_DEV_CENTRAL: true - BALLERINA_STAGE_CENTRAL: false - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} - run: | - sed -i 's/version=\(.*\)-SNAPSHOT/version=\1/g' gradle.properties - ./gradlew clean build -PpublishToCentral=true - - - name: Ballerina Central Stage Push - if: ${{ github.event.inputs.environment == 'STAGE CENTRAL' }} - env: - BALLERINA_DEV_CENTRAL: false - BALLERINA_STAGE_CENTRAL: true - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }} - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} - run: | - sed -i 's/version=\(.*\)-SNAPSHOT/version=\1/g' gradle.properties - ./gradlew clean build -PpublishToCentral=true + call_workflow: + name: Run Central Publish Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/central-publish-template.yml@main + secrets: inherit + with: + environment: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 64b46527..6756e392 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,73 +1,17 @@ -name: Publish release +name: Publish Release on: workflow_dispatch: repository_dispatch: - types: [ stdlib-release-pipeline ] + types: [stdlib-release-pipeline] jobs: - publish-release: - 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: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: | - git config --global user.name ${{ secrets.BALLERINA_BOT_USERNAME }} - git config --global user.email ${{ secrets.BALLERINA_BOT_EMAIL }} - ./gradlew build -x check -x test -x :mssql-examples:build - - 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: '/github/workspace/ballerina/lib' - format: 'table' - timeout: '10m0s' - exit-code: '1' - - 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 depenedency 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/observe\(.*\)=\(.*\)-SNAPSHOT/observe\1=\2/g' gradle.properties - sed -i 's/observe\(.*\)=\(.*\)-[0-9]\{8\}-[0-9]\{6\}-.*$/observe\1=\2/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: Publish artifact - env: - BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} - GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - publishUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - publishPAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - run: | - ./gradlew clean 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 }} - run: | - gh release create v$VERSION --title "module-ballerinax-mssql-v$VERSION" - gh pr create --base main --title "[Automated] Sync main after $VERSION release" --body "Sync main after $VERSION release" + 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: mssql + package-org: ballerinax + additional-build-flags: "-x :mssql-examples:build" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 19b4d3ef..5cdb8f7f 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,45 +1,13 @@ -name: PR build +name: PR Build -on: - pull_request: - branches: - - main - - 2201.[0-9]+.x +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: true -jobs: - ubuntu-build: - name: Build on Ubuntu - 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.0.7 - - name: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew build - - name: Generate Codecov Report - uses: codecov/codecov-action@v2 - with: - token: ${{ secrets.CODECOV_TOKEN }} +on: pull_request - windows-build: - name: Build on Windows - runs-on: windows-latest - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17.0.7 - - name: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew.bat build -x test - # Disabling tests because no docker in gitaction windows +jobs: + call_workflow: + name: Run PR Build Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/pull-request-build-template.yml@main diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 418cf753..f3b9cbae 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -3,31 +3,11 @@ name: Trivy on: workflow_dispatch: schedule: - - cron: '30 20 * * *' + - cron: "30 20 * * *" jobs: - ubuntu-build: - name: Build on Ubuntu - 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.0.7 - - name: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew build -x check -x test -x :mssql-examples:build - - 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: '/github/workspace/ballerina/lib' - format: 'table' - timeout: '10m0s' - exit-code: '1' + call_workflow: + name: Run Trivy Scan Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/trivy-scan-template.yml@main + secrets: inherit From d2b69e0b351fdb945ca083777bdd9bfb2fafa64d Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Mon, 2 Oct 2023 12:29:18 +0530 Subject: [PATCH 2/4] Disable tests for windows builds --- .github/workflows/pull-request.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 5cdb8f7f..3b1cd433 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,3 +11,5 @@ jobs: name: Run PR Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} uses: ballerina-platform/ballerina-standard-library/.github/workflows/pull-request-build-template.yml@main + with: + additional-windows-test-flags: "-x test" From f1e247c662925237ca92b955c5ac1a4e1bac9110 Mon Sep 17 00:00:00 2001 From: Niveathika Date: Sat, 11 Nov 2023 08:20:49 +0530 Subject: [PATCH 3/4] Inherit secrets for pr build --- .github/workflows/pull-request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 3b1cd433..a5ca37aa 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,5 +11,6 @@ jobs: name: Run PR Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} uses: ballerina-platform/ballerina-standard-library/.github/workflows/pull-request-build-template.yml@main + secrets: inherit with: additional-windows-test-flags: "-x test" From ecdecee577577cfea464b800da39bde975c04d4b Mon Sep 17 00:00:00 2001 From: Niveathika Date: Tue, 5 Dec 2023 11:05:30 +0530 Subject: [PATCH 4/4] Disable examples build in trivy scan --- .github/workflows/trivy-scan.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index f3b9cbae..7c3058db 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -11,3 +11,5 @@ jobs: if: ${{ github.repository_owner == 'ballerina-platform' }} uses: ballerina-platform/ballerina-standard-library/.github/workflows/trivy-scan-template.yml@main secrets: inherit + with: + additional-build-flags: "-x :mssql-examples:build"