|
| 1 | +name: Build and Publish Master Container |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + packages: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-publish: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up JDK 23 |
| 21 | + uses: actions/setup-java@v4 |
| 22 | + with: |
| 23 | + java-version: "23" |
| 24 | + distribution: "oracle" |
| 25 | + cache: "maven" |
| 26 | + |
| 27 | + - name: Extract version from pom.xml |
| 28 | + id: extract-version |
| 29 | + run: | |
| 30 | + echo "Extracting version from pom.xml..." |
| 31 | + chmod +x ./mvnw |
| 32 | + VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 33 | + DOCKER_VERSION=${VERSION%-SNAPSHOT} |
| 34 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 35 | + echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT |
| 36 | + echo "Detected version: $VERSION" |
| 37 | + echo "Docker version: $DOCKER_VERSION" |
| 38 | +
|
| 39 | + - name: Build application |
| 40 | + run: ./mvnw --no-transfer-progress clean package -DskipTests |
| 41 | + |
| 42 | + - name: Verify JAR file was created |
| 43 | + run: | |
| 44 | + echo "Checking target directory..." |
| 45 | + ls -la target/ |
| 46 | + echo "Looking for JAR files..." |
| 47 | + find target/ -name "*.jar" -type f |
| 48 | + echo "Verifying specific JAR exists..." |
| 49 | + JAR_FILE="target/wrongsecrets-${{ steps.extract-version.outputs.version }}.jar" |
| 50 | + if [ -f "$JAR_FILE" ]; then |
| 51 | + echo "✅ JAR file found: $JAR_FILE" |
| 52 | + ls -la "$JAR_FILE" |
| 53 | + else |
| 54 | + echo "❌ Expected JAR file not found: $JAR_FILE" |
| 55 | + echo "Available JAR files:" |
| 56 | + find target/ -name "*.jar" -type f || echo "No JAR files found" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Set up Docker Buildx |
| 61 | + uses: docker/setup-buildx-action@v3 |
| 62 | + |
| 63 | + - name: Log in to GitHub Container Registry |
| 64 | + uses: docker/login-action@v3 |
| 65 | + with: |
| 66 | + registry: ghcr.io |
| 67 | + username: ${{ github.actor }} |
| 68 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + |
| 70 | + - name: Extract metadata |
| 71 | + id: meta |
| 72 | + uses: docker/metadata-action@v5 |
| 73 | + with: |
| 74 | + images: ghcr.io/${{ github.repository }}/wrongsecrets-master |
| 75 | + tags: | |
| 76 | + type=ref,event=branch |
| 77 | + type=raw,value=latest-master |
| 78 | + type=sha,prefix={{branch}}- |
| 79 | +
|
| 80 | + - name: Build and push Docker image |
| 81 | + id: build |
| 82 | + uses: docker/build-push-action@v5 |
| 83 | + with: |
| 84 | + context: . |
| 85 | + push: true |
| 86 | + tags: ${{ steps.meta.outputs.tags }} |
| 87 | + labels: ${{ steps.meta.outputs.labels }} |
| 88 | + build-args: | |
| 89 | + argBasedVersion=${{ steps.extract-version.outputs.docker_version }} |
| 90 | + cache-from: type=gha |
| 91 | + cache-to: type=gha,mode=max |
| 92 | + |
| 93 | + - name: Verify Docker image was built |
| 94 | + run: | |
| 95 | + echo "Verifying Docker image was built successfully..." |
| 96 | + echo "Image tags: ${{ steps.meta.outputs.tags }}" |
| 97 | + echo "Image digest: ${{ steps.build.outputs.digest }}" |
| 98 | +
|
| 99 | + - name: Create Release Summary |
| 100 | + run: | |
| 101 | + echo "## 🚀 Master Container Published" >> $GITHUB_STEP_SUMMARY |
| 102 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 103 | + echo "**📦 Container Images Published:**" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 105 | +
|
| 106 | + # Convert multi-line tags to individual entries |
| 107 | + TAGS="${{ steps.meta.outputs.tags }}" |
| 108 | + echo "$TAGS" | while read -r tag; do |
| 109 | + if [ ! -z "$tag" ]; then |
| 110 | + echo "- \`$tag\`" >> $GITHUB_STEP_SUMMARY |
| 111 | + fi |
| 112 | + done |
| 113 | +
|
| 114 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 115 | + echo "**🐳 Try the bleeding-edge version:**" >> $GITHUB_STEP_SUMMARY |
| 116 | + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY |
| 117 | + echo "docker pull ghcr.io/${{ github.repository }}/wrongsecrets-master:latest-master" >> $GITHUB_STEP_SUMMARY |
| 118 | + echo "docker run -p 8080:8080 ghcr.io/${{ github.repository }}/wrongsecrets-master:latest-master" >> $GITHUB_STEP_SUMMARY |
| 119 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 120 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 121 | + echo "Then visit: http://localhost:8080" >> $GITHUB_STEP_SUMMARY |
0 commit comments