Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handle-release-branches-workflow #16580

Merged
merged 1 commit into from
Nov 11, 2021
Merged

Conversation

kylegach
Copy link
Contributor

@kylegach kylegach commented Nov 3, 2021

Why

To trigger branch-based versioned docs builds, we need to do some branch management between this repo and frontpage. By automating the creation of the release-x-x branches (both here and in frontpage), we can develop as usual, without having to manually ensure that the release-x-x branches are kept in-sync with main & next (here) and master (frontpage).

What I did

Scenarios

For each of the scenarios below, assume:

  • "latest" (master branch) version is 6.3
  • "next" (next branch) version is 6.4

On push to main

  • Use webhook to kick off production frontpage deploy

main

On push to next

  • Creates & force-pushes release-6-4 branch
  • Sends dispatch event to frontpage repo to create release-6-4 branch

next

On push to release-x-x

  • If pushing to release-6-4
    • Warns that changes will be lost on next push to next
    • release-6-3
    • release-6-3-error
  • Else
    • Sends dispatch event to frontpage repo to create release-x-x branch
    • release-6-0

Questions

  • Should this PR be against main?
  • I think this workflow would obviate the need for the build-frontpage script. Is that correct?
    • If not, that script or this workflow will likely need modified to live alongside one another
  • Have I done enough to safeguard this workflow?
  • Is there a better way to alert of potentially lost changes than a failure w/ logged warning?
    • PR comment, perhaps?
  • Sending the dispatch event to frontpage will require an access token. I'm unsure what that should be. Do we have a bot account for such things?

@kylegach kylegach requested a review from shilman November 3, 2021 19:50
@nx-cloud
Copy link

nx-cloud bot commented Nov 3, 2021

Nx Cloud Report

CI ran the following commands for commit 0308885. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch

Status Command
#000000 nx run-many --target=prepare --all --parallel --max-parallel=15

Sent with 💌 from NxCloud.

steps:
- if: ${{ needs.branch-checks.outputs.is-actionable-branch == 'true' && needs.latest-or-next-release-branch-check.outputs.check == 'false' }}
run: |
curl -X POST https://api.github.com/repos/storybookjs/frontpage/dispatches \
Copy link
Contributor Author

@kylegach kylegach Nov 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This technique is from:

The frontpage workflow would look like:

name: Respond to request-create-frontpage-branch

on: [repository_dispatch]

jobs:
  build:
    runs-on: ubuntu-latest
    if: github.event.action == 'request-create-frontpage-branch'
    steps:
      - uses: actions/checkout@v2
      - run: |
          echo "Creating `${{ github.event.client_payload.branch }}` branch..."
          git branch temp
          git push -f origin temp:${{ github.event.client_payload.branch }}
          curl -X POST https://api.github.com/repos/kylegach/actions-test-a/dispatches \
          -H 'Accept: application/vnd.github.v3+json' \
          -u ${{ secrets.ACCESS_TOKEN }} \
          --data '{"event_type": "created-frontpage-branch", "client_payload": { "branch": "${{ needs.branch-checks.outputs.branch }}" }}'

Pushing the release-x-x branch would then kick off a Netlify build for that branch, which would pull in the appropriate version's content from this repo's release-x-x branch.

The curl above would allow for this repo to receive a confirmation message, if desired. Otherwise, it can be removed.

@kylegach kylegach force-pushed the handle-release-branches-workflow branch from 364b727 to 5e95e33 Compare November 3, 2021 20:34
@shilman shilman added the maintenance User-facing maintenance tasks label Nov 4, 2021
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this PR be against main?

No, next is the default branch

I think this workflow would obviate the need for the build-frontpage script. Is that correct?
If not, that script or this workflow will likely need modified to live alongside one another

Yes, I believe so

Have I done enough to safeguard this workflow? Is there a better way to alert of potentially lost changes than a failure w/ logged warning? Which steps could fail?

At any rate, since this is only copying the branch automatically, we never lose information correct? We only run the risk of some info not propagating properly

Sending the dispatch event to frontpage will require an access token. I'm unsure what that should be. Do we have a bot account for such things?

Yes we do -- DM'ing

.github/workflows/handle-release-branches.yml Show resolved Hide resolved
@kylegach
Copy link
Contributor Author

