From 11a848414e651bf44bce6abbf3c15d793cf6179b Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Fri, 9 Feb 2024 23:06:36 +0100 Subject: [PATCH] consolidate generate-sandboxes workflows into a single workflow and composite action --- .../generate-sandboxes-composite-action.yml | 58 ++++++++++++++++++ .github/workflows/generate-sandboxes-main.yml | 60 ------------------- .github/workflows/generate-sandboxes.yml | 34 +++++++++++ 3 files changed, 92 insertions(+), 60 deletions(-) create mode 100644 .github/actions/generate-sandboxes-composite-action.yml delete mode 100644 .github/workflows/generate-sandboxes-main.yml create mode 100644 .github/workflows/generate-sandboxes.yml diff --git a/.github/actions/generate-sandboxes-composite-action.yml b/.github/actions/generate-sandboxes-composite-action.yml new file mode 100644 index 000000000000..d47166c73ec4 --- /dev/null +++ b/.github/actions/generate-sandboxes-composite-action.yml @@ -0,0 +1,58 @@ +name: Generate and push sandboxes action +description: This is a composite action that generates sandboxes and pushes them to the storybookjs/sandboxes repository + +inputs: + destination-branch: + description: The destination branch to generate sandboxes to in the storybookjs/sandboxes repository + required: true + +defaults: + run: + shell: bash + working-directory: ./code + +runs: + using: "composite" + steps: + - uses: actions/setup-node@v3 + with: + node-version-file: ".nvmrc" + + - name: Setup git user + run: | + git config --global user.name "storybook-bot" + git config --global user.email "32066757+storybook-bot@users.noreply.github.com" + + - name: Install dependencies + working-directory: ./scripts + env: + YARN_ENABLE_IMMUTABLE_INSTALLS: false + run: node --experimental-modules ./check-dependencies.js + + - name: Compile Storybook libraries + run: yarn task --task compile --start-from=auto --no-link + + - name: Publish to local registry + run: yarn local-registry --publish + + - name: Run local registry + run: yarn local-registry --open & + + - name: Wait for registry + run: yarn wait-on tcp:127.0.0.1:6001 + + - name: Generate + env: + CLEANUP_SANDBOX_NODE_MODULES: true + run: yarn generate-sandboxes --local-registry + + - name: Publish + run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/sandboxes.git --push --branch=${{ inputs.destination-branch }} + + - name: The job has failed + if: ${{ failure() || cancelled() }} + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_URL }} + uses: Ilshidur/action-discord@master + with: + args: "The generation of sandboxes in the **${{ inputs.destination-branch }}** branch has failed. [View Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" diff --git a/.github/workflows/generate-sandboxes-main.yml b/.github/workflows/generate-sandboxes-main.yml deleted file mode 100644 index cc17376c57de..000000000000 --- a/.github/workflows/generate-sandboxes-main.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Generate and push sandboxes (main) - -on: - schedule: - - cron: '2 2 */1 * *' - workflow_dispatch: - # To test fixes on push rather than wait for the scheduling, do the following: - # 1. Uncomment the lines below and add your branch. - # push: - # branches: - # - - # 2. change the "ref" value to in the actions/checkout step below. - # 3. 👉 DON'T FORGET TO UNDO THE VALUES BACK TO `main` BEFORE YOU MERGE YOUR CHANGES! - -jobs: - generate: - runs-on: ubuntu-latest - env: - YARN_ENABLE_IMMUTABLE_INSTALLS: false - CLEANUP_SANDBOX_NODE_MODULES: true - steps: - - uses: actions/checkout@v3 - with: - ref: main - - uses: actions/setup-node@v3 - with: - node-version-file: '.nvmrc' - - name: Setup git user - run: | - git config --global user.name "Storybook Bot" - git config --global user.email "bot@storybook.js.org" - - name: Install dependencies - run: | - cd ./scripts - node --experimental-modules ./check-dependencies.js - cd .. - - name: Compile Storybook libraries - run: yarn task --task compile --start-from=auto --no-link - - name: Publishing to local registry - run: yarn local-registry --publish - working-directory: ./code - - name: Running local registry - run: yarn local-registry --open & - working-directory: ./code - - name: Wait for registry - run: yarn wait-on tcp:127.0.0.1:6001 - working-directory: ./code - - name: Generate - run: yarn generate-sandboxes --local-registry - working-directory: ./code - - name: Publish - run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/sandboxes.git --push --branch=main - working-directory: ./code - - name: The job has failed - if: ${{ failure() || cancelled() }} - env: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_URL }} - uses: Ilshidur/action-discord@master - with: - args: 'The generation of sandboxes in the **main** branch has failed. [View Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})' diff --git a/.github/workflows/generate-sandboxes.yml b/.github/workflows/generate-sandboxes.yml new file mode 100644 index 000000000000..dd80cefcb790 --- /dev/null +++ b/.github/workflows/generate-sandboxes.yml @@ -0,0 +1,34 @@ +name: Generate and push sandboxes + +on: + schedule: + - cron: "2 2 */1 * *" + workflow_dispatch: + # To test fixes on push rather than wait for the scheduling, do the following: + # 1. Uncomment the lines below and add your branch. + # push: + # branches: + # - + # 2. Change the "ref" value to in the actions/checkout step below. + # 3. Comment out the whole "generate-main" job starting at line 26 + # 3. 👉 DON'T FORGET TO UNDO STEP 2 AND 3 BEFORE YOU MERGE YOUR CHANGES! + +jobs: + generate-next: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: next + - uses: .github/actions/generate-sandboxes-composite-action.yml + with: + destination-branch: next + generate-main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: main + - uses: .github/actions/generate-sandboxes-composite-action.yml + with: + destination-branch: main