|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + packages: write |
| 12 | + |
| 13 | +env: |
| 14 | + REGISTRY: ghcr.io |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-and-push: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Set up JDK |
| 25 | + uses: actions/setup-java@v4 |
| 26 | + with: |
| 27 | + distribution: "temurin" |
| 28 | + java-version: "17" |
| 29 | + cache: gradle |
| 30 | + |
| 31 | + - name: Copy application.yml into runner |
| 32 | + run: | |
| 33 | + mkdir -p src/main/resources |
| 34 | + echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml |
| 35 | +
|
| 36 | + - name: Build + Test(Gradle) |
| 37 | + if: ${{ hashFiles('**/build.gradle*') != '' }} |
| 38 | + run: | |
| 39 | + chmod +x ./gradlew |
| 40 | + ./gradlew clean test |
| 41 | + ./gradlew bootJar |
| 42 | + JAR=$(ls build/libs/*.jar | head -n 1) |
| 43 | + cp "$JAR" app.jar |
| 44 | +
|
| 45 | + - name: Compute image name (change to lowercase) |
| 46 | + id: img |
| 47 | + run: echo "name=${{ env.REGISTRY }}/${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT |
| 48 | + |
| 49 | + - name: Log in to GHCR |
| 50 | + uses: docker/login-action@v3 |
| 51 | + with: |
| 52 | + registry: ${{ env.REGISTRY }} |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GHCR_TOKEN }} |
| 55 | + |
| 56 | + - name: Extract Docker metadata (tags, labels) |
| 57 | + id: meta |
| 58 | + uses: docker/metadata-action@v5 |
| 59 | + with: |
| 60 | + images: ${{ steps.img.outputs.name }} |
| 61 | + tags: | |
| 62 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} |
| 63 | + type=ref,event=tag |
| 64 | + type=sha |
| 65 | +
|
| 66 | + - name: Set up Docker Build |
| 67 | + uses: docker/setup-buildx-action@v3 |
| 68 | + |
| 69 | + - name: Debug paths |
| 70 | + run: | |
| 71 | + pwd |
| 72 | + ls -la |
| 73 | + find . -maxdepth 3 -iname 'Dockerfile' -print |
| 74 | +
|
| 75 | +
|
| 76 | + - name: Build and push |
| 77 | + uses: docker/build-push-action@v6 |
| 78 | + with: |
| 79 | + context: . |
| 80 | + file: ./Dockerfile |
| 81 | + push: ${{ github.event_name != 'pull_request' }} |
| 82 | + tags: ${{ steps.meta.outputs.tags }} |
| 83 | + labels: ${{ steps.meta.outputs.labels }} |
| 84 | + cache-from: type=gha |
| 85 | + cache-to: type=gha,mode=max |
0 commit comments