|
1 | 1 | name: Commit Stage |
| 2 | + |
2 | 3 | on: |
3 | 4 | push: |
4 | 5 | branches: |
5 | 6 | - main |
| 7 | + paths-ignore: |
| 8 | + - '.editorconfig' |
| 9 | + - '.gitignore' |
| 10 | + - '.sdkmanrc' |
| 11 | + - '*.adoc' |
| 12 | + - '*.png' |
| 13 | + - '*.md' |
| 14 | + - 'docs/**' |
| 15 | + - '.github/ISSUE_TEMPLATE/**' |
| 16 | + - '.github/*.md' |
| 17 | + - '.github/*.yml' |
| 18 | + - '.github/*.yaml' |
6 | 19 |
|
7 | 20 | env: |
8 | 21 | REGISTRY: ghcr.io |
9 | 22 | IMAGE_NAME: ${{ values.repoUrl.owner | lower }}/${{ values.repoUrl.repo }} |
10 | 23 | VERSION: ${{ '${{ github.sha }}' }} |
11 | 24 |
|
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + |
12 | 28 | jobs: |
13 | 29 | build: |
14 | 30 | name: Build |
15 | 31 | runs-on: ubuntu-24.04 |
16 | 32 | permissions: |
17 | 33 | contents: read |
18 | 34 | packages: write |
| 35 | + security-events: write |
19 | 36 | steps: |
20 | 37 | - name: Check out source code |
21 | | - uses: actions/checkout@v4 |
22 | | - |
| 38 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + |
23 | 42 | - name: Set up Java |
24 | | - uses: actions/setup-java@v4 |
| 43 | + uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4.4.0 |
25 | 44 | with: |
26 | 45 | java-version: 22 |
27 | | - distribution: temurin |
28 | | - cache: gradle |
| 46 | + distribution: 'graalvm' |
| 47 | + |
| 48 | + - name: Setup Gradle |
| 49 | + uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808 # v4.1.0 |
29 | 50 |
|
30 | 51 | - name: Compile and test |
31 | | - run: ./gradlew build |
| 52 | + run: ./gradlew build sonar |
| 53 | + env: |
| 54 | + SONAR_TOKEN: ${{ '${{ secrets.SONAR_TOKEN }}' }} |
| 55 | + |
| 56 | + - name: SBOM vulnerability scanning |
| 57 | + uses: aquasecurity/trivy-action@97646fedde05bcd0961217c60b50e23f721e7ec7 # master |
| 58 | + with: |
| 59 | + scan-type: 'sbom' |
| 60 | + scan-ref: 'build/reports/application.cdx.json' |
| 61 | + format: 'sarif' |
| 62 | + output: 'trivy-results-build.sarif' |
| 63 | + |
| 64 | + - name: Upload vulnerability report |
| 65 | + uses: github/codeql-action/upload-sarif@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 |
| 66 | + if: success() || failure() |
| 67 | + with: |
| 68 | + sarif_file: 'trivy-results-build.sarif' |
| 69 | + category: build |
32 | 70 |
|
33 | 71 | - name: Package as OCI image |
34 | 72 | run: ./gradlew bootBuildImage --imageName ${{ '${{ env.REGISTRY }}' }}/${{ '${{ env.IMAGE_NAME }}' }}:${{ '${{ env.VERSION }}' }} |
35 | 73 |
|
36 | 74 | - name: Authenticate with the container registry |
37 | | - uses: docker/login-action@v3 |
| 75 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
38 | 76 | with: |
39 | 77 | username: ${{ '${{ github.actor }}' }} |
40 | 78 | password: ${{ '${{ secrets.GITHUB_TOKEN }}' }} |
|
45 | 83 | docker tag ${{ '${{ env.REGISTRY }}' }}/${{ '${{ env.IMAGE_NAME }}' }}:${{ '${{ env.VERSION }}' }} ${{ '${{ env.REGISTRY }}' }}/${{ '${{ env.IMAGE_NAME }}' }}:latest |
46 | 84 | docker push ${{ '${{ env.REGISTRY }}' }}/${{ '${{ env.IMAGE_NAME }}' }}:${{ '${{ env.VERSION }}' }} |
47 | 85 | docker push ${{ '${{ env.REGISTRY }}' }}/${{ '${{ env.IMAGE_NAME }}' }}:latest |
| 86 | +
|
| 87 | + sign: |
| 88 | + name: Sign |
| 89 | + runs-on: ubuntu-24.04 |
| 90 | + needs: [ build ] |
| 91 | + permissions: |
| 92 | + contents: read |
| 93 | + packages: write |
| 94 | + id-token: write |
| 95 | + outputs: |
| 96 | + image-digest: ${{ '${{ steps.image-info.outputs.digest }}' }} |
| 97 | + image-name: ${{ '${{ steps.image-info.outputs.name }}' }} |
| 98 | + steps: |
| 99 | + - name: Install Cosign |
| 100 | + uses: sigstore/cosign-installer@4959ce089c160fddf62f7b42464195ba1a56d382 # v3.6.0 |
| 101 | + |
| 102 | + - uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1.7 |
| 103 | + with: |
| 104 | + username: ${{ '${{ github.actor }}' }} |
| 105 | + password: ${{ '${{ secrets.GITHUB_TOKEN }}' }} |
| 106 | + registry: ${{ '${{ env.REGISTRY }}' }} |
| 107 | + |
| 108 | + - name: Fetch OCI image |
| 109 | + run: podman pull ${{ '${{ env.REGISTRY }}' }}/${{ '${{ env.IMAGE_NAME }}' }}:${{ '${{ env.VERSION }}' }} |
| 110 | + |
| 111 | + - name: Get OCI image digest |
| 112 | + id: image-info |
| 113 | + run: | |
| 114 | + image_digest=$(podman inspect --format='{{.Digest}}' ${REGISTRY}/${IMAGE_NAME}:${VERSION}) |
| 115 | + echo $image_digest |
| 116 | + echo "IMAGE_DIGEST=${image_digest}" >> $GITHUB_ENV |
| 117 | + echo "digest=${image_digest}" >> $GITHUB_OUTPUT |
| 118 | + echo "name=${REGISTRY}/${IMAGE_NAME}" >> $GITHUB_OUTPUT |
| 119 | +
|
| 120 | + - name: Sign image |
| 121 | + run: | |
| 122 | + cosign sign --yes "${REGISTRY}/${IMAGE_NAME}@${IMAGE_DIGEST}" |
| 123 | +
|
| 124 | + provenance: |
| 125 | + needs: [ sign ] |
| 126 | + permissions: |
| 127 | + actions: read |
| 128 | + id-token: write |
| 129 | + packages: write |
| 130 | + uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v2.0.0 |
| 131 | + with: |
| 132 | + image: ${{ '${{ needs.sign.outputs.image-name }}' }} |
| 133 | + digest: ${{ '${{ needs.sign.outputs.image-digest }}' }} |
| 134 | + registry-username: ${{ '${{ github.actor }}' }} |
| 135 | + secrets: |
| 136 | + registry-password: ${{ '${{ secrets.GITHUB_TOKEN }}' }} |
0 commit comments