|
| 1 | +name: Publish Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Release tag to publish, for example v0.9.1' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + target: |
| 11 | + description: 'Branch to release from' |
| 12 | + required: true |
| 13 | + default: main |
| 14 | + type: string |
| 15 | + prerelease: |
| 16 | + description: 'Publish this as a prerelease' |
| 17 | + required: true |
| 18 | + default: false |
| 19 | + type: boolean |
| 20 | + latest: |
| 21 | + description: 'Mark the published release as latest' |
| 22 | + required: true |
| 23 | + default: 'true' |
| 24 | + type: choice |
| 25 | + options: |
| 26 | + - 'true' |
| 27 | + - 'false' |
| 28 | + - legacy |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: write |
| 32 | + pull-requests: read |
| 33 | + |
| 34 | +concurrency: |
| 35 | + group: publish-release |
| 36 | + cancel-in-progress: false |
| 37 | + |
| 38 | +env: |
| 39 | + COMPOSER_NO_INTERACTION: 1 |
| 40 | + |
| 41 | +jobs: |
| 42 | + publish: |
| 43 | + runs-on: ubuntu-latest |
| 44 | + timeout-minutes: 30 |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout code |
| 48 | + uses: actions/checkout@v6 |
| 49 | + with: |
| 50 | + ref: ${{ inputs.target }} |
| 51 | + fetch-depth: 0 |
| 52 | + |
| 53 | + - name: Setup PHP |
| 54 | + uses: shivammathur/setup-php@v2 |
| 55 | + with: |
| 56 | + php-version: '8.4' |
| 57 | + extensions: none, dom, mbstring, sqlite, pdo_sqlite |
| 58 | + tools: composer:v2 |
| 59 | + coverage: none |
| 60 | + |
| 61 | + - name: Validate release inputs |
| 62 | + id: release_meta |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + if [[ ! "${{ inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then |
| 66 | + echo "Version must look like v1.2.3 or v1.2.3-rc.1" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | +
|
| 70 | + echo "version_number=${INPUT_VERSION#v}" >> "$GITHUB_OUTPUT" |
| 71 | + env: |
| 72 | + INPUT_VERSION: ${{ inputs.version }} |
| 73 | + |
| 74 | + - name: Ensure tag does not already exist |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + if git ls-remote --exit-code --tags origin "refs/tags/${{ inputs.version }}" >/dev/null 2>&1; then |
| 78 | + echo "Tag ${{ inputs.version }} already exists on origin." |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +
|
| 82 | + - name: Validate composer.json |
| 83 | + run: composer validate --strict |
| 84 | + |
| 85 | + - name: Install composer dependencies |
| 86 | + uses: ramsey/composer-install@v3 |
| 87 | + |
| 88 | + - name: Run test suite |
| 89 | + run: vendor/bin/pest --no-coverage |
| 90 | + |
| 91 | + - name: Run static analysis |
| 92 | + run: php -d memory_limit=512M vendor/bin/phpstan analyse |
| 93 | + |
| 94 | + - name: Publish GitHub release |
| 95 | + id: release |
| 96 | + uses: release-drafter/release-drafter@v6 |
| 97 | + with: |
| 98 | + publish: true |
| 99 | + name: ${{ inputs.version }} |
| 100 | + tag: ${{ inputs.version }} |
| 101 | + version: ${{ steps.release_meta.outputs.version_number }} |
| 102 | + prerelease: ${{ inputs.prerelease }} |
| 103 | + latest: ${{ inputs.latest }} |
| 104 | + commitish: ${{ inputs.target }} |
| 105 | + env: |
| 106 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + |
| 108 | + - name: Update changelog |
| 109 | + uses: stefanzweifel/changelog-updater-action@v1 |
| 110 | + with: |
| 111 | + latest-version: ${{ inputs.version }} |
| 112 | + release-notes: ${{ steps.release.outputs.body }} |
| 113 | + |
| 114 | + - name: Commit updated changelog |
| 115 | + uses: stefanzweifel/git-auto-commit-action@v7 |
| 116 | + with: |
| 117 | + branch: ${{ inputs.target }} |
| 118 | + commit_message: "docs: update changelog for ${{ inputs.version }}" |
| 119 | + file_pattern: CHANGELOG.md |
0 commit comments