Skip to content

Publish new version on 32899/merge, triggered by storybook-bot #1167

Publish new version on 32899/merge, triggered by storybook-bot

Publish new version on 32899/merge, triggered by storybook-bot #1167

Workflow file for this run

name: Publish
run-name: "${{ github.event_name == 'workflow_dispatch' && format('Publish Canary on PR #{0}, triggered by {1}', inputs.pr, github.triggering_actor) || format('Publish new version on {0}, triggered by {1}', github.ref_name, github.triggering_actor) }}"
on:
push:
# Normal releases, major/minor/patch/prerelease
branches:
- latest-release
- next-release
workflow_dispatch:
# Manual canary releases on PRs
inputs:
pr:
description: "⚠️ CANARY RELEASES ONLY - Enter the pull request number to create a canary release for"
required: true
type: number
pull_request:
# Automated canary releases on PRs with the "with-canary-release"-suffix in the branch name
types: [opened, synchronize, reopened]
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1
permissions:
id-token: write
contents: write
pull-requests: write
concurrency:
# Group concurrent runs based on the event type:
# - For workflow_dispatch and pull_request: group by PR number to allow only one canary release per PR
# - For push events: group by branch name to prevent multiple releases on the same branch
group: ${{ github.event_name == 'workflow_dispatch' && format('{0}-{1}', github.workflow, inputs.pr) || github.event_name == 'pull_request' && format('{0}-{1}', github.workflow, github.event.pull_request.number) || format('{0}-{1}', github.workflow, github.ref_name) }}
cancel-in-progress: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' }}
jobs:
publish-normal:
name: Publish normal version
runs-on: ubuntu-latest
if: |
github.event_name == 'push' &&
(github.ref_name == 'latest-release' || github.ref_name == 'next-release') &&
contains(github.event.head_commit.message, '[skip ci]') != true
environment: Release
defaults:
run:
working-directory: scripts
steps:
- name: Checkout ${{ github.ref_name }}
uses: actions/checkout@v4
with:
fetch-depth: 100
token: ${{ secrets.GH_TOKEN }}
- name: Setup Node.js and Install Dependencies
uses: ./.github/actions/setup-node-and-install
with:
install-code-deps: true
- name: Cancel all release preparation runs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: yarn release:cancel-preparation-runs
- name: Apply deferred version bump and commit
working-directory: .
env:
REF_NAME: ${{ github.ref_name }}
run: |
CURRENT_VERSION=$(cat ./code/package.json | jq '.version')
DEFERRED_NEXT_VERSION=$(cat ./code/package.json | jq '.deferredNextVersion')
if [[ "$DEFERRED_NEXT_VERSION" == "null" ]]; then
echo "No deferred version set, not bumping versions"
exit 0
fi
cd scripts
yarn release:version --apply --verbose
cd ..
git config --global user.name "storybook-bot"
git config --global user.email "[email protected]"
git add .
git commit -m "Bump version from $CURRENT_VERSION to $DEFERRED_NEXT_VERSION [skip ci]" || true
git push origin "$REF_NAME"
- name: Get current version
id: version
run: yarn release:get-current-version
- name: Check if publish is needed
id: publish-needed
env:
CURRENT_VERSION: ${{ steps.version.outputs.current-version }}
run: yarn release:is-version-published "$CURRENT_VERSION"
- name: Check release vs prerelease
if: steps.publish-needed.outputs.published == 'false'
id: is-prerelease
env:
CURRENT_VERSION: ${{ steps.version.outputs.current-version }}
run: yarn release:is-prerelease "$CURRENT_VERSION" --verbose
- name: Publish
if: steps.publish-needed.outputs.published == 'false'
run: yarn release:publish --tag ${{ steps.is-prerelease.outputs.prerelease == 'true' && 'next' || 'latest' }} --verbose
- name: Get target branch
id: target
run: echo "target=${{ github.ref_name == 'next-release' && 'next' || 'main' }}" >> $GITHUB_OUTPUT
- name: Get changelog for ${{ steps.version.outputs.current-version }}
if: steps.publish-needed.outputs.published == 'false'
id: changelog
env:
CURRENT_VERSION: ${{ steps.version.outputs.current-version }}
run: yarn release:get-changelog-from-file "$CURRENT_VERSION"
# tags are needed to get list of patches to label as picked
- name: Fetch git tags
if: github.ref_name == 'latest-release'
run: git fetch --tags origin
# when this is a patch release from main, label any patch PRs included in the release
- name: Label patch PRs as picked
if: github.ref_name == 'latest-release'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: yarn release:label-patches
- name: Create GitHub Release
if: steps.publish-needed.outputs.published == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CURRENT_VERSION: ${{ steps.version.outputs.current-version }}
REPOSITORY: ${{ github.repository }}
REF_NAME: ${{ github.ref_name }}
CHANGELOG: ${{ steps.changelog.outputs.changelog }}
IS_PRERELEASE: ${{ steps.is-prerelease.outputs.prerelease == 'true' && '--prerelease' || '' }}
run: |
gh release create \
"v$CURRENT_VERSION" \
--repo "$REPOSITORY" \
--target "$REF_NAME" \
--title "v$CURRENT_VERSION" \
--notes "$CHANGELOG" \
$IS_PRERELEASE
- name: Merge ${{ github.ref_name }} into ${{ steps.target.outputs.target }}
env:
REF_NAME: ${{ github.ref_name }}
TARGET_BRANCH: ${{ steps.target.outputs.target }}
run: |
git config --global user.name "storybook-bot"
git config --global user.email "[email protected]"
git fetch origin "$TARGET_BRANCH"
git checkout "$TARGET_BRANCH"
git merge "$REF_NAME"
git push origin "$TARGET_BRANCH"
- name: Force push from 'next' to 'latest-release' and 'main' on minor/major releases
if: github.ref_name == 'next-release' && steps.is-prerelease.outputs.prerelease == 'false'
run: |
git checkout next
git pull
git push origin --force next:latest-release
git push origin --force next:main
- name: Sync CHANGELOG.md from `main` to `next`
if: steps.target.outputs.target == 'main'
working-directory: .
env:
CURRENT_VERSION: ${{ steps.version.outputs.current-version }}
run: |
git fetch origin next
git checkout next
git pull
git checkout origin/main ./CHANGELOG.md
git add ./CHANGELOG.md
git commit -m "Update CHANGELOG.md for v$CURRENT_VERSION [skip ci]" || true
git push origin next
# Sync the next.json version file to the main branch so it gets deployed to the docs site
# but only if this is a prerelease, because in minor/major releases we're already force pushing next-release onto main, so it's already there
- name: Sync version JSONs from `next-release` to `main`
if: github.ref_name == 'next-release' && steps.is-prerelease.outputs.prerelease == 'true'
working-directory: .
env:
CURRENT_VERSION: ${{ steps.version.outputs.current-version }}
run: |
VERSION_FILE="./docs/versions/next.json"
git fetch origin main
git checkout main
git pull
git checkout origin/next-release $VERSION_FILE
git add $VERSION_FILE
git commit -m "Update $VERSION_FILE for v$CURRENT_VERSION"
git push origin main
- name: Create Sentry release
if: steps.publish-needed.outputs.published == 'false'
uses: getsentry/action-release@v3
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
release: ${{ steps.version.outputs.current-version }}
environment: ${{ steps.is-prerelease.outputs.prerelease == 'true' && 'prerelease' || 'latest' }}
- name: Report job failure to Discord
if: failure()
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_URL }}
uses: Ilshidur/action-discord@d2594079a10f1d6739ee50a2471f0ca57418b554
with:
args: "The GitHub Action for publishing version ${{ steps.version.outputs.current-version }} (triggered by ${{ github.triggering_actor }}) failed! See run at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
publish-canary:
name: Publish canary version
runs-on: ubuntu-latest
if: |
(
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' && endsWith(github.head_ref, 'with-canary-release'))
) &&
contains(github.event.head_commit.message, '[skip ci]') != true
environment: Release
steps:
- name: Fail if triggering actor is not administrator
uses: prince-chrismc/check-actor-permissions-action@87c6d9b36c730377858fd9719fbbac1b58fa678d
with:
permission: admin
- name: Get pull request information
id: info
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
PR_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr || github.event.pull_request.number }}
REPOSITORY: ${{ github.repository }}
run: |
PR_INFO=$(gh pr view "$PR_NUMBER" --repo "$REPOSITORY" --json isCrossRepository,headRefOid,headRefName,headRepository,headRepositoryOwner --jq '{isFork: .isCrossRepository, owner: .headRepositoryOwner.login, repoName: .headRepository.name, branch: .headRefName, sha: .headRefOid}')
echo $PR_INFO
# Loop through each key-value pair in PR_INFO and set as step output
for key in $(echo "$PR_INFO" | jq -r 'keys[]'); do
value=$(echo "$PR_INFO" | jq -r ".$key")
echo "$key=$value" >> "$GITHUB_OUTPUT"
done
echo "repository=$(echo "$PR_INFO" | jq -r ".owner")/$(echo "$PR_INFO" | jq -r ".repoName")" >> $GITHUB_OUTPUT
echo "shortSha=$(echo "$PR_INFO" | jq -r ".sha" | cut -c 1-8)" >> $GITHUB_OUTPUT
echo "date=$(date)" >> $GITHUB_OUTPUT
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ steps.info.outputs.isFork == 'true' && steps.info.outputs.repository || null }}
ref: ${{ steps.info.outputs.sha }}
token: ${{ secrets.GH_TOKEN }}
- name: Setup Node.js and Install Dependencies
uses: ./.github/actions/setup-node-and-install
with:
install-code-deps: true
- name: Set version
id: version
working-directory: scripts
env:
PR_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr || github.event.pull_request.number }}
SHORT_SHA: ${{ steps.info.outputs.shortSha }}
run: |
yarn release:version --exact "0.0.0-pr-$PR_NUMBER-sha-$SHORT_SHA" --verbose
- name: Publish v${{ steps.version.outputs.next-version }}
working-directory: scripts
run: yarn release:publish --tag canary --verbose
- name: Replace Pull Request Body
uses: ivangabriele/find-and-replace-pull-request-body@042438c6cbfbacf6a4701d6042f59b1f73db2fd8
with:
githubToken: ${{ secrets.GH_TOKEN }}
prNumber: ${{ github.event_name == 'workflow_dispatch' && inputs.pr || '' }}
find: "CANARY_RELEASE_SECTION"
isHtmlCommentTag: true
replace: |
This pull request has been released as version `${{ steps.version.outputs.next-version }}`. Try it out in a new sandbox by running `npx storybook@${{ steps.version.outputs.next-version }} sandbox` or in an existing project with `npx storybook@${{ steps.version.outputs.next-version }} upgrade`.
<details>
<summary>More information</summary>
| | |
| --- | --- |
| **Published version** | [`${{ steps.version.outputs.next-version }}`](https://npmjs.com/package/storybook/v/${{ steps.version.outputs.next-version }}) |
| **Triggered by** | @${{ github.triggering_actor }} |
| **Repository** | [${{ steps.info.outputs.repository }}](https://github.com/${{ steps.info.outputs.repository }}) |
| **Branch** | [`${{ steps.info.outputs.branch }}`](https://github.com/${{ steps.info.outputs.repository }}/tree/${{ steps.info.outputs.branch }}) |
| **Commit** | [`${{ steps.info.outputs.shortSha }}`](https://github.com/${{ steps.info.outputs.repository }}/commit/${{ steps.info.outputs.sha }}) |
| **Datetime** | ${{ steps.info.outputs.date }} (`${{ steps.info.outputs.timestamp }}`) |
| **Workflow run** | [${{ github.run_id }}](https://github.com/storybookjs/storybook/actions/runs/${{ github.run_id }}) |
To request a new release of this pull request, mention the `@storybookjs/core` team.
_core team members can create a new canary release [here](https://github.com/storybookjs/storybook/actions/workflows/publish.yml) or locally with `gh workflow run --repo storybookjs/storybook publish.yml --field pr=${{ github.event_name == 'workflow_dispatch' && inputs.pr || github.event.pull_request.number }}`_
</details>
- name: Create failing comment on PR
if: failure()
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
PR_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr || github.event.pull_request.number }}
REPOSITORY: ${{ github.repository }}
TRIGGERING_ACTOR: ${{ github.triggering_actor }}
RUN_ID: ${{ github.run_id }}
run: |
gh pr comment "$PR_NUMBER"\
--repo "$REPOSITORY"\
--body "Failed to publish canary version of this pull request, triggered by @$TRIGGERING_ACTOR. See the failed workflow run at: https://github.com/$REPOSITORY/actions/runs/$RUN_ID"