|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + type: string |
| 8 | + required: true |
| 9 | + secrets: |
| 10 | + chainloop_token: |
| 11 | + required: true |
| 12 | + cosign_key: |
| 13 | + required: true |
| 14 | + cosign_pass: |
| 15 | + required: true |
| 16 | + |
| 17 | +permissions: {} |
| 18 | + |
| 19 | +jobs: |
| 20 | + # This reusable workflow inspects if the given workflow_name exists on Chainloop. If the Workflow does not exist |
| 21 | + # it will create one with an empty contract ready for operators to be filled. Otherwise, if found, it will just |
| 22 | + # be ignored and the process will continue. For this to work it's using a pre-created API Token |
| 23 | + release: |
| 24 | + name: Record release from GitHub |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + packages: write |
| 28 | + contents: write |
| 29 | + env: |
| 30 | + CHAINLOOP_TOKEN: ${{ secrets.chainloop_token }} |
| 31 | + CHAINLOOP_WORKFLOW_NAME: chainloop-vault-release |
| 32 | + CHAINLOOP_PROJECT: chainloop |
| 33 | + GH_TOKEN: ${{ github.token }} |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 36 | + |
| 37 | + - name: Install Chainloop |
| 38 | + run: | |
| 39 | + curl -sfL https://raw.githubusercontent.com/chainloop-dev/chainloop/01ad13af08950b7bfbc83569bea207aeb4e1a285/docs/static/install.sh | bash -s |
| 40 | +
|
| 41 | + - name: Initialize Attestation |
| 42 | + run: | |
| 43 | + tag=$(echo -n ${{inputs.tag}} | cut -d / -f3) |
| 44 | + chainloop attestation init --workflow ${CHAINLOOP_WORKFLOW_NAME} --project ${CHAINLOOP_PROJECT} --version "$tag" |
| 45 | +
|
| 46 | + - name: Attest all assets |
| 47 | + run: | |
| 48 | + tag=$(echo -n ${{inputs.tag}} | cut -d / -f3) |
| 49 | + gh release download $tag -D /tmp/github-release |
| 50 | + for entry in $(ls /tmp/github-release); do |
| 51 | + # If the name is cas.cyclonedx.json, controlplane.cyclonedx.json or cli.cyclonedx.json, we need to add the attestation with the correct name |
| 52 | + if [[ $entry =~ ^(cas|controlplane|cli)\.cyclonedx\.json$ ]]; then |
| 53 | + name=$(echo -n "${entry%.json}" | sed 's/\./-/g') |
| 54 | + chainloop attestation add --value "/tmp/github-release/$entry" --name "$name" |
| 55 | + continue |
| 56 | + fi |
| 57 | + chainloop attestation add --value "/tmp/github-release/$entry" |
| 58 | + done |
| 59 | +
|
| 60 | + # Include source code |
| 61 | + version=$(echo -n $tag | sed 's/v//g') |
| 62 | + gh release download $tag -A tar.gz -D /tmp |
| 63 | + chainloop attestation add --value "/tmp/chainloop-$version.tar.gz" |
| 64 | +
|
| 65 | + - name: Finish and Record Attestation |
| 66 | + id: attestation-push |
| 67 | + if: ${{ success() }} |
| 68 | + run: | |
| 69 | + chainloop attestation status --full |
| 70 | + attestation_sha=$(chainloop attestation push --key env://CHAINLOOP_SIGNING_KEY -o json | jq -r '.digest') |
| 71 | + # check that the command succeeded |
| 72 | + [ -n "${attestation_sha}" ] || exit 1 |
| 73 | + echo "attestation_sha=$attestation_sha" >> $GITHUB_OUTPUT |
| 74 | + env: |
| 75 | + CHAINLOOP_SIGNING_PASSWORD: ${{ secrets.cosign_pass }} |
| 76 | + CHAINLOOP_SIGNING_KEY: ${{ secrets.cosign_key }} |
| 77 | + |
| 78 | + - name: Mark attestation as failed |
| 79 | + if: ${{ failure() }} |
| 80 | + run: | |
| 81 | + chainloop attestation reset |
| 82 | +
|
| 83 | + - name: Mark attestation as cancelled |
| 84 | + if: ${{ cancelled() }} |
| 85 | + run: | |
| 86 | + chainloop attestation reset --trigger cancellation |
| 87 | +
|
| 88 | + - name: Add attestation link to release notes |
| 89 | + if: ${{ success() }} |
| 90 | + run: | |
| 91 | + chainloop_release_url="## Chainloop Attestation"$'\n'"[View the attestation of this release](https://app.chainloop.dev/attestation/${{ steps.attestation-push.outputs.attestation_sha }})" |
| 92 | + current_notes=$(gh release view ${{inputs.tag}} --json body -q '.body') |
| 93 | +
|
| 94 | + if echo "$current_notes" | grep -q "## Chainloop Attestation"; then |
| 95 | + # Replace the existing Chainloop Attestation section with the new URL |
| 96 | + modified_notes=$(echo "$current_notes" | sed -E "s|## Chainloop Attestation[^\n]*\n\[View the attestation of this release\]\(https://app\.chainloop\.dev/attestation/[^\)]*\)|$chainloop_release_url|") |
| 97 | + else |
| 98 | + # Add the Chainloop Attestation section to the top |
| 99 | + modified_notes="$chainloop_release_url"$'\n\n'"$current_notes" |
| 100 | + fi |
| 101 | +
|
| 102 | + # Update the release notes and ignore if it fails since we might be lacking permissions to update the release notes |
| 103 | + gh release edit ${{inputs.tag}} -n "$modified_notes" || echo -n "Not enough permissions to edit the release notes. Skipping..." |
0 commit comments