Skip to content

Commit

Permalink
Merge pull request #49 from Achintha444/main
Browse files Browse the repository at this point in the history
build: add PR builder for the project
  • Loading branch information
Achintha444 authored Aug 20, 2024
2 parents 1479407 + 869590e commit 9c219e1
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ concurrency:
env:
GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
DOC_DIR: docs
DOCS_SCRIPT_DIR: .github/workflows/scripts/docs

jobs:
deploy:
Expand Down Expand Up @@ -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
Expand Down
160 changes: 160 additions & 0 deletions .github/workflows/pr-builder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# -------------------------------------------------------------------------------------
#
# 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:
- "**/LICENSE"

concurrency:
group: pr-builder-${{ github.ref }}
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

jobs:
check_for_relevant_changes:
name: 🔄 Check for Relevant Changes
runs-on: ubuntu-latest
outputs:
android_changed: ${{ steps.check_android_changes.outputs.android_changed }}
documentation_changed: ${{ steps.check_documentation_changes.outputs.documentation_changed }}
steps:
- name: ⬇️ Checkout
uses: actions/checkout@v3
with:
token: ${{ env.GH_TOKEN }}
fetch-depth: 0

- 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
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_relevant_changes
if: needs.check_for_relevant_changes.outputs.android_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout
id: checkout
uses: actions/checkout@v3
with:
token: ${{ env.GH_TOKEN }}
fetch-depth: 0

- name: ☕️ Set up Adopt JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "adopt"

- name: 🚧 Build Asgardeo Android SDK
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:
token: ${{ env.GH_TOKEN }}
fetch-depth: 0

- 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
13 changes: 7 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +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 }}
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:
Expand Down Expand Up @@ -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 }}
77 changes: 77 additions & 0 deletions .github/workflows/scripts/android/android_sdk_build.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9c219e1

Please sign in to comment.