-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (148 loc) · 5.84 KB
/
ci.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: ci
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
permissions:
contents: read # Allows read access to the code in the repository
on:
push:
schedule:
- cron: '0 0 * * *' # Runs every midnight (00:00 UTC)
workflow_dispatch: # Allows manual triggering
jobs:
compile:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up node
uses: actions/setup-node@v4
- name: Compile
run: yarn && yarn build
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up node
uses: actions/setup-node@v4
- name: Compile & Test
run: yarn && yarn test
run-examples:
name: Run examples (to look for regressions)
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up node
uses: actions/setup-node@v4
with:
node-version: 21
- name: Build
run: yarn && yarn build
- name: Test examples
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Running hello world"
node examples/hello-world.mjs
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Running smoke test"
node examples/smoke-test.mjs
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Running trade search"
node examples/trade-search.mjs
publish:
needs: [compile, test, run-examples]
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up node
uses: actions/setup-node@v4
- name: Install dependencies
run: yarn install
- name: Build
run: yarn build
- name: Publish to npm
run: |
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
npm publish --access public
env:
NPM_TOKEN: ${{ secrets.SDK_NPM_TOKEN }}
notify-slack-ci:
name: Notify Slack - CI Jobs Completed
needs: [compile, test, run-examples]
runs-on: ubuntu-latest
if: success()
steps:
- name: Check for PR on the branch and get reviewers
id: pr_check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetch open PRs for the branch using GitHub API
PR_NUMBER=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open" \
| jq '.[0].number // empty')
if [ -n "$PR_NUMBER" ]; then
echo "This branch has an open pull request: #$PR_NUMBER"
echo "::set-output name=pr_number::$PR_NUMBER"
# Fetch reviewers for the PR
REVIEWERS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/requested_reviewers" \
| jq -r '.users[].login' | sed 's/^/@/g' | paste -sd ", ")
echo "::set-output name=reviewers::$REVIEWERS"
else
echo "No open pull requests for this branch."
echo "::set-output name=pr_number::"
echo "::set-output name=reviewers::"
fi
- name: Send Slack Notification
env:
WEBHOOK_URL: ${{ secrets.GH_ACTION_WEBHOOK_URL }}
GITHUB_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
REPOSITORY: ${{ github.repository }}
run: |
# Branch, PR, and reviewers info
BRANCH=${{ github.ref_name }}
PR_NUMBER="${{ steps.pr_check.outputs.pr_number }}"
REVIEWERS="${{ steps.pr_check.outputs.reviewers }}"
# Construct PR link if PR_NUMBER is set
if [ -n "$PR_NUMBER" ]; then
PULL_REQUEST_INFO="Pull-Request: <https://github.com/${REPOSITORY}/pull/${PR_NUMBER}|#${PR_NUMBER}>"
else
PULL_REQUEST_INFO=""
fi
# Include reviewers if available
if [ -n "$REVIEWERS" ]; then
REVIEWERS_INFO="Reviewers: $REVIEWERS"
else
REVIEWERS_INFO=""
fi
# Slack message format
MESSAGE="CI Build for Branch : *${BRANCH}* (${REPOSITORY})\nCommit Author : @${{ github.actor }}\n*Click <${GITHUB_RUN_URL}|here> for the job URL*"
# Append pull request info and reviewers if they exist
if [ -n "$PULL_REQUEST_INFO" ]; then
MESSAGE="$MESSAGE\n${PULL_REQUEST_INFO}"
fi
if [ -n "$REVIEWERS_INFO" ]; then
MESSAGE="$MESSAGE\n${REVIEWERS_INFO}"
fi
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"$MESSAGE\"}" $WEBHOOK_URL
notify-slack-publish:
name: Notify Slack - Publish Job Completed
needs: [publish]
runs-on: ubuntu-latest
if: success()
steps:
- name: Send Slack Notification
env:
WEBHOOK_URL: ${{ secrets.GH_ACTION_WEBHOOK_URL }}
GITHUB_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
BRANCH=${{ github.ref_name }}
MESSAGE="Publish job for branch *${BRANCH}* completed successfully. Package is now available. See details here: $GITHUB_RUN_URL"
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"$MESSAGE\"}" $WEBHOOK_URL