Skip to content

Commit d86a690

Browse files
committed
Add test cases and workflow files for Moesif extension
1 parent f5e04d5 commit d86a690

File tree

19 files changed

+1248
-2
lines changed

19 files changed

+1248
-2
lines changed

.github/workflows/build-main.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ballerina_version:
7+
description: 'Ballerina version'
8+
required: true
9+
default: '2201.10.0'
10+
push:
11+
branches:
12+
- main
13+
14+
env:
15+
BALLERINA_DISTRIBUTION_VERSION: 2201.12.8 # Update this with the latest Ballerina version
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
if: github.repository_owner == 'ballerina-platform'
21+
steps:
22+
- name: Checkout Repository
23+
uses: actions/checkout@v3
24+
- name: Set up JDK 21
25+
uses: actions/setup-java@v3
26+
with:
27+
distribution: 'temurin'
28+
java-version: 21.0.3
29+
- name: Set up Ballerina
30+
if: github.event_name == 'workflow_dispatch'
31+
uses: ballerina-platform/setup-ballerina@v1.1.3
32+
with:
33+
version: ${{ github.event.inputs.ballerina_version }}
34+
- name: Set up Ballerina
35+
if: github.event_name == 'push'
36+
uses: ballerina-platform/setup-ballerina@v1.1.3
37+
with:
38+
version: ${{ env.BALLERINA_DISTRIBUTION_VERSION }}
39+
- name: Change to Timestamped Version
40+
run: |
41+
startTime=$(TZ="Asia/Kolkata" date +'%Y%m%d-%H%M00')
42+
latestCommit=$(git log -n 1 --pretty=format:"%h")
43+
VERSION=$((grep -w 'version' | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev)
44+
updatedVersion=$VERSION-$startTime-$latestCommit
45+
echo $updatedVersion
46+
echo TIMESTAMPED_VERSION=$updatedVersion >> $GITHUB_ENV
47+
sed -i "s/version=\(.*\)/version=$updatedVersion/g" gradle.properties
48+
- name: Grant execute permission for gradlew
49+
run: chmod +x gradlew
50+
- name: Set Docker Host env variable
51+
run: echo "DOCKER_HOST=$(docker context ls --format '{{print .DockerEndpoint}}' | tr -d '\n')" >> $GITHUB_ENV
52+
- name: Build with Gradle
53+
env:
54+
DOCKER_HOST: unix:///var/run/docker.sock
55+
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
56+
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
57+
packagePublishRepo: ${{ github.repository }}
58+
run: |
59+
./gradlew clean build publish --stacktrace --scan --console=plain --no-daemon
60+
./gradlew codeCoverageReport --console=plain --no-daemon
61+
- name: Upload Coverage Report
62+
uses: codecov/codecov-action@v4
63+
with:
64+
files: ballerina-tests/moesif-server-tests/target/report/moesif_server_tests/coverage-report.xml
65+
- name: Upload Artifacts
66+
uses: actions/upload-artifact@v2
67+
with:
68+
name: distribution
69+
path: |
70+
ballerina/build/distributions/moesif-extension-ballerina-*.zip
71+
if-no-files-found: error
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Publish to the Ballerina central
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ballerina_version:
7+
description: 'Ballerina version'
8+
required: true
9+
default: '2201.12.8'
10+
environment:
11+
type: choice
12+
description: Select environment
13+
required: true
14+
options:
15+
- CENTRAL
16+
- DEV CENTRAL
17+
- STAGE CENTRAL
18+
19+
jobs:
20+
publish-release:
21+
runs-on: ubuntu-latest
22+
if: github.repository_owner == 'ballerina-platform'
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Set up JDK 21
26+
uses: actions/setup-java@v3
27+
with:
28+
distribution: 'temurin'
29+
java-version: 21.0.3
30+
- name: Set up Ballerina
31+
uses: ballerina-platform/setup-ballerina@v1.1.3
32+
with:
33+
version: ${{ github.event.inputs.ballerina_version }}
34+
- name: Build with Gradle
35+
env:
36+
packageUser: ${{ github.actor }}
37+
packagePAT: ${{ secrets.GITHUB_TOKEN }}
38+
run: ./gradlew build -x check -x test
39+
- name: Run Trivy vulnerability scanner
40+
uses: aquasecurity/trivy-action@master
41+
with:
42+
scan-type: 'rootfs'
43+
scan-ref: '/github/workspace/ballerina/lib'
44+
format: 'table'
45+
timeout: '10m0s'
46+
exit-code: '1'
47+
48+
- name: Ballerina Central Push
49+
if: ${{ github.event.inputs.environment == 'CENTRAL' }}
50+
env:
51+
BALLERINA_DEV_CENTRAL: false
52+
BALLERINA_STAGE_CENTRAL: false
53+
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }}
54+
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
55+
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
56+
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
57+
run: |
58+
./gradlew clean build -PpublishToCentral=true
59+
- name: Ballerina Central Dev Push
60+
if: ${{ github.event.inputs.environment == 'DEV CENTRAL' }}
61+
env:
62+
BALLERINA_DEV_CENTRAL: true
63+
BALLERINA_STAGE_CENTRAL: false
64+
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }}
65+
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
66+
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
67+
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
68+
run: |
69+
sed -i 's/version=\(.*\)-SNAPSHOT/version=\1/g' gradle.properties
70+
./gradlew clean build -PpublishToCentral=true
71+
- name: Ballerina Central Stage Push
72+
if: ${{ github.event.inputs.environment == 'STAGE CENTRAL' }}
73+
env:
74+
BALLERINA_DEV_CENTRAL: false
75+
BALLERINA_STAGE_CENTRAL: true
76+
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_STAGE_ACCESS_TOKEN }}
77+
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
78+
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
79+
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
80+
run: |
81+
sed -i 's/version=\(.*\)-SNAPSHOT/version=\1/g' gradle.properties
82+
./gradlew clean build -PpublishToCentral=true

