From e8b9261775ebbeb9b59ceb94f6ecce3d76e4bb71 Mon Sep 17 00:00:00 2001 From: Maksim Pischulenok Date: Sun, 7 Sep 2025 20:18:24 +0300 Subject: [PATCH 1/2] Fix ci --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa96e65..6f784a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: publish: runs-on: ubuntu-latest + needs: verify if: github.event_name == 'push' && github.ref == 'refs/heads/main' permissions: @@ -36,6 +37,8 @@ jobs: distribution: 'temurin' java-version: '21' cache: 'gradle' + - name: Build with Gradle + run: ./gradlew build - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: From 035137148c931611e61356083903e84210f9c242 Mon Sep 17 00:00:00 2001 From: Maksim Pischulenok Date: Sun, 7 Sep 2025 20:26:28 +0300 Subject: [PATCH 2/2] Refactor ci --- .github/workflows/ci.yaml | 33 +++++++++++++++ .github/workflows/ci.yml | 59 --------------------------- .github/workflows/release.yaml | 73 ++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..2af10f8 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,33 @@ +name: CI Verification + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +# Cancel redundant, in-progress runs for the same branch or PR +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + verify: + name: Build & Test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + cache: 'gradle' + + - name: Verify with Gradle + # The 'build' command will compile, run tests, and package the app. + # If any step fails, the workflow will fail, protecting your main branch. + run: ./gradlew build + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 6f784a7..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: CI - -on: - push: - branches: - - main - pull_request: - -jobs: - verify: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '21' - cache: 'gradle' - - name: Build with Gradle - run: ./gradlew build - - publish: - runs-on: ubuntu-latest - needs: verify - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - - permissions: - contents: read - packages: write - attestations: write - id-token: write - - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '21' - cache: 'gradle' - - name: Build with Gradle - run: ./gradlew build - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and push Docker image - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: ghcr.io/${{ github.repository_owner }}/memevizor:latest - cache-from: type=gha - cache-to: type=gha,mode=max - diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..35c50f5 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,73 @@ +name: Publish Release + +# This workflow is triggered ONLY when a new release is created in GitHub +on: + release: + types: [ created ] + +jobs: + build: + name: Build Release Artifact + runs-on: ubuntu-latest + steps: + - name: Checkout code + # Checks out the specific Git tag associated with the release + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + cache: 'gradle' + + - name: Build with Gradle + run: ./gradlew build + + - name: Upload JAR artifact for publisher job + uses: actions/upload-artifact@v4 + with: + name: app-jar + path: build/libs/*.jar # Adjust path if needed + retention-days: 1 + + publish: + name: Publish to GitHub Container Registry + runs-on: ubuntu-latest + needs: build # This job waits for the 'build' job to succeed + permissions: + contents: read + packages: write + + steps: + - name: Download JAR artifact from build job + uses: actions/download-artifact@v4 + with: + name: app-jar + path: build/libs + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + # Tag with the release version (e.g., v1.2.3) + type=raw,value=${{ github.ref_name }} + # Also tag as 'latest' + type=raw,value=latest + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}