-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
114 lines (110 loc) · 4.14 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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, unlabeled, reopened, converted_to_draft, ready_for_review]
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 }}
trigger-normal-tests:
runs-on: ubuntu-latest
needs: get-branch
if: github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'ci:normal')
steps:
- name: Trigger Normal tests
run: >
curl -X POST --location "https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline" \
-H "Content-Type: application/json" \
-H "Circle-Token: $CIRCLE_CI_TOKEN" \
-d '{
"branch": "'"$BRANCH"'",
"parameters": {
"workflow": "normal"
}
}'
env:
CIRCLE_CI_TOKEN: ${{ secrets.CIRCLE_CI_TOKEN }}
BRANCH: ${{ needs.get-branch.outputs.branch }}
trigger-docs-tests:
runs-on: ubuntu-latest
needs: get-branch
if: github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'ci:docs')
steps:
- name: Trigger docs tests
run: >
curl -X POST --location "https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline" \
-H "Content-Type: application/json" \
-H "Circle-Token: $CIRCLE_CI_TOKEN" \
-d '{
"branch": "'"$BRANCH"'",
"parameters": {
"workflow": "docs"
}
}'
env:
CIRCLE_CI_TOKEN: ${{ secrets.CIRCLE_CI_TOKEN }}
BRANCH: ${{ needs.get-branch.outputs.branch }}
trigger-merged-tests:
runs-on: ubuntu-latest
needs: get-branch
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci:merged')
steps:
- name: Trigger merged tests
run: >
curl -X POST --location "https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline" \
-H "Content-Type: application/json" \
-H "Circle-Token: $CIRCLE_CI_TOKEN" \
-d '{
"branch": "'"$BRANCH"'",
"parameters": {
"workflow": "merged"
}
}'
env:
CIRCLE_CI_TOKEN: ${{ secrets.CIRCLE_CI_TOKEN }}
BRANCH: ${{ needs.get-branch.outputs.branch }}
trigger-daily-tests:
runs-on: ubuntu-latest
needs: get-branch
if: github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'ci:daily')
steps:
- name: Trigger the daily tests
run: >
curl -X POST --location "https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline" \
-H "Content-Type: application/json" \
-H "Circle-Token: $CIRCLE_CI_TOKEN" \
-d '{
"branch": "'"$BRANCH"'",
"parameters": {
"workflow": "daily"
}
}'
env:
CIRCLE_CI_TOKEN: ${{ secrets.CIRCLE_CI_TOKEN }}
BRANCH: ${{ needs.get-branch.outputs.branch }}