|
| 1 | +name: Build and Publish Docker Image and JAR |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v2 |
| 17 | + |
| 18 | + # --- Gradle Build --- |
| 19 | + - name: Set up JDK 17 |
| 20 | + uses: actions/setup-java@v2 |
| 21 | + with: |
| 22 | + distribution: 'temurin' |
| 23 | + java-version: '17' |
| 24 | + |
| 25 | + - name: Grant execute permission to Gradle Wrapper |
| 26 | + run: chmod +x gradlew |
| 27 | + |
| 28 | + - name: Build with Gradle |
| 29 | + run: ./gradlew build |
| 30 | + |
| 31 | + - name: Find built JAR |
| 32 | + id: find_jar |
| 33 | + run: echo "JAR_PATH=$(find build/libs -name '*.jar' | head -n 1)" >> $GITHUB_ENV |
| 34 | + |
| 35 | + # --- Docker Build & Push --- |
| 36 | + - name: Set up Docker Buildx |
| 37 | + uses: docker/setup-buildx-action@v1 |
| 38 | + |
| 39 | + - name: Log in to GitHub Container Registry |
| 40 | + uses: docker/login-action@v2 |
| 41 | + with: |
| 42 | + registry: ghcr.io |
| 43 | + username: ${{ github.actor }} |
| 44 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Build Docker image |
| 47 | + run: | |
| 48 | + docker build -t ghcr.io/${{ github.repository_owner }}/docktainer:${{ github.sha }} . |
| 49 | +
|
| 50 | + - name: Push Docker image |
| 51 | + run: | |
| 52 | + docker push ghcr.io/${{ github.repository_owner }}/docktainer:${{ github.sha }} |
| 53 | +
|
| 54 | + - name: Tag Docker image with version |
| 55 | + if: startsWith(github.ref, 'refs/tags') |
| 56 | + run: | |
| 57 | + docker tag ghcr.io/${{ github.repository_owner }}/docktainer:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/docktainer:${{ github.ref_name }} |
| 58 | + docker push ghcr.io/${{ github.repository_owner }}/docktainer:${{ github.ref_name }} |
| 59 | +
|
| 60 | + - name: Tag Docker image as latest |
| 61 | + run: | |
| 62 | + docker tag ghcr.io/${{ github.repository_owner }}/docktainer:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/docktainer:latest |
| 63 | + docker push ghcr.io/${{ github.repository_owner }}/docktainer:latest |
| 64 | +
|
| 65 | + release: |
| 66 | + if: startsWith(github.ref, 'refs/tags') |
| 67 | + needs: build |
| 68 | + runs-on: ubuntu-latest |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Checkout code |
| 72 | + uses: actions/checkout@v2 |
| 73 | + |
| 74 | + - name: Find built JAR |
| 75 | + id: find_jar |
| 76 | + run: echo "JAR_PATH=$(find build/libs -name '*.jar' | head -n 1)" >> $GITHUB_ENV |
| 77 | + |
| 78 | + - name: Create GitHub Release |
| 79 | + uses: softprops/action-gh-release@v1 |
| 80 | + with: |
| 81 | + files: ${{ env.JAR_PATH }} |
| 82 | + tag_name: ${{ github.ref_name }} |
| 83 | + release_name: Release ${{ github.ref_name }} |
| 84 | + body: "Automated release for ${{ github.ref_name }}" |
| 85 | + draft: true |
| 86 | + prerelease: false |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments