|
| 1 | +# Entirely written by ChatGPT |
| 2 | + |
| 3 | +name: Build and publish release container |
| 4 | + |
| 5 | +on: |
| 6 | + release: |
| 7 | + types: |
| 8 | + - published |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + packages: write |
| 14 | + |
| 15 | +env: |
| 16 | + IMAGE_NAME: fetcharr |
| 17 | + |
| 18 | +jobs: |
| 19 | + docker: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Check out repo at release tag |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + ref: ${{ github.event.release.tag_name }} |
| 27 | + |
| 28 | + - name: Set up Java |
| 29 | + uses: actions/setup-java@v4 |
| 30 | + with: |
| 31 | + distribution: temurin |
| 32 | + java-version: '21' |
| 33 | + cache: maven |
| 34 | + |
| 35 | + - name: Build project |
| 36 | + run: mvn -B clean package |
| 37 | + |
| 38 | + - name: Find main JAR |
| 39 | + id: jar |
| 40 | + shell: bash |
| 41 | + run: | |
| 42 | + set -Eeuo pipefail |
| 43 | + shopt -s nullglob |
| 44 | +
|
| 45 | + candidates=() |
| 46 | + for f in ./App/target/*.jar; do |
| 47 | + name="$(basename "$f")" |
| 48 | + case "$name" in |
| 49 | + *-sources.jar|*-javadoc.jar|*-javadoc-resources.jar|*-test-javadoc-resources.jar|original-*.jar) |
| 50 | + continue |
| 51 | + ;; |
| 52 | + *) |
| 53 | + candidates+=("$f") |
| 54 | + ;; |
| 55 | + esac |
| 56 | + done |
| 57 | +
|
| 58 | + if (( ${#candidates[@]} == 0 )); then |
| 59 | + echo "No usable JAR found in ./App/target" >&2 |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | +
|
| 63 | + jar_file="$(printf '%s\n' "${candidates[@]}" | awk -F/ '{print length($NF), $0}' | sort -n | head -n1 | cut -d' ' -f2-)" |
| 64 | + echo "jar_file=$jar_file" >> "$GITHUB_OUTPUT" |
| 65 | +
|
| 66 | + - name: Derive release version |
| 67 | + id: version |
| 68 | + shell: bash |
| 69 | + run: | |
| 70 | + set -Eeuo pipefail |
| 71 | + version="${{ github.event.release.tag_name }}" |
| 72 | + version="${version#v}" |
| 73 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 74 | +
|
| 75 | + - name: Set up QEMU |
| 76 | + uses: docker/setup-qemu-action@v3 |
| 77 | + |
| 78 | + - name: Set up Buildx |
| 79 | + uses: docker/setup-buildx-action@v3 |
| 80 | + |
| 81 | + - name: Log in to Docker Hub |
| 82 | + uses: docker/login-action@v3 |
| 83 | + with: |
| 84 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 85 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 86 | + |
| 87 | + - name: Log in to GHCR |
| 88 | + uses: docker/login-action@v3 |
| 89 | + with: |
| 90 | + registry: ghcr.io |
| 91 | + username: ${{ github.actor }} |
| 92 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + |
| 94 | + - name: Build and push multi-arch release image |
| 95 | + uses: docker/build-push-action@v6 |
| 96 | + with: |
| 97 | + context: . |
| 98 | + file: ./Containerfile |
| 99 | + push: true |
| 100 | + platforms: linux/amd64,linux/arm64,linux/ppc64le |
| 101 | + build-args: | |
| 102 | + JAR_FILE=${{ steps.jar.outputs.jar_file }} |
| 103 | + tags: | |
| 104 | + docker.io/egg82/fetcharr:${{ steps.version.outputs.version }} |
| 105 | + docker.io/egg82/fetcharr:latest |
| 106 | + ghcr.io/${{ github.repository_owner }}/fetcharr:${{ steps.version.outputs.version }} |
| 107 | + ghcr.io/${{ github.repository_owner }}/fetcharr:latest |
| 108 | + cache-from: type=gha |
| 109 | + cache-to: type=gha,mode=max |
0 commit comments