|
| 1 | +name: Publish Release |
| 2 | +run-name: Publish Release |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + release: |
| 8 | + description: 'Release version (e.g. 1.2.3)' |
| 9 | + required: true |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +env: |
| 15 | + TAG: ${{ github.event.inputs.release }} |
| 16 | + BRANCH: temp-release-${{ github.event.inputs.release }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + # ref and repository are required, otherwise repo could appear in detached head state |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + ref: ${{ github.head_ref }} |
| 27 | + repository: ${{ github.repository }} |
| 28 | + |
| 29 | + - name: Parse Changelog Entries |
| 30 | + uses: actions/github-script@v7 |
| 31 | + id: changelog |
| 32 | + with: |
| 33 | + script: | |
| 34 | + const { open } = require('fs/promises'); |
| 35 | +
|
| 36 | + const version = process.env.TAG; |
| 37 | + const delimiter = '#### '; |
| 38 | + const file = await open('./changes.md'); |
| 39 | +
|
| 40 | + let description = []; |
| 41 | + let found = false; |
| 42 | +
|
| 43 | + for await (let line of file.readLines()) { |
| 44 | + line = line.trim(); |
| 45 | + |
| 46 | + if ( line.startsWith(`${delimiter}${version}`) ) { |
| 47 | + found = true; |
| 48 | + continue; |
| 49 | + } |
| 50 | + |
| 51 | + if (!found) continue; |
| 52 | + if ( line.startsWith(delimiter) ) break; |
| 53 | +
|
| 54 | + description.push(line); |
| 55 | + } |
| 56 | +
|
| 57 | + if ( !description.length ) core.setFailed(`Release ${version} not found in the changelog!`); |
| 58 | +
|
| 59 | + core.setOutput('description', description.join('\n') ); |
| 60 | +
|
| 61 | +
|
| 62 | + # cleanup files that are not needed for the release |
| 63 | + # but keep the .git folder, because we need it for the next step |
| 64 | + - name: Cleanup files |
| 65 | + run: | |
| 66 | + rm -f composer.lock || true |
| 67 | + rm -rf tests || true |
| 68 | + rm -rf vendor/composer/installers || true |
| 69 | + find ./ -name '.git*' -not -path './.git' -type f -delete || true |
| 70 | + find ./ -name '.git*' -not -path './.git' -type d -exec rm -rf {} \; || true |
| 71 | + find ./vendor -name .svn -exec rm -rf {} \; || true |
| 72 | +
|
| 73 | + # cleanup files, specific to Google API PHP library |
| 74 | + - name: Cleanup files for Google API library |
| 75 | + run: | |
| 76 | + rm -f lib/Google/phpstan.neon.dist || true |
| 77 | + rm -f lib/Google/vendor/paragonie/random_compat/build-phar.sh || true |
| 78 | + find ./lib/Google/ -name '.repo-metadata.json' -type f -delete || true |
| 79 | + find ./lib/Google/vendor -name .svn -exec rm -rf '{}' \; || true |
| 80 | +
|
| 81 | + # commit changes to temporary release branch and create a new tag |
| 82 | + - name: Commit changes |
| 83 | + uses: EndBug/add-and-commit@v9 |
| 84 | + with: |
| 85 | + message: Cleanup files for release |
| 86 | + new_branch: ${{ env.BRANCH }} |
| 87 | + tag: ${{ env.TAG }} |
| 88 | + |
| 89 | + # generate SBOM that will be attached to a release as an artifact |
| 90 | + - name: Create SBOM |
| 91 | + id: sbom |
| 92 | + uses: anchore/sbom-action@v0 |
| 93 | + with: |
| 94 | + path: . |
| 95 | + output-file: sbom.spdx.json |
| 96 | + format: spdx-json |
| 97 | + |
| 98 | + # create a draft release with the version changelog as a description |
| 99 | + - name: Create Draft Release |
| 100 | + id: draft_release |
| 101 | + uses: softprops/action-gh-release@v1 |
| 102 | + with: |
| 103 | + name: "Release ${{ env.TAG }}" |
| 104 | + body: "${{ steps.changelog.outputs.description }}" |
| 105 | + tag_name: ${{ env.TAG }} |
| 106 | + draft: true |
| 107 | + prerelease: false |
| 108 | + |
| 109 | + # attach SBOM to release |
| 110 | + - name: Upload SBOM to release |
| 111 | + uses: actions/upload-release-asset@v1.0.2 |
| 112 | + env: |
| 113 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 114 | + with: |
| 115 | + upload_url: ${{ steps.draft_release.outputs.upload_url }} |
| 116 | + asset_path: ./sbom.spdx.json |
| 117 | + asset_name: sbom.spdx.json |
| 118 | + asset_content_type: application/json |
| 119 | + |
| 120 | + # publish release using an ID from the 'draft_release' step |
| 121 | + - name: Publish Release |
| 122 | + uses: eregon/publish-release@v1 |
| 123 | + env: |
| 124 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + with: |
| 126 | + release_id: ${{ steps.draft_release.outputs.id }} |
| 127 | + |
| 128 | + # delete temporary release branch |
| 129 | + - name: Delete temporary release branch |
| 130 | + run: | |
| 131 | + git push origin --delete ${{ env.BRANCH }} |
0 commit comments