forked from PalisadoesFoundation/talawa-api
-
Notifications
You must be signed in to change notification settings - Fork 0
275 lines (242 loc) · 9.59 KB
/
push.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
##############################################################################
##############################################################################
#
# NOTE!
#
# Please read the README.md file in this directory that defines what should
# be placed in this file
#
##############################################################################
##############################################################################
name: Push Workflow
on:
push:
branches:
- '**'
env:
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}
jobs:
##############################################################################
# This section is added so that the most recent and valid level of
# code coverage (post PR merge) is reported
##############################################################################
Push-Workflow:
name: Testing Application
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
services:
redis:
image: redis:6.0
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 10
ports:
- 6379:6379
mongo:
image: mongo:4.4
options: >-
--health-cmd mongo
--health-interval 10s
--health-timeout 5s
--health-retries 10
ports:
- 27017:27017
env:
MONGO_DB_URL: mongodb://localhost:27017/talawa-test-db
REDIS_HOST: localhost
REDIS_PORT: 6379
# ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
# REFRESH_TOKEN_SECRET: ${{ secrets.REFRESH_TOKEN_SECRET }}
# We checkout the content of the Talawa-API repository in a directory called `api`
# This is done as we will use the Talawa-Docs repository later too
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate Access Token Secret
run: echo "ACCESS_TOKEN_SECRET=$(openssl rand -hex 32)" >> $GITHUB_ENV
- name: Generate Refresh Token Secret
run: echo "REFRESH_TOKEN_SECRET=$(openssl rand -hex 32)" >> $GITHUB_ENV
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- name: Install dependencies
run: npm ci
- name: Sleep for 10s
uses: juliangruber/sleep-action@v2
with:
time: 10s
# Testing the application
- name: Run the tests
run: npm run test
# Upload Coverage
- name: Present and upload coverage to Codecov as ${{env.CODECOV_UNIQUE_NAME}}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
fail_ci_if_error: false
name: '${{env.CODECOV_UNIQUE_NAME}}'
Generate-Documentation:
name: Generate Documentation
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
needs: Push-Workflow
steps:
- name: Checkout repository
uses: actions/checkout@v4
# with:
# persist-credentials: false
- name: Generate Documentation of HTML pages
run: |
npm install --global typedoc
npm install typedoc-plugin-markdown
npm i --save-dev @types/node
npx typedoc --entryPoints src --out talawa-api-docs --plugin typedoc-plugin-markdown --theme markdown --entryPointStrategy expand
- name: Make Markdown Files MDX Compatible
run: python3 .github/workflows/md_mdx_format_adjuster.py --directory talawa-api-docs
- name: Checking doc updated
id: DocUpdated
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "updateDoc=true" >> $GITHUB_OUTPUT
echo -e "Documentation has been updated!!"
else
Green='0;32'
NoColor='\033[0m'
echo -e "${Green}No documentation updated${NoColor}"
fi
- name: Set env variables
if: steps.DocUpdated.outputs.updateDoc
run: |
echo "commit_id=$(echo $(git rev-parse HEAD))" >> $GITHUB_ENV
echo "email=$(echo $(git log --pretty=format:"%ae" $commit_id))" >> $GITHUB_ENV
- name: Update Doc
if: steps.DocUpdated.outputs.updateDoc
run: |
Green='0;32'
NoColor='\033[0m'
git config --global user.name "${{github.actor}}"
git config --global user.email "${{env.email}}"
git add .
git commit -m "Update documentation"
git push -f https://[email protected]/PalisadoesFoundation/talawa-api.git HEAD:automated-docs
echo -e "🚀${Green} Hurrah! doc updated${NoColor}"
env:
ACCESS_TOKEN: ${{secrets.GH_TOKEN}}
- name: Create Documentation Artifact
uses: actions/upload-artifact@v2
with:
name: documentation-api
path: talawa-api-docs
Empty-Commit:
name: Create Empty Commit
runs-on: ubuntu-latest
needs: Generate-Documentation
if: github.ref == 'refs/heads/develop'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
token: ${{ secrets.TALAWA_DOCS_SYNC }}
- name: Empty Commit
run: |
git config --global user.name "${{github.actor}}"
git config --global user.email "${{env.email}}"
git config --global url.https://${{ secrets.TALAWA_DOCS_SYNC }}@github.com/.insteadOf https://github.com/
git commit --allow-empty -m "Trigger Documentation Workflow"
git push origin develop:automated-docs --force
# Copy-docs-to-talawa-docs:
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/automated-docs'
# # needs: Generate-Documentation
# steps:
# - uses: actions/checkout@v3
# - uses: dmnemec/[email protected]
# env:
# API_TOKEN_GITHUB: ${{secrets.TALAWA_DOCS_SYNC}}
# with:
# source_file: 'talawa-api-docs/'
# destination_repo: 'PalisadoesFoundation/talawa-docs'
# destination_branch: 'develop'
# destination_folder: 'docs/'
# user_email: '${{env.email}}'
# user_name: '${{github.actor}}'
# commit_message: 'Talawa API docs updated'
# You can find the deployment instructions in the scripts/cloud-api-demo/README.md file
Deploy-Workflow:
name: Deploying Application to Cloud VPS
needs: Push-Workflow
runs-on: ubuntu-latest
steps:
- name: Generate Access Token Secret
run: |
secret=$(openssl rand -hex 32)
echo "INPUT_ACCESS_TOKEN_SECRET=$secret" >> $GITHUB_ENV
echo "::add-mask::$secret"
- name: Generate Refresh Token Secret
run: |
secret=$(openssl rand -hex 32)
echo "INPUT_REFRESH_TOKEN_SECRET=$secret" >> $GITHUB_ENV
echo "::add-mask::$secret"
- name: Execute remote ssh commands
uses: appleboy/[email protected]
env:
INPUT_RECAPTCHA_SECRET_KEY: ${{ secrets.API_DEMO_RECAPTCHA_SECRET_KEY }}
INPUT_MAIL_USERNAME: ${{ secrets.API_DEMO_MAIL_USERNAME }}
INPUT_MAIL_PASSWORD: ${{ secrets.API_DEMO_MAIL_PASSWORD }}
INPUT_LAST_RESORT_SUPERADMIN_EMAIL: ${{ secrets.API_DEMO_LAST_RESORT_SUPERADMIN_EMAIL }}
with:
host: ${{secrets.API_DEMO_HOST}}
username: ${{ secrets.API_DEMO_USERNAME }}
key: ${{ secrets.API_DEMO_SSH_KEY }}
port: ${{ secrets.API_DEMO_SSH_PORT}}
allenvs: true
command_timeout: 30m
script: |
python3 /usr/local/bin/scripts/create_env.py --access_token_secret $INPUT_ACCESS_TOKEN_SECRET --refresh_token_secret $INPUT_REFRESH_TOKEN_SECRET --recaptcha_secret_key $INPUT_RECAPTCHA_SECRET_KEY --mail_username $INPUT_MAIL_USERNAME --mail_password $INPUT_MAIL_PASSWORD --last_resort_superadmin_email $INPUT_LAST_RESORT_SUPERADMIN_EMAIL
python3 /usr/local/bin/scripts/deploy.py --path ~/develop --branch develop
Check-Schema:
name: Check Schema
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore node_modules from cache
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: |
~/.npm
node_modules
key: ${{ runner.os }}-node-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ env.cache-name }}-
${{ runner.os }}-node-
${{ runner.os }}-
- name: Install dependencies
run: npm ci
- name: Generate schema.graphql
run: npm run gen:schema
# A separate step for extracting branch name from $GITHUB_HEAD_REF/$GITHUB_REF
# $GITHUB_HEAD_REF on pull_request and $GITHUB_REF on push
# If GITHUB_HEAD_REF is not set, extract the branch name from GITHUB_REF using parameter expansion to remove "refs/heads/" prefix
# If GITHUB_HEAD_REF is set, directly assign its value to the branch variable
- name: Extract branch name
shell: bash
run: |
if [ -z "$GITHUB_HEAD_REF" ]; then
branch=${GITHUB_REF#refs/heads/}
else
branch=$GITHUB_HEAD_REF
fi
echo "branch=$branch" >> $GITHUB_OUTPUT
id: extract_branch
- uses: kamilkisiela/graphql-inspector@master
with:
schema: ${{ steps.extract_branch.outputs.branch }}:schema.graphql