-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (134 loc) · 5.49 KB
/
node.js.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
name: Node.js CI
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20] # Specify Node.js 20
# Only run workflow if TypeScript files were modified
outputs:
js_library_rebuilt: ${{ steps.build_check.outputs.ts_files_modified }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2 # Fetch the last two commits to ensure `git diff` works
- name: Check if TypeScript files were modified
id: build_check
run: |
# Get modified files that are in the 'src/' folder and end with '.ts'
MODIFIED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^src/.*\.ts$' || true)
# Print the modified files for debugging
echo "Modified files:"
echo "$MODIFIED_FILES"
# Check if MODIFIED_FILES has any content
if [[ -n "$MODIFIED_FILES" ]]; then
echo "Typescript files were modified."
echo "::set-output name=ts_files_modified::true"
else
echo "No TypeScript files were modified."
echo "::set-output name=ts_files_modified::false"
fi
- name: Setup Node.js
if: steps.build_check.outputs.ts_files_modified == 'true'
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
if: steps.build_check.outputs.ts_files_modified == 'true'
run: npm install
- name: Compile TypeScript
if: steps.build_check.outputs.ts_files_modified == 'true'
run: npx tsc
- name: Run tests
if: steps.build_check.outputs.ts_files_modified == 'true'
run: npm test
- name: Upload artifacts
if: steps.build_check.outputs.ts_files_modified == 'true'
uses: actions/upload-artifact@v3
with:
name: dist
path: ./dist
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2 # Fetch the last two commits to ensure `git diff` works
- name: Get modified proc and func sql files
id: get_changed_files
run: |
# Get modified files that are in the 'scripts/' folder and end with '-func.sql' or '-proc.sql'
MODIFIED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^scripts/.*\(-func\.sql\|-proc\.sql\)$' || true)
# Output the filtered list of modified files
echo "$MODIFIED_FILES" > modified_files.txt
# Check if the modified_files.txt has any content
if [[ -s modified_files.txt ]]; then
echo "::set-output name=modified_files_exist::true"
else
echo "::set-output name=modified_files_exist::false"
fi
# Print the modified files for debugging purposes
echo "Modified files:"
cat modified_files.txt
- name: Download artifacts
if: needs.build.outputs.js_library_rebuilt == 'true'
uses: actions/download-artifact@v3
with:
name: dist
path: ./dist # Make sure the files are downloaded into the correct path
- name: Authenticate to Google Cloud for clingen-swc
if: (needs.build.outputs.js_library_rebuilt == 'true') || (steps.get_changed_files.outputs.modified_files_exist == 'true')
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Setup Google Cloud SDK
if: (needs.build.outputs.js_library_rebuilt == 'true') || (steps.get_changed_files.outputs.modified_files_exist == 'true')
uses: google-github-actions/setup-gcloud@v1
with:
version: 'latest'
- name: Copy javascript libraries to Google Cloud Storage
if: needs.build.outputs.js_library_rebuilt == 'true'
run: |
if [ -z "$(ls -A ./dist)" ]; then
echo "No files found in ./dist, skipping upload."
exit 0
else
echo "Files found, proceeding with upload."
gsutil cp -r ./dist/* gs://clinvar-ingest/bq-tools
fi
- name: Execute clingen-stage modified sql Scripts
if: steps.get_changed_files.outputs.modified_files_exist == 'true'
run: |
echo "Executing sql scripts for clingen-stage in alphabetical order..."
for file in $(find ./scripts -type f -name '*.sql' | sort); do
relative_file=$(realpath --relative-to=. "$file") # Get relative path of the file
if grep -q "$relative_file" modified_files.txt; then
echo "Executing $file..."
bq query --use_legacy_sql=false --project_id=$PROJECT_ID < "$file"
else
echo "Skipping $file as it was not modified."
fi
done
env:
PROJECT_ID: 'clingen-stage'
- name: Execute clingen-dev modified sql Scripts
if: steps.get_changed_files.outputs.modified_files_exist == 'true'
run: |
echo "Executing sql scripts for clingen-dev in alphabetical order..."
for file in $(find ./scripts -type f -name '*.sql' | sort); do
relative_file=$(realpath --relative-to=. "$file") # Get relative path of the file
if grep -q "$relative_file" modified_files.txt; then
echo "Executing $file..."
bq query --use_legacy_sql=false --project_id=$PROJECT_ID < "$file"
else
echo "Skipping $file as it was not modified."
fi
done
env:
PROJECT_ID: 'clingen-dev'