From 2a8a205f7b52ea3fd08b5350dabcd692325bce7a Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Tue, 20 Aug 2024 09:18:19 +0530 Subject: [PATCH 1/7] build: add PR builder for the project --- .github/workflows/pr-builder.yml | 85 +++++++++++++++++++ .../scripts/android/android_sdk_build.sh | 77 +++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 .github/workflows/pr-builder.yml create mode 100644 .github/workflows/scripts/android/android_sdk_build.sh diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml new file mode 100644 index 0000000..6b91fbd --- /dev/null +++ b/.github/workflows/pr-builder.yml @@ -0,0 +1,85 @@ +# ------------------------------------------------------------------------------------- +# +# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------------------------------- + +# This workflow will run the build for PRs to check for any build related issues. + +name: 👷 PR Builder + +on: + pull_request: + types: [ opened, synchronize, labeled ] + branches: [ main ] + paths-ignore: + - "**/*.md" + - "**/LICENSE" + +concurrency: + group: pr-builder-${{ github.ref }} + cancel-in-progress: true + +env: + GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }} + +jobs: + check_for_android_changes: + name: 🤖 🔄 Check for Android Changes + runs-on: ubuntu-latest + outputs: + android_changed: ${{ steps.validate_android_changes.outputs.android_changed }} + steps: + - name: ⬇️ Checkout + id: checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + # token: ${{ env.GH_TOKEN }} + + - name: ✅ Validate Android Changes + id: validate_android_changes + run: | + echo "Checking for Android changes" + android_changed=false + if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q "android"; then + android_changed=true + fi + echo "android_changed=${android_changed}" >> $GITHUB_OUTPUT + + asgardeo-android-sdk-builder: + name: 🤖 🚧 Asgardeo Android SDK Builder + needs: check_for_android_changes + if: needs.check_for_android_changes.outputs.android_changed == 'true' + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout + id: checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + # token: ${{ env.GH_TOKEN }} + + - name: ☕️ Set up Adopt JDK 17 + uses: actions/setup-java@v3 + with: + java-version: "17" + distribution: "adopt" + + - name: 🚧 Build Asgardeo Android SDK + working-directory: .github/workflows/scripts/android + run: bash ./android_sdk_build.sh diff --git a/.github/workflows/scripts/android/android_sdk_build.sh b/.github/workflows/scripts/android/android_sdk_build.sh new file mode 100644 index 0000000..8c01b98 --- /dev/null +++ b/.github/workflows/scripts/android/android_sdk_build.sh @@ -0,0 +1,77 @@ +# ------------------------------------------------------------------------------------- +# +# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------------------------------- + +#!/bin/bash + +# Go to android sdk directory +go_to_android_sdk_dir() { + cd ../../../../android +} + +# Function to regenerate Gradle wrapper +regenerate_gradle_wrapper() { + echo + ./gradlew wrapper +} + +# Function to check Gradle wrapper +check_gradle_wrapper() { + echo + if [ ! -f "./gradlew" ]; then + echo "Gradle wrapper (./gradlew) not found. Please regenerate using './gradlew wrapper'" + exit 1 + fi + + echo "Gradle Wrapper - OK" + + if [ ! -f "./gradlew.bat" ]; then + echo "Gradle wrapper (./gradlew.bat) not found. Please regenerate using './gradlew wrapper'" + exit 1 + fi + + echo "Gradle Wrapper (Windows) - OK" + + ./gradlew --version + if [ $? -ne 0 ]; then + echo "Error: Gradle wrapper execution failed. Please check Gradle installation and configuration." + exit 1 + fi + echo "Gradle Wrapper - OK" +} + +# Function to build with Gradle +gradle_build() { + echo + ./gradlew clean build +} + +# run gradle tasks to build Android SDKs +build_android_sdks() { + # Go to android sdk directory + go_to_android_sdk_dir + + # Functions to release Android SDKs + regenerate_gradle_wrapper + check_gradle_wrapper + gradle_build +} + +# Call the functions in sequence +build_android_sdks From de477967102321be28d613775ab5a069c785a335 Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Tue, 20 Aug 2024 13:50:19 +0530 Subject: [PATCH 2/7] uild: add documentation PR builder check --- .github/workflows/deploy-gh-pages.yml | 3 +- .github/workflows/pr-builder.yml | 124 +++++++++++++++++++++----- .github/workflows/release.yml | 3 +- 3 files changed, 105 insertions(+), 25 deletions(-) diff --git a/.github/workflows/deploy-gh-pages.yml b/.github/workflows/deploy-gh-pages.yml index ff46923..dd81a2e 100644 --- a/.github/workflows/deploy-gh-pages.yml +++ b/.github/workflows/deploy-gh-pages.yml @@ -39,6 +39,7 @@ concurrency: env: GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }} DOC_DIR: docs + DOCS_SCRIPT_DIR: .github/workflows/scripts/docs jobs: deploy: @@ -85,7 +86,7 @@ jobs: distribution: "adopt" - name: 🤖 Generate Android SDK API Docs - working-directory: .github/workflows/scripts/docs/android + working-directory: ${{ env.DOCS_SCRIPT_DIR }}/android run: bash ./dokka_build.sh - name: 🌩 Upload artifact diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml index 6b91fbd..5ff94a2 100644 --- a/.github/workflows/pr-builder.yml +++ b/.github/workflows/pr-builder.yml @@ -27,7 +27,6 @@ on: types: [ opened, synchronize, labeled ] branches: [ main ] paths-ignore: - - "**/*.md" - "**/LICENSE" concurrency: @@ -36,35 +35,71 @@ concurrency: env: GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }} + ANDROID_SCRIPT_DIR: .github/workflows/scripts/android + DOCS_SCRIPT_DIR: .github/workflows/scripts/docs + DOC_DIR: docs jobs: - check_for_android_changes: - name: 🤖 🔄 Check for Android Changes + check_for_relevant_changes: + name: 🔄 Check for Relevant Changes runs-on: ubuntu-latest outputs: - android_changed: ${{ steps.validate_android_changes.outputs.android_changed }} + android_changed: ${{ steps.check_android_changes.outputs.android_changed }} + documentation_changed: ${{ steps.check_documentation_changes.outputs.documentation_changed }} steps: - - name: ⬇️ Checkout - id: checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - # token: ${{ env.GH_TOKEN }} + - name: ⬇️ Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ env.GH_TOKEN }} - - name: ✅ Validate Android Changes - id: validate_android_changes - run: | - echo "Checking for Android changes" - android_changed=false - if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q "android"; then - android_changed=true - fi - echo "android_changed=${android_changed}" >> $GITHUB_OUTPUT + - name: 🌴 Fetch PR branch + run: | + if [ ${{ github.event.pull_request.head.repo.fork }} == true ]; then + git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} + else + git fetch origin ${{ github.head_ref }} + fi + + - name: 🗃️ Get changed files + id: changed-files + run: | + if [ ${{ github.event.pull_request.head.repo.fork }} == true ]; then + echo "Comparing changes for PR from fork" + git diff --name-only origin/${{ github.base_ref }}..pr-${{ github.event.pull_request.number }} > changed_files.txt + else + echo "Comparing changes for internal PR" + git diff --name-only origin/${{ github.base_ref }}..origin/${{ github.head_ref }} > changed_files.txt + fi + echo "Changed files:" + cat changed_files.txt + + - name: 🤖 Check for Android Changes + id: check_android_changes + run: | + echo "Checking for Android changes" + android_changed=false + if grep -q "android/" changed_files.txt; then + android_changed=true + echo "Android changes detected" + fi + echo "android_changed=${android_changed}" >> $GITHUB_OUTPUT + + - name: 📑 Check for Documentation Changes + id: check_documentation_changes + run: | + echo "Checking for Documentation changes" + documentation_changed=false + if grep -q "docs/" changed_files.txt; then + documentation_changed=true + echo "Documentation changes detected" + fi + echo "documentation_changed=${documentation_changed}" >> $GITHUB_OUTPUT asgardeo-android-sdk-builder: name: 🤖 🚧 Asgardeo Android SDK Builder - needs: check_for_android_changes - if: needs.check_for_android_changes.outputs.android_changed == 'true' + needs: check_for_relevant_changes + if: needs.check_for_relevant_changes.outputs.android_changed == 'true' runs-on: ubuntu-latest steps: - name: ⬇️ Checkout @@ -72,7 +107,7 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 - # token: ${{ env.GH_TOKEN }} + token: ${{ env.GH_TOKEN }} - name: ☕️ Set up Adopt JDK 17 uses: actions/setup-java@v3 @@ -81,5 +116,48 @@ jobs: distribution: "adopt" - name: 🚧 Build Asgardeo Android SDK - working-directory: .github/workflows/scripts/android + working-directory: ${{ env.ANDROID_SCRIPT_DIR }} run: bash ./android_sdk_build.sh + + documentation-builder: + name: 📑 🚧 Documentation Builder + needs: check_for_relevant_changes + if: needs.check_for_relevant_changes.outputs.documentation_changed == 'true' + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [lts/*] + steps: + - name: ⬇️ Checkout + id: checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ env.GH_TOKEN }} + + - name: 🟢 Setup node + id: setup-node + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: 🧩 Install Dependencies + id: install-dependencies + working-directory: ${{ env.DOC_DIR }} + run: npm ci + + - name: 🏗️ Build with VitePress + id: build + working-directory: ${{ env.DOC_DIR }} + run: | + npm run docs:build + + - name: ☕️ Set up Adopt JDK 17 (For Android SDK API Docs Generation) + uses: actions/setup-java@v3 + with: + java-version: "17" + distribution: "adopt" + + - name: 🤖 Generate Android SDK API Docs + working-directory: ${{ env.DOCS_SCRIPT_DIR }}/android + run: bash ./dokka_build.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5bb7110..4a7e6b0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -46,6 +46,7 @@ env: BOT_EMAIL: ${{ secrets.RELEASE_BOT_EMAIL }} NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} + ANDROID_SCRIPT_DIR: .github/workflows/scripts/android jobs: release: @@ -73,6 +74,6 @@ jobs: distribution: "adopt" - name: 🤖 Release Android SDKs - working-directory: .github/workflows/scripts/android + working-directory: ${{ env.ANDROID_SCRIPT_DIR }} if: ${{ github.event.inputs.sdkType == 'android' }} run: bash ./android_sdk_release.sh ${{ github.event.inputs.version }} ${{ env.NEXUS_USERNAME }} ${{ env.NEXUS_PASSWORD }} ${{ env.GH_TOKEN }} ${{ github.run_number }} ${{ github.repository }} From ef4fcd975957079989388ba9ae34a22e4f02ee4c Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Tue, 20 Aug 2024 15:27:28 +0530 Subject: [PATCH 3/7] build: update PR builder --- .github/workflows/pr-builder.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml index 5ff94a2..19543e1 100644 --- a/.github/workflows/pr-builder.yml +++ b/.github/workflows/pr-builder.yml @@ -60,6 +60,8 @@ jobs: else git fetch origin ${{ github.head_ref }} fi + with: + token: ${{ env.GH_TOKEN }} - name: 🗃️ Get changed files id: changed-files @@ -73,6 +75,8 @@ jobs: fi echo "Changed files:" cat changed_files.txt + with: + token: ${{ env.GH_TOKEN }} - name: 🤖 Check for Android Changes id: check_android_changes From 34e32ad282385434e9952535023ca8013d684a85 Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Tue, 20 Aug 2024 15:28:55 +0530 Subject: [PATCH 4/7] build: update PR builder --- .github/workflows/pr-builder.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml index 19543e1..5ff94a2 100644 --- a/.github/workflows/pr-builder.yml +++ b/.github/workflows/pr-builder.yml @@ -60,8 +60,6 @@ jobs: else git fetch origin ${{ github.head_ref }} fi - with: - token: ${{ env.GH_TOKEN }} - name: 🗃️ Get changed files id: changed-files @@ -75,8 +73,6 @@ jobs: fi echo "Changed files:" cat changed_files.txt - with: - token: ${{ env.GH_TOKEN }} - name: 🤖 Check for Android Changes id: check_android_changes From a6d3ff8e7f1e419328bb0ee937f6baf64b62b18b Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Tue, 20 Aug 2024 15:38:36 +0530 Subject: [PATCH 5/7] build: update PR builder --- .github/workflows/pr-builder.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml index 5ff94a2..6473bbf 100644 --- a/.github/workflows/pr-builder.yml +++ b/.github/workflows/pr-builder.yml @@ -50,8 +50,8 @@ jobs: - name: ⬇️ Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 token: ${{ env.GH_TOKEN }} + fetch-depth: 0 - name: 🌴 Fetch PR branch run: | @@ -106,8 +106,8 @@ jobs: id: checkout uses: actions/checkout@v3 with: - fetch-depth: 0 token: ${{ env.GH_TOKEN }} + fetch-depth: 0 - name: ☕️ Set up Adopt JDK 17 uses: actions/setup-java@v3 @@ -132,8 +132,8 @@ jobs: id: checkout uses: actions/checkout@v3 with: - fetch-depth: 0 token: ${{ env.GH_TOKEN }} + fetch-depth: 0 - name: 🟢 Setup node id: setup-node From 84e2b874c92873981aedac2c86b83b573516cae5 Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Tue, 20 Aug 2024 15:40:18 +0530 Subject: [PATCH 6/7] build: fix indentation issue --- .github/workflows/pr-builder.yml | 8 ++++---- .github/workflows/release.yml | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml index 6473bbf..e38f201 100644 --- a/.github/workflows/pr-builder.yml +++ b/.github/workflows/pr-builder.yml @@ -34,10 +34,10 @@ concurrency: cancel-in-progress: true env: - GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }} - ANDROID_SCRIPT_DIR: .github/workflows/scripts/android - DOCS_SCRIPT_DIR: .github/workflows/scripts/docs - DOC_DIR: docs + GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }} + ANDROID_SCRIPT_DIR: .github/workflows/scripts/android + DOCS_SCRIPT_DIR: .github/workflows/scripts/docs + DOC_DIR: docs jobs: check_for_relevant_changes: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4a7e6b0..7da5d68 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,12 +41,12 @@ on: - patch env: - GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }} - BOT_USERNAME: ${{ secrets.RELEASE_BOT_USER_NAME }} - BOT_EMAIL: ${{ secrets.RELEASE_BOT_EMAIL }} - NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} - NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} - ANDROID_SCRIPT_DIR: .github/workflows/scripts/android + GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }} + BOT_USERNAME: ${{ secrets.RELEASE_BOT_USER_NAME }} + BOT_EMAIL: ${{ secrets.RELEASE_BOT_EMAIL }} + NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} + NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} + ANDROID_SCRIPT_DIR: .github/workflows/scripts/android jobs: release: From 869590ee84080b7793cad437f8c452f5ec3f01aa Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Tue, 20 Aug 2024 16:04:51 +0530 Subject: [PATCH 7/7] chore(build): fix PR comments --- .github/workflows/pr-builder.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml index e38f201..7e95ca9 100644 --- a/.github/workflows/pr-builder.yml +++ b/.github/workflows/pr-builder.yml @@ -67,9 +67,6 @@ jobs: if [ ${{ github.event.pull_request.head.repo.fork }} == true ]; then echo "Comparing changes for PR from fork" git diff --name-only origin/${{ github.base_ref }}..pr-${{ github.event.pull_request.number }} > changed_files.txt - else - echo "Comparing changes for internal PR" - git diff --name-only origin/${{ github.base_ref }}..origin/${{ github.head_ref }} > changed_files.txt fi echo "Changed files:" cat changed_files.txt