|
| 1 | +# MoquiDemo Release - Build and publish MoquiDemo zip, WAR, Docker images on release |
| 2 | +# Equivalent to make_demo.sh with multi-arch images, SBOM, provenance, and cosign signing |
| 3 | +name: MoquiDemo Release |
| 4 | + |
| 5 | +on: |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + version: |
| 11 | + description: 'Version (e.g., 3.0.0)' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + ref: |
| 15 | + description: 'Branch or tag to build from (default: default branch)' |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + upload_to_release: |
| 19 | + description: 'Upload assets to GitHub Release' |
| 20 | + required: false |
| 21 | + type: boolean |
| 22 | + default: false |
| 23 | + |
| 24 | +permissions: |
| 25 | + contents: write # Upload release assets |
| 26 | + id-token: write # OIDC for keyless cosign signing |
| 27 | + attestations: write # Attestations for provenance/SBOM |
| 28 | + packages: write # Push to ghcr.io |
| 29 | + |
| 30 | +env: |
| 31 | + REGISTRY: ghcr.io |
| 32 | + |
| 33 | +jobs: |
| 34 | + build-moquidemo: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + outputs: |
| 37 | + version: ${{ steps.vars.outputs.version }} |
| 38 | + version_minor: ${{ steps.vars.outputs.version_minor }} |
| 39 | + version_major: ${{ steps.vars.outputs.version_major }} |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Get version |
| 43 | + id: vars |
| 44 | + run: | |
| 45 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 46 | + VERSION="${{ github.event.inputs.version }}" |
| 47 | + else |
| 48 | + # Strip 'v' prefix from tag (e.g., v3.0.0 -> 3.0.0) |
| 49 | + VERSION="${GITHUB_REF#refs/tags/v}" |
| 50 | + fi |
| 51 | + # Strip leading 'v' if user included it |
| 52 | + VERSION="${VERSION#v}" |
| 53 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 54 | + VERSION_MINOR=$(echo "$VERSION" | cut -d. -f1,2) |
| 55 | + echo "version_minor=$VERSION_MINOR" >> $GITHUB_OUTPUT |
| 56 | + VERSION_MAJOR=$(echo "$VERSION" | cut -d. -f1) |
| 57 | + echo "version_major=$VERSION_MAJOR" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + - name: Checkout repository |
| 60 | + uses: actions/checkout@v4 |
| 61 | + with: |
| 62 | + ref: ${{ github.event.inputs.ref || github.ref }} |
| 63 | + |
| 64 | + - name: Set up JDK 21 |
| 65 | + uses: actions/setup-java@v4 |
| 66 | + with: |
| 67 | + java-version: '21' |
| 68 | + distribution: 'temurin' |
| 69 | + cache: 'gradle' |
| 70 | + |
| 71 | + - name: Get runtime and demo components |
| 72 | + run: | |
| 73 | + ./gradlew getRuntime getComponentSet -PcomponentSet=demo getComponent -Pcomponent=moqui-poi -PlocationType=release |
| 74 | +
|
| 75 | + - name: Download JDBC drivers and OpenSearch |
| 76 | + run: | |
| 77 | + ./gradlew getMySqlJdbc getPostgresJdbc downloadOpenSearch |
| 78 | +
|
| 79 | + - name: Load data and run tests |
| 80 | + run: | |
| 81 | + ./gradlew load test |
| 82 | + env: |
| 83 | + # Prevent ElasticSearch/OpenSearch from stealing focus |
| 84 | + ES_JAVA_OPTS: "-Xms512m -Xmx512m" |
| 85 | + |
| 86 | + - name: Wait for OpenSearch to stop |
| 87 | + run: sleep 5 |
| 88 | + |
| 89 | + - name: Create moqui-plus-runtime WAR |
| 90 | + run: ./gradlew addRuntime |
| 91 | + |
| 92 | + - name: Create MoquiDemo zip and rename WAR |
| 93 | + run: | |
| 94 | + VERSION="${{ steps.vars.outputs.version }}" |
| 95 | + cp moqui-plus-runtime.war "MoquiDemo-${VERSION}.war" |
| 96 | + zip -r "MoquiDemo-${VERSION}.zip" . \ |
| 97 | + -x "*.git*" \ |
| 98 | + -x "*.git/*" \ |
| 99 | + -x "build/*" \ |
| 100 | + -x "framework/build/*" \ |
| 101 | + -x "runtime/log/*" \ |
| 102 | + -x "runtime/sessions/*" \ |
| 103 | + -x "runtime/txlog/*" \ |
| 104 | + -x "runtime/db/*" \ |
| 105 | + -x "runtime/elasticsearch/data/*" \ |
| 106 | + -x "runtime/opensearch/data/*" \ |
| 107 | + -x "wartemp" \ |
| 108 | + -x "moqui.war" |
| 109 | + # Include the renamed WAR in the zip |
| 110 | + zip -u "MoquiDemo-${VERSION}.zip" "MoquiDemo-${VERSION}.war" |
| 111 | +
|
| 112 | + - name: Upload artifacts |
| 113 | + uses: actions/upload-artifact@v4 |
| 114 | + with: |
| 115 | + name: moquidemo-build |
| 116 | + path: | |
| 117 | + moqui-plus-runtime.war |
| 118 | + MoquiDemo-${{ steps.vars.outputs.version }}.zip |
| 119 | + MoquiDemo-${{ steps.vars.outputs.version }}.war |
| 120 | + docker/ |
| 121 | + retention-days: 1 |
| 122 | + |
| 123 | + build-docker: |
| 124 | + needs: build-moquidemo |
| 125 | + runs-on: ubuntu-latest |
| 126 | + |
| 127 | + steps: |
| 128 | + - name: Download build artifacts |
| 129 | + uses: actions/download-artifact@v4 |
| 130 | + with: |
| 131 | + name: moquidemo-build |
| 132 | + |
| 133 | + - name: Set up QEMU |
| 134 | + uses: docker/setup-qemu-action@v3 |
| 135 | + |
| 136 | + - name: Set up Docker Buildx |
| 137 | + uses: docker/setup-buildx-action@v3 |
| 138 | + |
| 139 | + - name: Log in to Container Registry |
| 140 | + uses: docker/login-action@v3 |
| 141 | + with: |
| 142 | + registry: ${{ env.REGISTRY }} |
| 143 | + username: ${{ github.actor }} |
| 144 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + |
| 146 | + - name: Extract WAR and prepare Docker build context |
| 147 | + run: | |
| 148 | + unzip -q moqui-plus-runtime.war |
| 149 | + rm -f moqui-plus-runtime.war |
| 150 | +
|
| 151 | + - name: Build and push multi-arch Docker image |
| 152 | + id: build |
| 153 | + uses: docker/build-push-action@v6 |
| 154 | + with: |
| 155 | + context: . |
| 156 | + file: ./docker/simple/Dockerfile |
| 157 | + platforms: linux/amd64,linux/arm64 |
| 158 | + push: true |
| 159 | + provenance: mode=max |
| 160 | + sbom: true |
| 161 | + tags: | |
| 162 | + ${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version }} |
| 163 | + ${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version_minor }} |
| 164 | + ${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version_major }} |
| 165 | + ${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:latest |
| 166 | +
|
| 167 | + - name: Sign container image with cosign (keyless) |
| 168 | + uses: sigstore/cosign-installer@v3 |
| 169 | + - name: Sign the images |
| 170 | + run: | |
| 171 | + IMAGE="${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version }}" |
| 172 | + cosign sign --yes "$IMAGE" |
| 173 | + cosign sign --yes "${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version_minor }}" |
| 174 | + cosign sign --yes "${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:${{ needs.build-moquidemo.outputs.version_major }}" |
| 175 | + cosign sign --yes "${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo:latest" |
| 176 | +
|
| 177 | + push-dockerhub: |
| 178 | + needs: [build-docker, build-moquidemo] |
| 179 | + runs-on: ubuntu-latest |
| 180 | + if: vars.DOCKERHUB_USERNAME != '' |
| 181 | + |
| 182 | + steps: |
| 183 | + - name: Set up Docker Buildx |
| 184 | + uses: docker/setup-buildx-action@v3 |
| 185 | + |
| 186 | + - name: Log in to Docker Hub |
| 187 | + uses: docker/login-action@v3 |
| 188 | + with: |
| 189 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 190 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 191 | + |
| 192 | + - name: Copy images from GHCR to Docker Hub |
| 193 | + run: | |
| 194 | + SOURCE="${{ env.REGISTRY }}/${{ github.repository_owner }}/moquidemo" |
| 195 | + for tag in ${{ needs.build-moquidemo.outputs.version }} ${{ needs.build-moquidemo.outputs.version_minor }} ${{ needs.build-moquidemo.outputs.version_major }} latest; do |
| 196 | + docker buildx imagetools create -t "moqui/moquidemo:${tag}" "${SOURCE}:${tag}" |
| 197 | + done |
| 198 | +
|
| 199 | + - name: Sign Docker Hub images with cosign (keyless) |
| 200 | + uses: sigstore/cosign-installer@v3 |
| 201 | + - name: Sign the Docker Hub images |
| 202 | + run: | |
| 203 | + cosign sign --yes moqui/moquidemo:${{ needs.build-moquidemo.outputs.version }} |
| 204 | + cosign sign --yes moqui/moquidemo:${{ needs.build-moquidemo.outputs.version_minor }} |
| 205 | + cosign sign --yes moqui/moquidemo:${{ needs.build-moquidemo.outputs.version_major }} |
| 206 | + cosign sign --yes moqui/moquidemo:latest |
| 207 | +
|
| 208 | + upload-release: |
| 209 | + needs: [build-moquidemo, build-docker] |
| 210 | + runs-on: ubuntu-latest |
| 211 | + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.upload_to_release == 'true') |
| 212 | + |
| 213 | + steps: |
| 214 | + - name: Download build artifacts |
| 215 | + uses: actions/download-artifact@v4 |
| 216 | + with: |
| 217 | + name: moquidemo-build |
| 218 | + |
| 219 | + - name: Attest build provenance for release assets |
| 220 | + uses: actions/attest-build-provenance@v3 |
| 221 | + with: |
| 222 | + subject-path: | |
| 223 | + MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.zip |
| 224 | + MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.war |
| 225 | +
|
| 226 | + - name: Attest SBOM for release assets |
| 227 | + uses: actions/attest-sbom@v2 |
| 228 | + with: |
| 229 | + subject-path: | |
| 230 | + MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.zip |
| 231 | + MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.war |
| 232 | +
|
| 233 | + - name: Upload release assets |
| 234 | + uses: softprops/action-gh-release@v2 |
| 235 | + with: |
| 236 | + tag_name: v${{ needs.build-moquidemo.outputs.version }} |
| 237 | + files: | |
| 238 | + MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.zip |
| 239 | + MoquiDemo-${{ needs.build-moquidemo.outputs.version }}.war |
| 240 | + fail_on_unmatched_files: true |
0 commit comments