Update analytics-ci.yml

This commit is contained in:
Unggu 2025-06-12 16:43:17 +09:00 committed by GitHub
parent 59cd7ffde3
commit cbbd0b445a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,110 +16,102 @@ on:
- 'build.gradle' - 'build.gradle'
- 'settings.gradle' - 'settings.gradle'
workflow_dispatch: workflow_dispatch:
env: env:
ACR_NAME: acrdigitalgarage03 ACR_NAME: acrdigitalgarage03
IMAGE_NAME: hiorder/analytics IMAGE_NAME: hiorder/analytics
jobs: jobs:
build-and-push: build-and-push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up JDK 21 - name: Set up JDK 21
uses: actions/setup-java@v4 uses: actions/setup-java@v4
with: with:
java-version: '21' java-version: '21'
distribution: 'temurin' distribution: 'temurin'
- name: Setup Gradle - name: Setup Gradle
uses: gradle/actions/setup-gradle@v3 uses: gradle/actions/setup-gradle@v3
with: with:
gradle-version: '8.13' gradle-version: '8.13'
- name: Cache Gradle packages - name: Cache Gradle packages
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: | path: |
~/.gradle/caches ~/.gradle/caches
~/.gradle/wrapper ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: | restore-keys: |
${{ runner.os }}-gradle- ${{ runner.os }}-gradle-
- name: Check gradle wrapper files - name: Fix Gradle Wrapper
run: | run: |
echo "Checking gradle wrapper files..." echo "Checking gradle wrapper files..."
ls -la gradle/wrapper/ if [ ! -f "gradle/wrapper/gradle-wrapper.jar" ]; then
ls -la gradlew* echo "gradle-wrapper.jar not found, downloading..."
echo "Downloading gradle wrapper if needed..." mkdir -p gradle/wrapper
if [ ! -f "gradle/wrapper/gradle-wrapper.jar" ]; then curl -L -o gradle/wrapper/gradle-wrapper.jar \
echo "gradle-wrapper.jar not found, generating wrapper..." "https://services.gradle.org/distributions/gradle-8.13-wrapper.jar"
gradle wrapper --gradle-version 8.13 fi
fi chmod +x gradlew
echo "Testing gradle wrapper..."
- name: Grant execute permission for gradlew ./gradlew --version
run: chmod +x gradlew
- name: Build analytics module with dependencies
- name: Verify gradle wrapper run: ./gradlew analytics:build -x test
run: |
echo "Testing gradle wrapper..." - name: Run analytics tests
./gradlew --version run: ./gradlew analytics:test
- name: Build common module - name: Generate build timestamp
run: ./gradlew common:build -x test id: timestamp
run: echo "BUILD_TIME=$(date +'%y%m%d%H%M')" >> $GITHUB_OUTPUT
- name: Build analytics module
run: ./gradlew analytics:build -x test - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Run analytics tests
run: ./gradlew analytics:test - name: Log in to Azure Container Registry
uses: azure/docker-login@v1
- name: Generate build timestamp with:
id: timestamp login-server: ${{ env.ACR_NAME }}.azurecr.io
run: echo "BUILD_TIME=$(date +'%y%m%d%H%M')" >> $GITHUB_OUTPUT username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 - name: Build and push Docker image
uses: docker/build-push-action@v5
- name: Log in to Azure Container Registry with:
uses: azure/docker-login@v1 context: .
with: file: ./analytics/Dockerfile
login-server: ${{ env.ACR_NAME }}.azurecr.io platforms: linux/amd64
username: ${{ secrets.ACR_USERNAME }} push: true
password: ${{ secrets.ACR_PASSWORD }} tags: |
${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.BUILD_TIME }}
- name: Build and push Docker image ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:latest
uses: docker/build-push-action@v5 cache-from: type=gha
with: cache-to: type=gha,mode=max
context: .
file: ./analytics/Dockerfile - name: Output image tags
platforms: linux/amd64 run: |
push: true echo "🎉 Image pushed successfully!"
tags: | echo "📦 Image: ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}"
${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.BUILD_TIME }} echo "🏷️ Tags: ${{ steps.timestamp.outputs.BUILD_TIME }}, latest"
${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha - name: Upload test results
cache-to: type=gha,mode=max uses: actions/upload-artifact@v4
if: always()
- name: Output image tags with:
run: | name: analytics-test-results
echo "🎉 Image pushed successfully!" path: analytics/build/reports/tests/test/
echo "📦 Image: ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}"
echo "🏷️ Tags: ${{ steps.timestamp.outputs.BUILD_TIME }}, latest" - name: Upload build artifacts
uses: actions/upload-artifact@v4
- name: Upload test results if: success()
uses: actions/upload-artifact@v4 with:
if: always() name: analytics-jar
with: path: analytics/build/libs/*.jar
name: analytics-test-results
path: analytics/build/reports/tests/test/
- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: success()
with:
name: analytics-jar
path: analytics/build/libs/*.jar