Skip to content

Commit

Permalink
Merge pull request #16580 from storybookjs/handle-release-branches-wo…
Browse files Browse the repository at this point in the history
…rkflow

Add handle-release-branches-workflow

(Also includes 3757dd8, f3d4353, 6aac0a7, e8494fb from `next`)
  • Loading branch information
kylegach committed Nov 11, 2021
1 parent 7b44fa2 commit 4cb0a54
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 68 deletions.
14 changes: 0 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,6 @@ jobs:
command: |
cd examples/cra-react15
yarn storybook --smoke-test --quiet
frontpage:
executor: sb_node_12_browsers
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
- run:
name: Install dependencies
command: yarn install --immutable
- run:
name: Trigger build
command: ./scripts/build-frontpage.js
lint:
executor:
class: small
Expand Down Expand Up @@ -446,6 +435,3 @@ workflows:
- cra-bench:
requires:
- publish
deploy:
jobs:
- frontpage
98 changes: 98 additions & 0 deletions .github/workflows/handle-release-branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Handle Release Branches

on:
push:

jobs:
branch-checks:
runs-on: ubuntu-latest
steps:
- id: get-branch
run: |
BRANCH=($(echo ${{ github.ref }} | sed -E 's/refs\/heads\///'))
echo "branch=$BRANCH" >> $GITHUB_ENV
outputs:
branch: ${{ env.branch }}
is-latest-branch: ${{ env.branch == 'main' }}
is-next-branch: ${{ env.branch == 'next' }}
is-release-branch: ${{ startsWith(env.branch, 'release-') }}
is-actionable-branch: ${{ env.branch == 'main' || env.branch == 'next' || startsWith(env.branch, 'release-') }}

handle-latest:
needs: branch-checks
if: ${{ needs.branch-checks.outputs.is-latest-branch == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- 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
steps:
- uses: actions/checkout@v2
with:
ref: next
path: next

- id: next-version
uses: notiz-dev/github-action-json-property@release
with:
path: ${{ github.workspace }}/next/docs/versions/next.json
prop_path: version

- run: |
NEXT_RELEASE_BRANCH=($(echo ${{ steps.next-version.outputs.prop }} | sed -E 's/([0-9]+)\.([0-9]+).*/release-\1-\2/'))
echo "next-release-branch=$NEXT_RELEASE_BRANCH" >> $GITHUB_ENV
outputs:
branch: ${{ env.next-release-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
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- run: |
REMOTE_BRANCH=$(git branch -a | grep remotes/origin/${{ needs.get-next-release-branch.outputs.branch }})
if [[ ! -z $REMOTE_BRANCH ]]; then git push origin --delete ${{ needs.get-next-release-branch.outputs.branch }}; fi
echo 'Pushing branch ${{ needs.get-next-release-branch.outputs.branch }}...'
git push -f origin ${{ needs.branch-checks.outputs.branch }}:${{ needs.get-next-release-branch.outputs.branch }}
outputs:
branch: ${{ needs.get-next-release-branch.outputs.branch }}

next-release-branch-check:
if: ${{ always() }}
needs: [branch-checks, get-next-release-branch]
runs-on: ubuntu-latest
steps:
- run: |
IS_NEXT_RELEASE_BRANCH=${{ needs.branch-checks.outputs.branch == needs.get-next-release-branch.outputs.branch }}
echo "is-next-release-branch=$IS_NEXT_RELEASE_BRANCH" >> $GITHUB_ENV
- if: ${{ env.is-next-release-branch == 'true' }}
run: echo "relevant-base-branch=next" >> $GITHUB_ENV

- if: ${{ env.is-next-release-branch == '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 `${{ env.relevant-base-branch }}` branch and the changes you just pushed will be lost.'
exit 1
outputs:
check: ${{ env.is-next-release-branch }}

request-create-frontpage-branch:
if: ${{ always() }}
needs: [branch-checks, next-release-branch-check, create-next-release-branch]
runs-on: ubuntu-latest
steps:
- if: ${{ needs.branch-checks.outputs.is-actionable-branch == 'true' && needs.next-release-branch-check.outputs.check == 'false' }}
run: |
curl -X POST https://api.github.com/repos/storybookjs/frontpage/dispatches \
-H 'Accept: application/vnd.github.v3+json' \
-u ${{ secrets.FRONTPAGE_ACCESS_TOKEN }} \
--data '{"event_type": "request-create-frontpage-branch", "client_payload": { "branch": "${{ needs.create-next-release-branch.outputs.branch || needs.branch-checks.outputs.branch }}" }}'
30 changes: 0 additions & 30 deletions .teamcity/settings.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ project {
buildType(Build)
buildType(E2E)
buildType(SmokeTests)
buildType(Frontpage)
buildType(Test)
buildType(Coverage)

Expand All @@ -56,7 +55,6 @@ project {
RelativeId("Build"),
RelativeId("E2E"),
RelativeId("SmokeTests"),
RelativeId("Frontpage"),
RelativeId("Test"),
RelativeId("Coverage")
)
Expand Down Expand Up @@ -403,34 +401,6 @@ object SmokeTests : BuildType({
}
})

object Frontpage : BuildType({
name = "Frontpage"
type = Type.DEPLOYMENT

steps {
script {
scriptContent = """
#!/bin/bash
set -e -x
yarn install --immutable
yarn bootstrap --install
node ./scripts/build-frontpage.js
""".trimIndent()
dockerImage = "node:12"
dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux
}
}

triggers {
vcs {
quietPeriodMode = VcsTrigger.QuietPeriodMode.USE_DEFAULT
triggerRules = "-:.teamcity/**"
branchFilter = "+:main"
}
}
})

object Test : BuildType({
name = "Test"

Expand Down
24 changes: 0 additions & 24 deletions scripts/build-frontpage.js

This file was deleted.

0 comments on commit 4cb0a54

Please sign in to comment.