Publish new version on next-release, triggered by shilman #105
This file contains 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: Publish | |
run-name: Publish new version on ${{ github.ref_name }}, triggered by ${{ github.triggering_actor }} | |
on: | |
push: | |
branches: | |
- latest-release | |
- next-release | |
env: | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 | |
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1 | |
permissions: | |
contents: write | |
pull-requests: write | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref_name }} | |
jobs: | |
publish: | |
name: Publish new version | |
runs-on: ubuntu-latest | |
environment: release | |
defaults: | |
run: | |
working-directory: scripts | |
steps: | |
- name: Cancel if [skip ci] | |
if: contains(github.event.head_commit.message, '[skip ci]') | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# From https://stackoverflow.com/a/75809743 | |
run: | | |
gh run cancel ${{ github.run_id }} | |
gh run watch ${{ github.run_id }} | |
- name: Checkout ${{ github.ref_name }} | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 100 | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: '.nvmrc' | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.yarn/berry/cache | |
key: yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }} | |
restore-keys: | | |
yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }} | |
yarn-v1-${{ hashFiles('scripts/yarn.lock') }} | |
yarn-v1 | |
- name: Install script dependencies | |
run: | | |
yarn install | |
- 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: . | |
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 ${{ github.ref_name }} | |
- name: Get current version | |
id: version | |
run: yarn release:get-current-version | |
- name: Check if publish is needed | |
id: publish-needed | |
run: yarn release:is-version-published ${{ steps.version.outputs.current-version }} | |
- name: Check release vs prerelease | |
if: steps.publish-needed.outputs.published == 'false' | |
id: is-prerelease | |
run: yarn release:is-prerelease ${{ steps.version.outputs.current-version }} --verbose | |
- name: Install code dependencies | |
if: steps.publish-needed.outputs.published == 'false' | |
working-directory: . | |
run: yarn task --task=install --start-from=install | |
- name: Publish | |
if: steps.publish-needed.outputs.published == 'false' | |
env: | |
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
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 | |
run: yarn release:get-changelog-from-file ${{ steps.version.outputs.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 }} | |
run: | | |
gh release create \ | |
v${{ steps.version.outputs.current-version }} \ | |
--repo "${{ github.repository }}" \ | |
--target ${{ github.ref_name }} \ | |
--title "v${{ steps.version.outputs.current-version }}" \ | |
--notes "${{ steps.changelog.outputs.changelog }}" \ | |
${{ steps.is-prerelease.outputs.prerelease == 'true' && '--prerelease' || '' }} | |
- name: Merge ${{ github.ref_name }} into ${{ steps.target.outputs.target }} | |
run: | | |
git config --global user.name "storybook-bot" | |
git config --global user.email "[email protected]" | |
git fetch origin ${{ steps.target.outputs.target }} | |
git checkout ${{ steps.target.outputs.target }} | |
git merge ${{ github.ref_name }} | |
git push origin ${{ steps.target.outputs.target }} | |
- name: Ensure `next` is a minor version ahead of `main` | |
if: steps.target.outputs.target == 'main' | |
run: | | |
git checkout next | |
git pull | |
yarn release:ensure-next-ahead --main-version "${{ steps.version.outputs.current-version }}" | |
git add .. | |
git diff --staged --quiet || git commit -m "Bump next to be one minor ahead of main [skip ci]" | |
git push origin next | |
- name: Sync CHANGELOG.md from `main` to `next` | |
if: steps.target.outputs.target == 'main' | |
working-directory: . | |
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${{ steps.version.outputs.current-version }} [skip ci]" || true | |
git push origin next | |
- name: Sync version JSONs from `next-release` to `main` | |
if: github.ref_name == 'next-release' | |
working-directory: . | |
run: | | |
VERSION_FILE="./docs/versions/${{ steps.is-prerelease.outputs.prerelease == 'true' && 'next' || 'latest' }}.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${{ steps.version.outputs.current-version }}" | |
git push origin main | |
- name: Report job failure to Discord | |
if: failure() | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_URL }} | |
uses: Ilshidur/action-discord@master | |
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 }}' |