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