debug #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tickets IFSP API - GHCR | |
on: | |
push: | |
branches: | |
- master | |
- homolog | |
jobs: | |
build: | |
name: Build Jar | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v3 | |
- name: Set up JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '21' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Refresh Gradle dependencies | |
run: ./gradlew --refresh-dependencies | |
- name: Cache Gradle dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/wrapper | |
~/.gradle/caches | |
~/.m2 | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}-java-${{ matrix.java-version }} | |
restore-keys: | | |
${{ runner.os }}-gradle-java-${{ matrix.java-version }}- | |
${{ runner.os }}-gradle- | |
- name: Build the project | |
run: ./gradlew bootJar | |
- name: Save artifact for master branch | |
if: github.ref == 'refs/heads/master' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: jar-artifact | |
path: build/libs/*.jar | |
retention-days: 5 | |
- name: Save artifact for other branches | |
if: github.ref != 'refs/heads/master' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: jar-artifact | |
path: build/libs/*.jar | |
retention-days: 2 | |
docker-build: | |
name: Build and Push Docker Image to GHCR | |
runs-on: ubuntu-latest | |
needs: build | |
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/homolog' | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v3 | |
- name: Download the JAR artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: jar-artifact | |
path: ./build/libs | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to GitHub Container Registry | |
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin | |
- name: Build and push Docker image | |
run: | | |
if [[ "${{ github.ref_name }}" == "master" ]]; then | |
tag="latest" | |
echo "Running on default branch 'master': tag = 'latest'" | |
else | |
tag="${{ github.ref_name }}" | |
echo "Running on branch '${{ github.ref_name }}': tag = '${{ github.ref_name }}'" | |
fi | |
docker build --pull -t ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:$tag . | |
docker push ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:$tag | |
- name: Clean up Docker images | |
run: | | |
docker rmi ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:$tag || true |