|
| 1 | +# Copyright 2023 SLSA Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +inputs: |
| 17 | + provenance-download-name: |
| 18 | + description: "The artifact name for the package provenance." |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + provenance-download-sha256: |
| 22 | + description: "The sha256 of the package provenance artifact." |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + target-download-sha256: |
| 26 | + description: "The sha256 of the target directory." |
| 27 | + required: true |
| 28 | + type: string |
| 29 | + maven-username: |
| 30 | + description: "Maven username" |
| 31 | + required: true |
| 32 | + maven-password: |
| 33 | + description: "Maven password" |
| 34 | + required: true |
| 35 | + gpg-key-pass: |
| 36 | + description: "gpg-key-pass" |
| 37 | + required: true |
| 38 | + gpg-private-key: |
| 39 | + description: "gpg-key-pass" |
| 40 | + required: true |
| 41 | +runs: |
| 42 | + using: "composite" |
| 43 | + steps: |
| 44 | + - name: Checkout the project repository |
| 45 | + uses: slsa-framework/slsa-github-generator/.github/actions/secure-project-checkout@main # needed because we run javadoc and sources. |
| 46 | + - name: Set up Java for publishing to Maven Central Repository |
| 47 | + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3 |
| 48 | + env: |
| 49 | + MAVEN_USERNAME: ${{ inputs.maven-username }} |
| 50 | + MAVEN_PASSWORD: ${{ inputs.maven-password }} |
| 51 | + GPG_KEY_PASS: ${{ inputs.gpg-key-pass }} |
| 52 | + with: |
| 53 | + java-version: '11' |
| 54 | + distribution: 'temurin' |
| 55 | + server-id: ossrh |
| 56 | + server-username: MAVEN_USERNAME |
| 57 | + server-password: MAVEN_PASSWORD |
| 58 | + gpg-private-key: ${{ inputs.gpg-private-key }} |
| 59 | + gpg-passphrase: GPG_KEY_PASS |
| 60 | + |
| 61 | + - name: Download the slsa attestation |
| 62 | + uses: slsa-framework/slsa-github-generator/.github/actions/secure-download-folder@main |
| 63 | + with: |
| 64 | + name: "${{ inputs.provenance-download-name }}" |
| 65 | + path: slsa-attestations |
| 66 | + sha256: "${{ inputs.provenance-download-sha256 }}" |
| 67 | + |
| 68 | + - name: Download the target dir |
| 69 | + uses: slsa-framework/slsa-github-generator/.github/actions/secure-download-folder@main |
| 70 | + with: |
| 71 | + name: target |
| 72 | + path: ./ |
| 73 | + sha256: "${{ inputs.target-download-sha256 }}" |
| 74 | + |
| 75 | + - name: Checkout the framework repository |
| 76 | + uses: slsa-framework/slsa-github-generator/.github/actions/secure-builder-checkout@main |
| 77 | + with: |
| 78 | + repository: slsa-framework/slsa-github-generator |
| 79 | + ref: v1.8.0 |
| 80 | + path: __BUILDER_CHECKOUT_DIR__ |
| 81 | + |
| 82 | + - name: Publish to the Maven Central Repository |
| 83 | + shell: bash |
| 84 | + env: |
| 85 | + MAVEN_USERNAME: "${{ inputs.maven-username }}" |
| 86 | + MAVEN_PASSWORD: "${{ inputs.maven-password }}" |
| 87 | + GPG_KEY_PASS: "${{ inputs.gpg-key-pass }}" |
| 88 | + SLSA_DIR: "${{ inputs.provenance-download-name }}" |
| 89 | + PROVENANCE_FILES: "${{ inputs.provenance-download-name }}" |
| 90 | + run: | |
| 91 | + cd __BUILDER_CHECKOUT_DIR__/actions/maven/publish/slsa-hashing-plugin && mvn clean install && cd - |
| 92 | + mvn javadoc:jar source:jar |
| 93 | + # Retrieve project version |
| 94 | + export version=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout) |
| 95 | + export artifactid=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.artifactId -q -DforceStdout) |
| 96 | + # Reset the environment variables add in the base provenance |
| 97 | + export files="slsa-attestations/${PROVENANCE_FILES}/${artifactid}-${version}.jar.build.slsa" |
| 98 | + export types=slsa |
| 99 | + export classifiers=jar.build |
| 100 | + # Find all necessary built jar files and attach them to the environment variable deploy |
| 101 | + while read -r name; do |
| 102 | + target=$(echo "${name}" | rev | cut -d- -f1 | rev) |
| 103 | + files=$files,$name |
| 104 | + types=$types,${target##*.} |
| 105 | + classifiers=$classifiers,${target%.*} |
| 106 | + done <<<"$(find ./ -name "$artifactid-$version-*.jar")" |
| 107 | + # Find all generated provenance files and attach them the the environment variable for deploy |
| 108 | + while read -r name; do |
| 109 | + target=$(echo "${name}" | rev | cut -d- -f1 | rev) |
| 110 | + files=$files,$name |
| 111 | + types=$types",slsa" |
| 112 | + classifiers=$classifiers,${target::-9} |
| 113 | + done <<<"$(find ./ -name "$artifactid-$version-*.jar.build.slsa")" |
| 114 | + # Sign and deploy the files to the ossrh remote repository |
| 115 | + mvn validate jar:jar -Dfile=target/"${artifactid}"-"${version}".jar -Durl=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=ossrh -Dfiles="${files}" -Dtypes="${types}" -Dclassifiers="${classifiers}" -DpomFile=pom.xml gpg:sign-and-deploy-file |
0 commit comments