From 52da05655f50a650580d8e3348642a79fee90b71 Mon Sep 17 00:00:00 2001 From: asteriskzie Date: Wed, 24 Apr 2024 02:16:22 +0700 Subject: [PATCH] Refactor workflow files --- .../{cloud-run-action.yml => cd.yml} | 2 +- .github/workflows/ci.yml | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) rename .github/workflows/{cloud-run-action.yml => cd.yml} (99%) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/cloud-run-action.yml b/.github/workflows/cd.yml similarity index 99% rename from .github/workflows/cloud-run-action.yml rename to .github/workflows/cd.yml index f2a1e83..47d1fb0 100644 --- a/.github/workflows/cloud-run-action.yml +++ b/.github/workflows/cd.yml @@ -1,4 +1,4 @@ -name: Java CI/CD Pipeline +name: Google Cloud CD Pipeline on: push: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7a4bfbd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,78 @@ +name: Java CI Pipeline + +on: + push: + branches: + - main + - dev + pull_request: + branches: + - main + - dev + workflow_dispatch: + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "21" + cache: "gradle" + + - name: Cache Gradle dependencies + uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Make gradlew executable + run: chmod +x ./gradlew + - name: Build with Gradle + run: | + ./gradlew assemble + # (Optional) Add steps for running tests and generating reports + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: java-app + path: build/libs/*.jar + + test: + name: Test + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "21" + cache: "gradle" + - name: Make gradlew executable + run: chmod +x ./gradlew + - name: Cache Gradle dependencies + uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Test with Gradle + run: | + ./gradlew check --info --stacktrace + ./gradlew test + ./gradlew jacocoTestReport + # (Optional) Add steps for generating coverage report and other post-test tasks