kylegach commented Nov 4, 2021

Why temp.xxx?

Because the value of ${{ needs.get-next-release-branch.outputs.branch }}, e.g. release-6-4 is likely to already exist, and this was easier and more straightforward (imo) than finding a way around the error when creating a branch that already exists.

@shilman
Copy link
Member

shilman commented Nov 4, 2021

@kylegach is the frontpage side set up to read temp:xxx branches? or am i misunderstanding

@kylegach
Copy link
Contributor Author

kylegach commented Nov 4, 2021

@kylegach is the frontpage side set up to read temp:xxx branches? or am i misunderstanding

That's a syntax to push the local temp branch to (something like) release-6-4 on the remote.

More info: https://stackoverflow.com/a/28302850

kylegach added a commit to storybookjs/frontpage that referenced this pull request Nov 4, 2021
- Responds to event dispatched by monorepo workflow
    - storybookjs/storybook#16580
@kylegach
Copy link
Contributor Author

kylegach commented Nov 5, 2021

since this is only copying the branch automatically, we never lose information correct? We only run the risk of some info not propagating properly

Realized I never answered this. 🤦‍♂️ To explain, I'll keep the same assumptions from the description: "latest" = 6.3 and "next" = 6.4. This workflow has one potentially dangerous outcome: push to next creates release-6-4, which is then force-pushed over whatever release-6-4 may be on remote. So I'm fairly sure the only data loss would be from someone pushing to release-6-4 directly, which this workflow explicitly no-ops and warns about (via a failure and a log message).

@kylegach kylegach marked this pull request as ready for review November 5, 2021 16:09
@kylegach
Copy link
Contributor Author

kylegach commented Nov 9, 2021

I don't believe the failing CircleCi checks, which are both e2e tests, are related.

- Assuming "latest" is 6.3 & "next" is 6.4...
- On push to `main`
    - Use webhook to kick off production frontpage deploy
- On push to `next`
    - Creates & force-pushes `release-6-4` branch
    - Sends dispatch event to frontpage repo to create `release-6-4` branch
- On push to `release-x-x`
    - If pushing to `release-6-4`
        - Warns that changes will be lost on next push to `next`
    - Else
        - Sends dispatch event to frontpage repo to create `release-n-n` branch
- Remove `build-frontpage` script
    - Remove references from teamcity & circleci configs
@kylegach kylegach force-pushed the handle-release-branches-workflow branch from bf30421 to 0308885 Compare November 11, 2021 15:13
@kylegach kylegach merged commit b09ca06 into next Nov 11, 2021
@kylegach kylegach deleted the handle-release-branches-workflow branch November 11, 2021 16:23
@shilman
Copy link
Member

shilman commented Nov 11, 2021

Amazing job @kylegach !!! 🚀

kylegach added a commit that referenced this pull request Nov 11, 2021
…rkflow

Add handle-release-branches-workflow

(Also includes 3757dd8, f3d4353, 6aac0a7 from `next`)
kylegach added a commit that referenced this pull request Nov 11, 2021
…rkflow

Add handle-release-branches-workflow

(Also includes 3757dd8, f3d4353, 6aac0a7, e8494fb from `next`)
kylegach added a commit that referenced this pull request Nov 11, 2021
…rkflow

Add handle-release-branches-workflow

(Also includes 3757dd8, f3d4353, 6aac0a7, e8494fb from `next`)
kylegach added a commit that referenced this pull request Nov 11, 2021
…rkflow

Add handle-release-branches-workflow

(Also includes 3757dd8, f3d4353, 6aac0a7, e8494fb from `next`)
kylegach added a commit that referenced this pull request Nov 11, 2021
…rkflow

Add handle-release-branches-workflow

(Also includes 3757dd8, f3d4353, 6aac0a7, e8494fb from `next`)
kylegach added a commit that referenced this pull request Nov 11, 2021
…rkflow

Add handle-release-branches-workflow

(Also includes 3757dd8, f3d4353, 6aac0a7, e8494fb from `next`)
jackwolfskin0302 added a commit to jackwolfskin0302/frontend that referenced this pull request Aug 31, 2022
- Responds to event dispatched by monorepo workflow
    - storybookjs/storybook#16580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants