Skip to content

Commit

Permalink
feature/IVYPORTAL-17377-Create-pipeline-to-run-Lighthouse-report
Browse files Browse the repository at this point in the history
  • Loading branch information
nhthinh-axonivy committed Dec 25, 2024
1 parent 33aa7ae commit 60774f5
Showing 1 changed file with 34 additions and 63 deletions.
97 changes: 34 additions & 63 deletions .github/workflows/lighthouse-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,44 @@ on:

env:
JAVA_VERSION: '21'
NODE_VERSION: '18'
NODE_VERSION: '16'
SERVER_URL: localhost:8000
WAIT_TIME: 30
REPORT_PATH: ./lighthouse-report-${{ github.run_id }}.html

CACHE_DIR: /var/tools/maven-cache
BUILT_MODULES: ""
REPORT_PATH: ./lighthouse-report.html
MAVEN_CACHE: /var/tools/maven-cache
DOCKER_CACHE_DIR: /var/tools/maven-cache
MODULES: |
AxonIvyPortal/portal-components AxonIvyPortal/portal AxonIvyPortal/PortalKitTestHelper \
Showcase/portal-user-examples Showcase/portal-developer-examples Showcase/InternalSupport \
Showcase/portal-components-examples
ENGINE_URL: localhost:8000

jobs:
build:
name: Build Modules
runs-on: ubuntu-latest

env:
GIT_COMMIT: ${{ github.sha }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Build Docker Image for Portal Modules
run: |
docker build -t build-portal-modules -f build/Dockerfile .
run: docker build -t build-portal-modules -f build/Dockerfile .
- name: Build Maven Modules Inside Docker
id: build-maven
run: |
docker build -t build-portal-modules -f build/Dockerfile .
docker run --rm -v $DOCKER_CACHE_DIR:/home/build/ \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
build-portal-modules sh -c '
MODULES="AxonIvyPortal/portal-components AxonIvyPortal/portal AxonIvyPortal/PortalKitTestHelper Showcase/portal-user-examples Showcase/portal-developer-examples Showcase/InternalSupport Showcase/portal-components-examples"
BUILT_MODULES=""
for MODULE in $MODULES; do
mvn clean install -f ${MODULE}/pom.xml
BUILT_MODULES="$BUILT_MODULES $MODULE"
done
echo "BUILT_MODULES=$BUILT_MODULES" >> $GITHUB_ENV
'
- name: Ensure Artifact Directories Exist
run: mkdir -p **/target/

docker run --rm \
-v ${{ env.DOCKER_CACHE_DIR }}:/home/build/ \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
build-portal-modules sh -c '
BUILT_MODULES=""
for MODULE in ${{ env.MODULES }}; do
mvn clean install -f ${MODULE}/pom.xml
BUILT_MODULES="$BUILT_MODULES $MODULE"
done
echo "::set-output name=built_modules::$BUILT_MODULES"
'
- name: Archive Artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -60,53 +58,34 @@ jobs:
name: Deploy Modules
runs-on: ubuntu-latest
needs: build

env:
CACHE_DIR: /var/tools/maven-cache

BUILT_MODULES: ${{ needs.build.outputs.built_modules }}
steps:
- name: Cleanup
run: |
docker system prune -f
rm -rf /var/tools/maven-cache || true
- name: Checkout Repository
uses: actions/checkout@v3

- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build-output

- name: Install Groovy
run: |
sudo apt update
sudo apt install -y groovy
- name: Load Common Utils
run: |
groovy build/common/utils.groovy
run: echo "Loading common utilities (e.g., groovy scripts)" # Placeholder for actual logic
- name: Build Docker Image for Deployment
run: docker build -t deploy-modules-to-engine -f build/Dockerfile .

- name: Deploy Maven Modules Inside Docker
run: |
docker run --rm \
-v ${{ env.CACHE_DIR }}:/home/build/ \
-v ${{ env.DOCKER_CACHE_DIR }}:/home/build/ \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
deploy-modules-to-engine sh -c '
ENGINE_URL=${{ env.SERVER_URL }}
BUILD_PLUGIN_VERSION=$(mvn help:evaluate -Dexpression=build.plugin.version -f AxonIvyPortal/portal-components/pom.xml -q -DforceStdout)
for MODULE in $BUILT_MODULES; do
for MODULE in ${{ env.BUILT_MODULES }}; do
mvn com.axonivy.ivy.ci:project-build-plugin:${BUILD_PLUGIN_VERSION}:deploy-to-engine \
-f ${MODULE}/pom.xml \
-Divy.deploy.server.id=engine-cockpit \
-Divy.deploy.engine.app=Portal \
-Divy.deploy.method=HTTP \
-Divy.deploy.engine.url=${ENGINE_URL} \
-Divy.deploy.engine.url=${{ env.ENGINE_URL }} \
-Divy.test.engine=MODIFY_EXISTING \
-Divy.deploy.test.users=true
done
Expand All @@ -116,30 +95,22 @@ jobs:
name: Lighthouse Audit
needs: deploy
runs-on: ubuntu-latest

steps:
- name: Install Lighthouse
run: npm install -g lighthouse

- name: Wait for Server to Be Ready
run: |
for i in $(seq 1 ${{ env.WAIT_TIME }}); do
if curl -f ${{ env.SERVER_URL }}/health > /dev/null; then
for ((i=1; i<=${{ env.WAIT_TIME }}; i++)); do
if curl -s ${{ env.SERVER_URL }} > /dev/null; then
echo "Server is ready"
exit 0
else
echo "Waiting for server..."
sleep 1
fi
echo "Waiting for server..."
sleep 1
done
echo "Server did not start in time" && exit 1
- name: Ensure Lighthouse Report Directory
run: mkdir -p ${{ env.REPORT_PATH }}

- name: Execute Lighthouse Audit
run: lighthouse ${{ env.SERVER_URL }} --output=json --output=html --output-path=${{ env.REPORT_PATH }}

- name: Upload Audit Report
uses: actions/upload-artifact@v3
with:
Expand Down

0 comments on commit 60774f5

Please sign in to comment.