Merge pull request #35335 from storybookjs/ghengeveld/review-thumbnai… #668
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: Handle Release Branches | |
| on: | |
| push: | |
| permissions: {} | |
| jobs: | |
| branch-checks: | |
| if: github.repository_owner == 'storybookjs' | |
| runs-on: ubuntu-latest | |
| permissions: {} | |
| steps: | |
| - id: get-branch | |
| env: | |
| REF: ${{ github.ref }} | |
| run: | | |
| BRANCH="${REF#refs/heads/}" | |
| echo "branch=$BRANCH" >> "$GITHUB_OUTPUT" | |
| outputs: | |
| branch: ${{ steps.get-branch.outputs.branch }} | |
| is-latest-branch: ${{ steps.get-branch.outputs.branch == 'main' }} | |
| is-next-branch: ${{ steps.get-branch.outputs.branch == 'next' }} | |
| is-release-branch: ${{ startsWith(steps.get-branch.outputs.branch, 'release-') }} | |
| is-actionable-branch: ${{ steps.get-branch.outputs.branch == 'main' || steps.get-branch.outputs.branch == 'next' || startsWith(steps.get-branch.outputs.branch, 'release-') }} | |
| handle-latest: | |
| needs: branch-checks | |
| if: ${{ needs.branch-checks.outputs.is-latest-branch == 'true' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: main | |
| persist-credentials: false | |
| - run: curl -X POST "https://api.netlify.com/build_hooks/${{ secrets.FRONTPAGE_HOOK }}" | |
| get-next-release-branch: | |
| needs: branch-checks | |
| if: ${{ needs.branch-checks.outputs.is-next-branch == 'true' || needs.branch-checks.outputs.is-release-branch == 'true' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: next | |
| path: next | |
| persist-credentials: false | |
| - id: next-release-branch | |
| run: | | |
| NEXT_RELEASE_BRANCH=$(jq -r '.version | capture("^(?<maj>[0-9]+)\\.(?<min>[0-9]+)") | "release-\(.maj)-\(.min)"' next/code/package.json) | |
| echo "branch=$NEXT_RELEASE_BRANCH" >> $GITHUB_OUTPUT | |
| outputs: | |
| branch: ${{ steps.next-release-branch.outputs.branch }} | |
| create-next-release-branch: | |
| needs: [branch-checks, get-next-release-branch] | |
| if: ${{ needs.branch-checks.outputs.is-next-branch == 'true' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout (with creds for later git push) | |
| # zizmor: ignore[artipacked] # git push origin requires persisted credentials | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - env: | |
| TARGET_BRANCH: ${{ needs.get-next-release-branch.outputs.branch }} | |
| SOURCE_BRANCH: ${{ needs.branch-checks.outputs.branch }} | |
| run: | | |
| set +e | |
| REMOTE_BRANCH=$(git branch -r | grep "origin/${TARGET_BRANCH}") | |
| if [[ -n "$REMOTE_BRANCH" ]]; then git push origin --delete "$TARGET_BRANCH"; fi | |
| echo "Pushing branch ${TARGET_BRANCH}..." | |
| git push -f origin "${SOURCE_BRANCH}:${TARGET_BRANCH}" | |
| outputs: | |
| branch: ${{ needs.get-next-release-branch.outputs.branch }} | |
| next-release-branch-check: | |
| if: ${{ always() && github.repository_owner == 'storybookjs' }} | |
| needs: [branch-checks, get-next-release-branch] | |
| runs-on: ubuntu-latest | |
| permissions: {} | |
| steps: | |
| - id: is-next-release-branch | |
| run: | | |
| IS_NEXT_RELEASE_BRANCH=${{ needs.branch-checks.outputs.branch == needs.get-next-release-branch.outputs.branch }} | |
| echo "result=$IS_NEXT_RELEASE_BRANCH" >> $GITHUB_OUTPUT | |
| - id: relevant-base-branch | |
| if: ${{ steps.is-next-release-branch.outputs.result == 'true' }} | |
| run: echo "relevant-base-branch=next" >> $GITHUB_OUTPUT | |
| - if: ${{ steps.is-next-release-branch.outputs.result == 'true' }} | |
| run: | | |
| echo 'WARNING: Do not push directly to the `${{ needs.branch-checks.outputs.branch }}` branch. This branch is created and force-pushed over after pushing to the `${{ steps.relevant-base-branch.outputs.relevant-base-branch }}` branch and the changes you just pushed will be lost.' | |
| exit 1 | |
| outputs: | |
| check: ${{ steps.is-next-release-branch.outputs.result }} | |
| request-create-frontpage-branch: | |
| if: ${{ always() && github.repository_owner == 'storybookjs' }} | |
| needs: | |
| [branch-checks, next-release-branch-check, create-next-release-branch] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - if: ${{ needs.branch-checks.outputs.is-actionable-branch == 'true' && needs.branch-checks.outputs.is-latest-branch == 'false' && needs.next-release-branch-check.outputs.check == 'false' }} | |
| env: | |
| BRANCH: ${{ needs.create-next-release-branch.outputs.branch || needs.branch-checks.outputs.branch }} | |
| FRONTPAGE_TOKEN: ${{ secrets.FRONTPAGE_ACCESS_TOKEN }} | |
| run: | | |
| DISPATCH_PAYLOAD=$(jq -n --arg branch "$BRANCH" \ | |
| '{event_type: "request-create-frontpage-branch", client_payload: {branch: $branch}}') | |
| curl -X POST https://api.github.com/repos/storybookjs/frontpage/dispatches \ | |
| -H 'Accept: application/vnd.github.v3+json' \ | |
| -u "$FRONTPAGE_TOKEN" \ | |
| --data "$DISPATCH_PAYLOAD" |