diff --git a/.github/workflows/lighthouse-report.yml b/.github/workflows/lighthouse-report.yml index d8cf454b27..70efe3a0f6 100644 --- a/.github/workflows/lighthouse-report.yml +++ b/.github/workflows/lighthouse-report.yml @@ -8,105 +8,120 @@ on: branches: - master -env: # Define reusable environment variables +env: JAVA_VERSION: '21' NODE_VERSION: '16' SERVER_URL: localhost:8000 - WAIT_TIME: 30 # Time to wait for server to be ready + WAIT_TIME: 30 REPORT_PATH: ./lighthouse-report.html MAVEN_CACHE: /var/tools/maven-cache jobs: - lighthouse-audit: # Renamed job for clarity + build: + name: Build Modules runs-on: ubuntu-latest + + env: + DOCKER_CACHE_DIR: /var/tools/maven-cache + GIT_COMMIT: ${{ github.sha }} + BUILT_MODULES: "" + steps: - - - name: checkout to master + - name: Checkout Repository uses: actions/checkout@v3 - with: - repository: ${{ github.repository }} - ref: 'master' - - name: Setup Java & Maven dependency caching - uses: actions/setup-java@v3 + - name: Build Docker Image for Portal Modules + run: docker build -t build-portal-modules -f build/Dockerfile . + + - name: Build Maven Modules Inside Docker + run: | + 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: Archive Artifacts + uses: actions/upload-artifact@v3 with: - distribution: 'temurin' - java-version: ${{ env.JAVA_VERSION }} + name: build-output + path: '**/*/target/*.iar' - - name: Setup Node.js and Install Lighthouse CLI - uses: actions/setup-node@v3 + deploy: + name: Deploy Modules + runs-on: ubuntu-latest + needs: build + + env: + DOCKER_CACHE_DIR: /var/tools/maven-cache + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Download Build Artifacts + uses: actions/download-artifact@v3 with: - node-version: ${{ env.NODE_VERSION }} - - run: npm install -g lighthouse + name: build-output - - name: Set up docker and Maven + - name: Load Common Utils run: | - sudo apt-get update - sudo apt-get install -y maven docker-compose - docker --version - mvn --version + echo "Loading common utils" + # Simulate loading 'utils.groovy' + + - name: Build Docker Image for Deployment + run: docker build -t deploy-modules-to-engine -f build/Dockerfile . - - name: Build Modules + - name: Deploy Maven Modules Inside Docker run: | - DOCKER_IMAGE="build-portal-modules" - DOCKERFILE_PATH="build/Dockerfile" - MODULES="AxonIvyPortal/portal-components AxonIvyPortal/portal AxonIvyPortal/PortalKitTestHelper Showcase/portal-user-examples Showcase/portal-developer-examples Showcase/InternalSupport Showcase/portal-components-examples" - MAVEN_CMD="mvn clean install -f" - - docker build -t $DOCKER_IMAGE -f $DOCKERFILE_PATH . - docker run -v ${{ env.MAVEN_CACHE }}:/home/build/ $DOCKER_IMAGE bash -c " - function get_changed_modules() { - echo \$(git diff --name-only \$GITHUB_SHA \$GITHUB_SHA~1) - } - - function build_modules() { - local modules=\"$MODULES\" - local changed_modules=\$(get_changed_modules) - local modules_to_build='' - - for module in \$modules; do - if [[ \$changed_modules == *\$module* || '${{ inputs.modulesMustBeBuilt }}' == *\${module##*/}* ]]; then - $MAVEN_CMD \$module/pom.xml - modules_to_build=\"\$modules_to_build \$module\" - fi + docker run --rm \ + -v $DOCKER_CACHE_DIR:/home/build/ \ + -v ${{ github.workspace }}:/workspace \ + -w /workspace \ + deploy-modules-to-engine sh -c ' + ENGINE_URL="http://jenkins-master:8000" + BUILD_PLUGIN_VERSION=$(mvn help:evaluate -Dexpression=build.plugin.version -f AxonIvyPortal/portal-components/pom.xml -q -DforceStdout) + for MODULE in $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.test.engine=MODIFY_EXISTING \ + -Divy.deploy.test.users=true done + ' - echo \"Built modules: \$modules_to_build\" - } + lighthouse-audit: + name: Lighthouse Audit + needs: deploy + runs-on: ubuntu-latest - build_modules - " + steps: + - name: Install Lighthouse + run: npm install -g lighthouse - - name: Deploy Modules + - name: Wait for Server to Be Ready run: | - maven_cache="${{ env.MAVEN_CACHE }}" - server_url="${{ env.SERVER_URL }}" - docker_image="deploy-modules-to-engine" - docker_file="build/Dockerfile" - - # Build Docker image - docker build -t $docker_image -f $docker_file . - - # Run deployment script inside Docker container - docker run -v "$maven_cache:/home/build/" $docker_image bash -c " - # Extract Maven build plugin version - plugin_version=\$(mvn help:evaluate -Dexpression=build.plugin.version -q -DforceStdout -f AxonIvyPortal/portal-components/pom.xml) - - # Deploy each module to the engine - for module in \$built_modules; do - mvn com.axonivy.ivy.ci:project-build-plugin:\$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=\$server_url \ - -Divy.test.engine=MODIFY_EXISTING \ - -Divy.deploy.test.users=true - done - " - - name: Start Application - run: docker-compose up -d - - name: Wait for Server to Start - run: sleep ${{ env.WAIT_TIME }} + for i in $(seq 1 ${{ env.WAIT_TIME }}); do + if curl -s ${{ env.SERVER_URL }} > /dev/null; then + echo "Server is ready" + exit 0 + else + echo "Waiting for server..." + sleep 1 + fi + done + echo "Server did not start in time" && exit 1 - name: Execute Lighthouse Audit run: lighthouse ${{ env.SERVER_URL }} --output=json --output=html --output-path=${{ env.REPORT_PATH }}