[sync] Package project-agent prompts for consumers (#130) #40
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Changelog Automation | |
| on: | |
| workflow_call: | |
| inputs: | |
| changelog-file: | |
| description: Path to the managed changelog file. | |
| required: false | |
| type: string | |
| default: CHANGELOG.md | |
| version: | |
| description: Optional version to promote during manual release preparation. | |
| required: false | |
| type: string | |
| default: '' | |
| release-branch-prefix: | |
| description: Prefix used for release-preparation branches. | |
| required: false | |
| type: string | |
| default: release/v | |
| workflow_dispatch: | |
| inputs: | |
| changelog-file: | |
| description: Path to the managed changelog file. | |
| required: false | |
| type: string | |
| default: CHANGELOG.md | |
| version: | |
| description: Optional version to promote. Leave empty to infer from Unreleased. | |
| required: false | |
| type: string | |
| default: '' | |
| release-branch-prefix: | |
| description: Prefix used for release-preparation branches. | |
| required: false | |
| type: string | |
| default: release/v | |
| pull_request: | |
| types: [opened, reopened, synchronize] | |
| pull_request_target: | |
| types: [closed] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: ${{ github.event.pull_request.number && format('changelog-pr-{0}', github.event.pull_request.number) || format('changelog-{0}', github.ref) }} | |
| cancel-in-progress: ${{ github.event.pull_request.merged != true }} | |
| jobs: | |
| resolve_php: | |
| name: Resolve PHP Version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| php-version: ${{ steps.resolve.outputs.php-version }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Resolve workflow PHP version | |
| id: resolve | |
| uses: php-fast-forward/dev-tools/resources/resolve-php-version@main | |
| validate_pull_request: | |
| name: Validate PR Changelog | |
| needs: resolve_php | |
| if: ${{ github.event.pull_request.number && github.event.pull_request.merged != true }} | |
| runs-on: ubuntu-latest | |
| env: | |
| CHANGELOG_FILE: ${{ inputs.changelog-file || 'CHANGELOG.md' }} | |
| CHANGELOG_ROOT_VERSION: ${{ github.event.pull_request.head.ref && format('dev-{0}', github.event.pull_request.head.ref) || 'dev-main' }} | |
| FORCE_COLOR: '1' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ needs.resolve_php.outputs.php-version }} | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v5 | |
| with: | |
| path: /tmp/composer-cache | |
| key: ${{ runner.os }}-composer-${{ needs.resolve_php.outputs.php-version }}-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-composer-${{ needs.resolve_php.outputs.php-version }}- | |
| ${{ runner.os }}-composer- | |
| - name: Mark workspace as safe for git | |
| run: git config --global --add safe.directory "$GITHUB_WORKSPACE" | |
| - name: Fetch base branch reference | |
| env: | |
| BASE_REF: ${{ github.event.pull_request.base.ref }} | |
| run: git fetch --no-tags --depth=1 origin "+refs/heads/${BASE_REF}:refs/remotes/origin/${BASE_REF}" | |
| - name: Install dependencies | |
| env: | |
| COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' | |
| COMPOSER_CACHE_DIR: /tmp/composer-cache | |
| COMPOSER_ROOT_VERSION: ${{ env.CHANGELOG_ROOT_VERSION }} | |
| run: composer install --prefer-dist --no-progress --no-interaction --no-plugins --no-scripts | |
| - name: Verify changelog update | |
| env: | |
| BASE_REF: ${{ github.event.pull_request.base.ref }} | |
| run: composer dev-tools changelog:check -- --file="${CHANGELOG_FILE}" --against="origin/${BASE_REF}" | |
| prepare_release_pull_request: | |
| name: Prepare Release Pull Request | |
| needs: resolve_php | |
| if: ${{ !github.event.pull_request.number }} | |
| runs-on: ubuntu-latest | |
| env: | |
| CHANGELOG_FILE: ${{ inputs.changelog-file || 'CHANGELOG.md' }} | |
| RELEASE_BRANCH_PREFIX: ${{ inputs.release-branch-prefix || 'release/v' }} | |
| CHANGELOG_ROOT_VERSION: ${{ format('dev-{0}', github.event.repository.default_branch) }} | |
| FORCE_COLOR: '1' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| token: ${{ github.token }} | |
| ref: ${{ github.event.repository.default_branch }} | |
| fetch-depth: 0 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ needs.resolve_php.outputs.php-version }} | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v5 | |
| with: | |
| path: /tmp/composer-cache | |
| key: ${{ runner.os }}-composer-${{ needs.resolve_php.outputs.php-version }}-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-composer-${{ needs.resolve_php.outputs.php-version }}- | |
| ${{ runner.os }}-composer- | |
| - name: Mark workspace as safe for git | |
| run: git config --global --add safe.directory "$GITHUB_WORKSPACE" | |
| - name: Install dependencies | |
| env: | |
| COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' | |
| COMPOSER_CACHE_DIR: /tmp/composer-cache | |
| COMPOSER_ROOT_VERSION: ${{ env.CHANGELOG_ROOT_VERSION }} | |
| run: composer install --prefer-dist --no-progress --no-interaction --no-plugins --no-scripts | |
| - name: Resolve release version | |
| id: version | |
| env: | |
| INPUT_VERSION: ${{ inputs.version || '' }} | |
| run: | | |
| if [ -n "${INPUT_VERSION}" ]; then | |
| version="${INPUT_VERSION}" | |
| source="input" | |
| else | |
| version="$(composer dev-tools changelog:next-version -- --file="${CHANGELOG_FILE}")" | |
| source="inferred" | |
| fi | |
| echo "value=${version}" >> "$GITHUB_OUTPUT" | |
| echo "source=${source}" >> "$GITHUB_OUTPUT" | |
| - name: Promote changelog release | |
| env: | |
| RELEASE_VERSION: ${{ steps.version.outputs.value }} | |
| run: | | |
| release_date="$(date -u +%F)" | |
| composer dev-tools changelog:promote -- "${RELEASE_VERSION}" --file="${CHANGELOG_FILE}" --date="${release_date}" | |
| - name: Render release notes preview | |
| env: | |
| RELEASE_VERSION: ${{ steps.version.outputs.value }} | |
| run: | | |
| mkdir -p .dev-tools | |
| composer dev-tools changelog:show -- "${RELEASE_VERSION}" --file="${CHANGELOG_FILE}" > .dev-tools/release-notes.md | |
| - name: Create release preparation pull request | |
| id: create_pr | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ github.token }} | |
| branch: ${{ env.RELEASE_BRANCH_PREFIX }}${{ steps.version.outputs.value }} | |
| delete-branch: false | |
| base: ${{ github.event.repository.default_branch }} | |
| add-paths: | | |
| ${{ env.CHANGELOG_FILE }} | |
| commit-message: Prepare release v${{ steps.version.outputs.value }} | |
| title: Prepare release v${{ steps.version.outputs.value }} | |
| body: | | |
| ## Summary | |
| - promote `Unreleased` into `${{ steps.version.outputs.value }}` | |
| - prepare the GitHub release body from `${{ env.CHANGELOG_FILE }}` | |
| ## Version Resolution | |
| - source: `${{ steps.version.outputs.source }}` | |
| - name: Summarize prepared release | |
| run: | | |
| echo "Prepared release version: ${{ steps.version.outputs.value }}" | |
| echo "Pull request operation: ${{ steps.create_pr.outputs.pull-request-operation || 'none' }}" | |
| echo "Pull request URL: ${{ steps.create_pr.outputs.pull-request-url || 'not created' }}" | |
| publish_merged_release: | |
| name: Publish Merged Release | |
| needs: resolve_php | |
| if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == github.event.repository.default_branch && github.event.pull_request.head.repo.full_name == github.repository && startsWith(github.event.pull_request.head.ref, inputs.release-branch-prefix || 'release/v') }} | |
| runs-on: ubuntu-latest | |
| env: | |
| CHANGELOG_FILE: ${{ inputs.changelog-file || 'CHANGELOG.md' }} | |
| RELEASE_BRANCH_PREFIX: ${{ inputs.release-branch-prefix || 'release/v' }} | |
| CHANGELOG_ROOT_VERSION: ${{ format('dev-{0}', github.event.repository.default_branch) }} | |
| FORCE_COLOR: '1' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| token: ${{ github.token }} | |
| ref: ${{ github.event.pull_request.base.ref }} | |
| fetch-depth: 0 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ needs.resolve_php.outputs.php-version }} | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v5 | |
| with: | |
| path: /tmp/composer-cache | |
| key: ${{ runner.os }}-composer-${{ needs.resolve_php.outputs.php-version }}-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-composer-${{ needs.resolve_php.outputs.php-version }}- | |
| ${{ runner.os }}-composer- | |
| - name: Mark workspace as safe for git | |
| run: git config --global --add safe.directory "$GITHUB_WORKSPACE" | |
| - name: Install dependencies | |
| env: | |
| COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' | |
| COMPOSER_CACHE_DIR: /tmp/composer-cache | |
| COMPOSER_ROOT_VERSION: ${{ env.CHANGELOG_ROOT_VERSION }} | |
| run: composer install --prefer-dist --no-progress --no-interaction --no-plugins --no-scripts | |
| - name: Resolve merged release version | |
| id: version | |
| env: | |
| HEAD_REF: ${{ github.event.pull_request.head.ref }} | |
| run: | | |
| version="${HEAD_REF#${RELEASE_BRANCH_PREFIX}}" | |
| if [ -z "${version}" ] || [ "${version}" = "${HEAD_REF}" ]; then | |
| echo "Failed to derive the release version from ${HEAD_REF}." >&2 | |
| exit 1 | |
| fi | |
| echo "value=${version}" >> "$GITHUB_OUTPUT" | |
| - name: Render release notes | |
| env: | |
| RELEASE_VERSION: ${{ steps.version.outputs.value }} | |
| run: | | |
| mkdir -p .dev-tools | |
| composer dev-tools changelog:show -- "${RELEASE_VERSION}" --file="${CHANGELOG_FILE}" > .dev-tools/release-notes.md | |
| - name: Publish GitHub release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| RELEASE_VERSION: ${{ steps.version.outputs.value }} | |
| RELEASE_TAG: v${{ steps.version.outputs.value }} | |
| RELEASE_TARGET: ${{ github.event.pull_request.merge_commit_sha || github.sha }} | |
| run: | | |
| if gh release view "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then | |
| gh release edit "${RELEASE_TAG}" \ | |
| --repo "${GITHUB_REPOSITORY}" \ | |
| --title "${RELEASE_TAG}" \ | |
| --notes-file .dev-tools/release-notes.md | |
| else | |
| gh release create "${RELEASE_TAG}" \ | |
| --repo "${GITHUB_REPOSITORY}" \ | |
| --target "${RELEASE_TARGET}" \ | |
| --title "${RELEASE_TAG}" \ | |
| --notes-file .dev-tools/release-notes.md | |
| fi |