.github/workflows/daily-build.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Daily Build
2+
3+
on:
4+
schedule:
5+
- cron: '30 18 * * *'
6+
workflow_dispatch:
7+
inputs:
8+
ballerina_version:
9+
description: 'Ballerina version'
10+
required: true
11+
default: '2201.10.0'
12+
13+
env:
14+
BALLERINA_DISTRIBUTION_VERSION: 2201.12.0 # Update this with the latest Ballerina version
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
if: github.repository_owner == 'ballerina-platform'
20+
steps:
21+
- name: Checkout Repository
22+
uses: actions/checkout@v3
23+
- name: Set up JDK 21
24+
uses: actions/setup-java@v3
25+
with:
26+
distribution: 'temurin'
27+
java-version: 21.0.3
28+
- name: Set up Ballerina
29+
if: github.event_name == 'workflow_dispatch'
30+
uses: ballerina-platform/setup-ballerina@v1.1.3
31+
with:
32+
version: ${{ github.event.inputs.ballerina_version }}
33+
- name: Set up Ballerina
34+
if: github.event_name == 'schedule'
35+
uses: ballerina-platform/setup-ballerina@v1.1.3
36+
with:
37+
version: ${{ env.BALLERINA_DISTRIBUTION_VERSION }}
38+
- name: Change to Timestamped Version
39+
run: |
40+
startTime=$(TZ="Asia/Kolkata" date +'%Y%m%d-%H%M00')
41+
latestCommit=$(git log -n 1 --pretty=format:"%h")
42+
VERSION=$((grep -w 'version' | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev)
43+
updatedVersion=$VERSION-$startTime-$latestCommit
44+
echo $updatedVersion
45+
echo TIMESTAMPED_VERSION=$updatedVersion >> $GITHUB_ENV
46+
sed -i "s/version=\(.*\)/version=$updatedVersion/g" gradle.properties
47+
- name: Grant execute permission for gradlew
48+
run: chmod +x gradlew
49+
- name: Set Docker Host env variable
50+
run: echo "DOCKER_HOST=$(docker context ls --format '{{print .DockerEndpoint}}' | tr -d '\n')" >> $GITHUB_ENV
51+
- name: Build with Gradle
52+
env:
53+
DOCKER_HOST: unix:///var/run/docker.sock
54+
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
55+
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
56+
packagePublishRepo: ${{ github.repository }}
57+
run: |
58+
./gradlew clean build publish --stacktrace --scan --console=plain --no-daemon
59+
./gradlew codeCoverageReport --console=plain --no-daemon
60+
- name: Upload Coverage Report
61+
uses: codecov/codecov-action@v4
62+
with:
63+
files: ballerina-tests/moesif-server-tests/target/report/moesif_server_tests/coverage-report.xml
64+
- name: Notify failure
65+
if: ${{ failure() }}
66+
run: |
67+
curl -X POST \
68+
'https://api.github.com/repos/ballerina-platform/ballerina-release/dispatches' \
69+
-H 'Accept: application/vnd.github.v3+json' \
70+
-H 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \
71+
--data "{
72+
\"event_type\": \"notify-build-failure\",
73+
\"client_payload\": {
74+
\"repoName\": \"module-ballerinax-moesif\"
75+
}
76+
}"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: GraalVM Check
2+
3+
on:
4+
schedule:
5+
- cron: '30 18 * * *'
6+
workflow_dispatch:
7+
inputs:
8+
ballerina_version:
9+
description: 'Ballerina version'
10+
required: true
11+
default: '2201.11.0'
12+
13+
env:
14+
BALLERINA_DISTRIBUTION_VERSION: 2201.12.8 # Update this with the latest Ballerina version
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up GraalVM
23+
uses: graalvm/setup-graalvm@v1
24+
with:
25+
version: 'latest'
26+
java-version: '21.0.3'
27+
components: 'native-image'
28+
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Check GraalVM installation
30+
run: |
31+
echo "GRAALVM_HOME: ${{ env.GRAALVM_HOME }}"
32+
echo "JAVA_HOME: ${{ env.JAVA_HOME }}"
33+
native-image --version
34+
- name: Set up Ballerina
35+
if: github.event_name == 'workflow_dispatch'
36+
uses: ballerina-platform/setup-ballerina@v1.1.3
37+
with:
38+
version: ${{ github.event.inputs.ballerina_version }}
39+
- name: Set up Ballerina
40+
if: github.event_name == 'schedule'
41+
uses: ballerina-platform/setup-ballerina@v1.1.3
42+
with:
43+
version: ${{ env.BALLERINA_DISTRIBUTION_VERSION }}
44+
- name: Grant execute permission for gradlew
45+
run: chmod +x gradlew
46+
- name: Build with Gradle
47+
env:
48+
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
49+
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
50+
JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true
51+
run: |
52+
./gradlew build
53+
- name: Update dependency versions
54+
run: ./gradlew :moesif-extension-ballerina:updateTomlVerions
55+
env:
56+
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
57+
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
58+
JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true
59+
- name: Run Ballerina build using the native executable
60+
run: bal build --native ./ballerina
61+
- name: Run Ballerina tests using the native executable
62+
run: bal test --native ./ballerina
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Publish Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
distribution_version:
7+
description: 'Ballerina distribution version (e.g.; 2201.9.0)'
8+
required: true
9+
default: '2201.11.0'
10+
11+
jobs:
12+
publish-release:
13+
runs-on: ubuntu-latest
14+
if: github.repository_owner == 'ballerina-platform'
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v3
18+
- name: Set up JDK 21
19+
uses: actions/setup-java@v3
20+
with:
21+
distribution: 'temurin'
22+
java-version: 21.0.3
23+
- name: Set up Ballerina
24+
uses: ballerina-platform/setup-ballerina@v1.1.3
25+
with:
26+
version: ${{ github.event.inputs.distribution_version }}
27+
- name: Set version env variable
28+
run: echo "VERSION=$((grep -w 'version' | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev)" >> $GITHUB_ENV
29+
- name: Pre release depenency version update
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
32+
run: |
33+
echo "Version: ${VERSION}"
34+
git config user.name ${{ secrets.BALLERINA_BOT_USERNAME }}
35+
git config user.email ${{ secrets.BALLERINA_BOT_EMAIL }}
36+
git checkout -b release-${VERSION}
37+
git add gradle.properties
38+
git commit -m "Move dependencies to stable version" || echo "No changes to commit"
39+
- name: Grant execute permission for gradlew
40+
run: chmod +x gradlew
41+
- name: Set Docker Host env variable
42+
run: echo "DOCKER_HOST=$(docker context ls --format '{{print .DockerEndpoint}}' | tr -d '\n')" >> $GITHUB_ENV
43+
- name: Build with Gradle
44+
env:
45+
packageUser: ${{ github.actor }}
46+
packagePAT: ${{ secrets.GITHUB_TOKEN }}
47+
run: ./gradlew build -x check -x test
48+
- name: Run Trivy vulnerability scanner
49+
uses: aquasecurity/trivy-action@master
50+
with:
51+
scan-type: 'fs'
52+
scan-ref: '.'
53+
format: 'table'
54+
timeout: '10m0s'
55+
exit-code: '1'
56+
- name: Publish artifact
57+
env:
58+
DOCKER_HOST: unix:///var/run/docker.sock
59+
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
60+
BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }}
61+
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
62+
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
63+
packagePublishRepo: ${{ github.repository }}
64+
run: |
65+
rm -rf .cache
66+
rm -rf trivy
67+
git stash
68+
./gradlew release -Prelease.useAutomaticVersion=true
69+
./gradlew -Pversion=${VERSION} publish -x test
70+
- name: Create Github release from the release tag
71+
run: |
72+
curl --request POST 'https://api.github.com/repos/${{ github.repository }}/releases' \
73+
--header 'Accept: application/vnd.github.v3+json' \
74+
--header 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \
75+
--header 'Content-Type: application/json' \
76+
--data-raw '{
77+
"tag_name": "v'"$VERSION"'",
78+
"name": "module-ballerinax-moesif-v'"$VERSION"'"
79+
}'
80+
- name: Post release PR
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
83+
run: |
84+
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
85+
bin/hub pull-request --base main -m "[Automated] Sync master after "$VERSION" release"

0 commit comments

Comments
 (0)