|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +concurrency: release |
| 9 | + |
| 10 | +jobs: |
| 11 | + smoke: |
| 12 | + name: Smoke Test |
| 13 | + runs-on: ubuntu-22.04 |
| 14 | + outputs: |
| 15 | + release_notes: ${{ steps.notes.outputs.body }} |
| 16 | + steps: |
| 17 | + - name: Setup Go |
| 18 | + uses: actions/setup-go@v3 |
| 19 | + with: |
| 20 | + go-version: 1.20.x |
| 21 | + |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v3 |
| 24 | + |
| 25 | + - name: Get pack version |
| 26 | + id: pack-version |
| 27 | + run: | |
| 28 | + version=$(jq -r .pack "scripts/.util/tools.json") |
| 29 | + echo "version=${version#v}" >> "$GITHUB_OUTPUT" |
| 30 | +
|
| 31 | + - name: Install Global Pack |
| 32 | + uses: buildpacks/github-actions/setup-pack@main |
| 33 | + with: |
| 34 | + pack-version: ${{ steps.pack-version.outputs.version }} |
| 35 | + |
| 36 | + - name: Run Smoke Tests |
| 37 | + run: ./scripts/smoke.sh --name builder |
| 38 | + |
| 39 | + - name: Generate Release Notes |
| 40 | + id: notes |
| 41 | + run: | |
| 42 | + notes="$(pack inspect-builder builder | grep -v 'Inspecting builder' \ |
| 43 | + | grep -v 'REMOTE:' \ |
| 44 | + | grep -v 'LOCAL:' \ |
| 45 | + | grep -v '\(not present\)' \ |
| 46 | + | grep -v 'Warning' \ |
| 47 | + | sed -e '/./,$!d' \ |
| 48 | + | awk -F, '{printf "%s\\n", $0}')" |
| 49 | + echo "body=${notes}" >> "$GITHUB_OUTPUT" |
| 50 | +
|
| 51 | + release: |
| 52 | + name: Release |
| 53 | + runs-on: ubuntu-22.04 |
| 54 | + needs: smoke |
| 55 | + steps: |
| 56 | + - name: Checkout With History |
| 57 | + uses: actions/checkout@v3 |
| 58 | + with: |
| 59 | + fetch-depth: 0 # gets full history |
| 60 | + |
| 61 | + - name: Compare With Previous Release |
| 62 | + id: compare_previous_release |
| 63 | + run: | |
| 64 | + if [ -z "$(git diff $(git describe --tags --abbrev=0) -- builder.toml)" ] |
| 65 | + then |
| 66 | + echo "builder_changes=false" >> "$GITHUB_OUTPUT" |
| 67 | + else |
| 68 | + echo "builder_changes=true" >> "$GITHUB_OUTPUT" |
| 69 | + fi |
| 70 | +
|
| 71 | + - name: Publish Release |
| 72 | + id: publish |
| 73 | + if: ${{ steps.compare_previous_release.outputs.builder_changes == 'true' }} |
| 74 | + uses: release-drafter/release-drafter@v5 |
| 75 | + with: |
| 76 | + config-name: release-drafter-config.yml |
| 77 | + publish: true |
| 78 | + env: |
| 79 | + GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} |
| 80 | + |
| 81 | + - name: Update Release Notes |
| 82 | + if: ${{ steps.compare_previous_release.outputs.builder_changes == 'true' }} |
| 83 | + run: | |
| 84 | + set -euo pipefail |
| 85 | + shopt -s inherit_errexit |
| 86 | +
|
| 87 | + payload="{\"body\" : \"\`\`\`\n${RELEASE_BODY}\n\`\`\`\"}" |
| 88 | +
|
| 89 | + curl --fail \ |
| 90 | + -X PATCH \ |
| 91 | + -H "Accept: application/vnd.github.v3+json" \ |
| 92 | + -H "Authorization: token ${GITHUB_TOKEN}" \ |
| 93 | + "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \ |
| 94 | + -d "${payload}" |
| 95 | + env: |
| 96 | + RELEASE_ID: ${{ steps.publish.outputs.id }} |
| 97 | + RELEASE_BODY: ${{ needs.smoke.outputs.release_notes }} |
| 98 | + GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} |
| 99 | + |
| 100 | + failure: |
| 101 | + name: Alert on Failure |
| 102 | + runs-on: ubuntu-22.04 |
| 103 | + needs: [ smoke, release ] |
| 104 | + if: ${{ always() && needs.smoke.result == 'failure' || needs.release.result == 'failure' }} |
| 105 | + steps: |
| 106 | + - name: File Failure Alert Issue |
| 107 | + uses: paketo-buildpacks/github-config/actions/issue/file@main |
| 108 | + with: |
| 109 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 110 | + repo: ${{ github.repository }} |
| 111 | + label: "failure:release" |
| 112 | + comment_if_exists: true |
| 113 | + issue_title: "Failure: Create Release workflow" |
| 114 | + issue_body: | |
| 115 | + Create Release workflow [failed](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}). |
| 116 | + comment_body: | |
| 117 | + Another failure occurred: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
0 commit comments