|
1 | 1 | name: Trigger CircleCI workflow |
2 | 2 |
|
3 | | -on: push |
| 3 | +on: |
| 4 | + # Use pull_request_target, as we don't need to check out the actual code of the fork in this script. |
| 5 | + # And this is the only way to trigger the Circle CI API on forks as well. |
| 6 | + pull_request_target: |
| 7 | + types: [opened, synchronize, labeled, reopened] |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - next |
| 11 | + - main |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
4 | 17 | jobs: |
5 | | - test: |
| 18 | + get-branch: |
| 19 | + if: github.repository_owner == 'storybookjs' |
6 | 20 | runs-on: ubuntu-latest |
7 | | - defaults: |
8 | | - run: |
9 | | - working-directory: ./scripts |
10 | 21 | steps: |
11 | | - - name: Checkout ${{ github.ref_name }} |
12 | | - uses: actions/checkout@v4 |
13 | | - with: |
14 | | - fetch-depth: 100 |
| 22 | + - id: get-branch |
| 23 | + env: |
| 24 | + # Stored as environment variable to prevent script injection |
| 25 | + REF_NAME: ${{ github.ref_name }} |
| 26 | + PR_REF_NAME: ${{ github.event.pull_request.head.ref }} |
| 27 | + run: | |
| 28 | + if [ "${{ github.event.pull_request.head.repo.fork }}" = "true" ]; then |
| 29 | + export BRANCH=pull/${{ github.event.pull_request.number }}/head |
| 30 | + elif [ "${{ github.event_name }}" = "push" ]; then |
| 31 | + export BRANCH="$REF_NAME" |
| 32 | + else |
| 33 | + export BRANCH="$PR_REF_NAME" |
| 34 | + fi |
| 35 | + echo "$BRANCH" |
| 36 | + echo "branch=$BRANCH" >> $GITHUB_ENV |
| 37 | + outputs: |
| 38 | + branch: ${{ env.branch }} |
15 | 39 |
|
16 | | - - name: Setup Node.js and Install Dependencies |
17 | | - uses: ./.github/actions/setup-node-and-install |
| 40 | + get-parameters: |
| 41 | + if: github.repository_owner == 'storybookjs' |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - if: github.event_name == 'pull_request_target' && (contains(github.event.pull_request.labels.*.name, 'ci:normal')) |
| 45 | + run: echo "workflow=normal" >> $GITHUB_ENV |
| 46 | + - if: github.event_name == 'pull_request_target' && (contains(github.event.pull_request.labels.*.name, 'ci:docs')) |
| 47 | + run: echo "workflow=docs" >> $GITHUB_ENV |
| 48 | + - if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci:merged') |
| 49 | + run: echo "workflow=merged" >> $GITHUB_ENV |
| 50 | + - if: github.event_name == 'pull_request_target' && (contains(github.event.pull_request.labels.*.name, 'ci:daily')) |
| 51 | + run: echo "workflow=daily" >> $GITHUB_ENV |
| 52 | + outputs: |
| 53 | + workflow: ${{ env.workflow }} |
| 54 | + ghBaseBranch: ${{ github.event.pull_request.base.ref }} |
| 55 | + ghPrNumber: ${{ github.event.pull_request.number }} |
18 | 56 |
|
19 | | - - name: run compile |
20 | | - run: yarn task --task=compile --start-from=compile --no-link |
21 | | - - name: run compile |
22 | | - run: yarn task --task=compile --start-from=compile --no-link |
23 | | - - name: run compile |
24 | | - run: yarn task --task=compile --start-from=compile --no-link |
25 | | - - name: run compile |
26 | | - run: yarn task --task=compile --start-from=compile --no-link |
| 57 | + trigger-circle-ci-workflow: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: [get-branch, get-parameters] |
| 60 | + if: github.repository_owner == 'storybookjs' && needs.get-parameters.outputs.workflow != '' |
| 61 | + steps: |
| 62 | + - name: Trigger Normal tests |
| 63 | + uses: fjogeleit/http-request-action@v1 |
| 64 | + with: |
| 65 | + url: 'https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline' |
| 66 | + method: 'POST' |
| 67 | + customHeaders: '{"Content-Type": "application/json", "Circle-Token": "${{ secrets.CIRCLE_CI_TOKEN }}"}' |
| 68 | + data: '{ "branch": "${{needs.get-branch.outputs.branch}}", "parameters": ${{toJson(needs.get-parameters.outputs)}} }' |
0 commit comments