Skip to content

Prepare patch PR, triggered by pull[bot] #663

Prepare patch PR, triggered by pull[bot]

Prepare patch PR, triggered by pull[bot] #663

name: Prepare patch PR
run-name: Prepare patch PR, triggered by ${{ github.triggering_actor }}
on:
push:
branches:
- next
workflow_dispatch:
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
permissions: {}
jobs:
prepare-patch-pull-request:
name: Prepare patch pull request
if: github.repository_owner == 'storybookjs'
runs-on: ubuntu-latest
environment: Release
permissions:
contents: write
pull-requests: write
actions: write
defaults:
run:
working-directory: scripts
steps:
- name: Checkout main
# zizmor: ignore[artipacked] # git push --force origin uses persisted GH_TOKEN credentials
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: main
token: ${{ secrets.GH_TOKEN }}
- name: Setup Node.js and Install Dependencies
uses: ./.github/actions/setup-node-and-install
- name: Check if pull request is frozen
if: github.event_name != 'workflow_dispatch'
id: check-frozen
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: yarn release:is-pr-frozen --patch
- name: Cancel when frozen
if: steps.check-frozen.outputs.frozen == 'true' && github.event_name != 'workflow_dispatch'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_ID: ${{ github.run_id }}
# From https://stackoverflow.com/a/75809743
run: |
gh run cancel "$RUN_ID"
gh run watch "$RUN_ID"
- name: Check for unreleased changes
id: unreleased-changes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: yarn release:unreleased-changes-exists --unpicked-patches
- name: Fetch next branch
run:
# depth needs to be set to a high enough number that it will contain all the merge commits to cherry-pick
# as of May 2023, the whole repo had 55K commits
git fetch --depth=2000 origin next
- name: Pick patches
id: pick-patches
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name 'storybook-bot'
git config --global user.email '32066757+storybook-bot@users.noreply.github.com'
yarn release:pick-patches
- name: Cancel when no patches to pick
if: steps.pick-patches.outputs.no-patch-prs == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_ID: ${{ github.run_id }}
# From https://stackoverflow.com/a/75809743
run: |
gh run cancel "$RUN_ID"
gh run watch "$RUN_ID"
- name: Bump version deferred
id: bump-version
if: steps.unreleased-changes.outputs.has-changes-to-release == 'true'
run: |
yarn release:version --deferred --release-type patch --verbose
# We need the current version to set the branch name, even when not bumping the version
- name: Get current version
id: current-version
if: steps.unreleased-changes.outputs.has-changes-to-release == 'false'
run: |
yarn release:get-current-version --verbose
- name: Set version output
id: versions
env:
BUMP_CURRENT: ${{ steps.bump-version.outputs.current-version }}
BUMP_NEXT: ${{ steps.bump-version.outputs.next-version }}
CUR_CURRENT: ${{ steps.current-version.outputs.current-version }}
run: |
echo "current=${BUMP_CURRENT:-$CUR_CURRENT}" >> "$GITHUB_OUTPUT"
echo "next=${BUMP_NEXT:-$CUR_CURRENT}" >> "$GITHUB_OUTPUT"
- name: Write changelog
if: steps.unreleased-changes.outputs.has-changes-to-release == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEXT_VERSION: ${{ steps.versions.outputs.next }}
run: |
yarn release:write-changelog "$NEXT_VERSION" --unpicked-patches --verbose
- name: 'Commit changes to branch: version-patch-from-${{ steps.versions.outputs.current }}'
working-directory: .
env:
CURRENT_VERSION: ${{ steps.versions.outputs.current }}
NEXT_VERSION: ${{ steps.versions.outputs.next }}
run: |
git config --global user.name 'storybook-bot'
git config --global user.email '32066757+storybook-bot@users.noreply.github.com'
git checkout -b "version-patch-from-${CURRENT_VERSION}"
git add .
git commit --allow-empty --no-verify -m "Write changelog for ${NEXT_VERSION} [skip ci]"
git push --force origin "version-patch-from-${CURRENT_VERSION}"
- name: Generate PR description
id: description
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HAS_CHANGES: ${{ steps.unreleased-changes.outputs.has-changes-to-release }}
CURRENT_VERSION: ${{ steps.versions.outputs.current }}
NEXT_VERSION: ${{ steps.versions.outputs.next }}
FAILED_PICKS: ${{ steps.pick-patches.outputs.failed-cherry-picks }}
run: |
ARGS=(--unpicked-patches --manual-cherry-picks="$FAILED_PICKS")
if [[ "$HAS_CHANGES" == "true" ]]; then
ARGS+=(--current-version "$CURRENT_VERSION" --next-version "$NEXT_VERSION")
fi
yarn release:generate-pr-description "${ARGS[@]}" --verbose
- name: Create or update pull request with release
if: steps.unreleased-changes.outputs.has-changes-to-release == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
NEXT_VERSION: ${{ steps.versions.outputs.next }}
CURRENT_VERSION: ${{ steps.versions.outputs.current }}
DESCRIPTION: ${{ steps.description.outputs.description }}
run: |
if PR_STATE=$(gh pr view --json state --jq .state 2>/dev/null) && [[ -n "$PR_STATE" && "$PR_STATE" == *"OPEN"* ]]; then
gh pr edit \
--repo "$REPO" \
--title "Release: Patch ${NEXT_VERSION}" \
--body "$DESCRIPTION"
else
gh pr create \
--repo "$REPO" \
--title "Release: Patch ${NEXT_VERSION}" \
--label "release" \
--base latest-release \
--head "version-patch-from-${CURRENT_VERSION}" \
--body "$DESCRIPTION"
fi
- name: Create or update pull request without release
if: steps.unreleased-changes.outputs.has-changes-to-release == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
CURRENT_VERSION: ${{ steps.versions.outputs.current }}
DESCRIPTION: ${{ steps.description.outputs.description }}
run: |
if PR_STATE=$(gh pr view --json state --jq .state 2>/dev/null) && [[ -n "$PR_STATE" && "$PR_STATE" == *"OPEN"* ]]; then
gh pr edit \
--repo "$REPO" \
--title "Release: Merge patches to \`main\` (without version bump)" \
--body "$DESCRIPTION"
else
gh pr create \
--repo "$REPO" \
--title "Release: Merge patches to \`main\` (without version bump)" \
--label "release" \
--base latest-release \
--head "version-patch-from-${CURRENT_VERSION}" \
--body "$DESCRIPTION"
fi
- name: Report job failure to Discord
if: failure()
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_URL }}
uses: Ilshidur/action-discord@d2594079a10f1d6739ee50a2471f0ca57418b554 # v0.4.0
with:
args: 'The GitHub Action for preparing the release pull request bumping from v${{ steps.versions.outputs.current }} to v${{ steps.versions.outputs.next }} (triggered by ${{ github.triggering_actor }}) failed! See run at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'