-
Notifications
You must be signed in to change notification settings - Fork 14
191 lines (170 loc) · 6.63 KB
/
tools-manifest.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
# Workflow to upload tool manifests
---
name: tools manifests
on:
workflow_dispatch:
push:
branches:
- "main"
- "staging"
# Pattern matched against refs/tags
tags:
- '**'
paths:
- 'models/**'
- '.github/workflows/tools-manifest.yml'
pull_request:
branches:
- "main"
- "staging"
paths:
- 'models/**'
- '.github/workflows/tools-manifest.yml'
env:
TOOLS_WALLET_ADDRESS: "0xA5B68dbA49cE48d0c1e0f29EA45885b5f83A0BD4"
# Only run one at a time
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
################ TOOLS MANIFEST ###########################
changes-tools:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
tools: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
# Only run when tool's directory or workflow files have changed
###############################################################
################## Add new tools here #########################
###############################################################
# Following syntax of topleveldir_configfilename_withoutjson
filters: |
# Toplevel dir after models_filename_without_json_extension
# this is a workaround to allow multiple config files under same directory
# Example if you have a config file under models/mymodel/mymodel_config_file.json
# you would add,
# mymodel_mymodel_config_file:
# - 'models/mymodel/mymodel_config_file.json'
tools:
needs: changes-tools
if: ${{ needs.changes-tools.outputs.tools != '' && toJson(fromJson(needs.changes-tools.outputs.tools)) != '[]' }}
strategy:
fail-fast: false
matrix:
tools: "${{ fromJSON(needs.changes-tools.outputs.tools) }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setting tool related envs
run: |
echo "TOOL_DIR=$(echo ${{ matrix.tools }} | cut -d '_' -f1)" >> $GITHUB_ENV
echo "TOOL_FILE=$(echo ${{ matrix.tools }} | cut -d '_' -f2-)" >> $GITHUB_ENV
- name: Setting tool file path
run: |
echo "TOOL_FILE_PATH=models/${{ env.TOOL_DIR }}/${{ env.TOOL_FILE }}.json" >> $GITHUB_ENV
- name: Setting some more tool related envs
run: |
# Extract name from json
echo "TOOL_NAME=$(cat ${{ env.TOOL_FILE_PATH }} | jq -r '.name')" >> $GITHUB_ENV
echo "NORMALIZED_GIT_REF=$(echo $GITHUB_REF | sed 's/refs\///g' | sed 's/heads\///g' | sed 's/\/merge//g' | sed 's/\//-/g')" >> $GITHUB_ENV
echo "GIT_SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Versionined tool name
env:
TOOL_NAME_VERSIONED: "${{ env.TOOL_NAME }}-${{ env.NORMALIZED_GIT_REF }}-${{ env.GIT_SHORT_SHA }}"
run: |
echo "TOOL_NAME_VERSIONED=${{ env.TOOL_NAME_VERSIONED }}" >> $GITHUB_ENV
- name: Params
run: |
echo "## Params" >> $GITHUB_STEP_SUMMARY
echo "| Parameter Name NAME | Parameter VALUE |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
echo "| TOOL_DIR | ${{ env.TOOL_DIR }} |" >> $GITHUB_STEP_SUMMARY
echo "| TOOL_FILE | ${{ env.TOOL_FILE }} |" >> $GITHUB_STEP_SUMMARY
echo "| TOOL_FILE_PATH | ${{ env.TOOL_FILE_PATH }} |" >> $GITHUB_STEP_SUMMARY
echo "| TOOL_NAME | ${{ env.TOOL_NAME }} |" >> $GITHUB_STEP_SUMMARY
echo "| GITHUB_REF | $GITHUB_REF |" >> $GITHUB_STEP_SUMMARY
echo "| NORMALIZED_GIT_REF | ${{ env.NORMALIZED_GIT_REF }} |" >> $GITHUB_STEP_SUMMARY
echo "| GIT_SHORT_SHA | $GIT_SHORT_SHA |" >> $GITHUB_STEP_SUMMARY
echo "| TOOL_NAME_VERSIONED | ${{ env.TOOL_NAME_VERSIONED }} |" >> $GITHUB_STEP_SUMMARY
- name: Dump updated manifest file to be POSTed
run: |
jq --arg toolname "${{ env.TOOL_NAME_VERSIONED }}" '{"toolJson": ., "walletAddress": "${{ env.TOOLS_WALLET_ADDRESS }}"} | .toolJson.name |= $toolname' ${{ env.TOOL_FILE_PATH }} > /tmp/manifest.json
- name: Dump Manifest json
run: |
echo '### Tool config' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat /tmp/manifest.json >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: upload manifest
uses: actions/upload-artifact@v3
with:
name: tool-manifest-${{ matrix.tools }}
path: |
/tmp/manifest.json
tools-upload:
needs:
- tools
- changes-tools
# If tool isn't empty
if: |
${{ needs.changes-tools.outputs.tools != '' &&
toJson(fromJson(needs.changes-tools.outputs.tools)) != '[]' }} &&
strategy:
fail-fast: false
matrix:
backends:
- env: stg
url: 'backend.stg.labdao.xyz:8080/models'
api_key: ${{ secrets.STG_API_KEY }}
- env: prod
url: 'backend.prod.labdao.xyz:8080/models'
api_key: ${{ secrets.PROD_API_KEY }}
- env: lbbprod
url: 'backend.lab.bio:8080/models'
api_key: ${{ secrets.LBBPROD_API_KEY }}
tools: "${{ fromJSON(needs.changes-tools.outputs.tools) }}"
runs-on:
- self-hosted
- "${{ matrix.backends.env }}"
steps:
- name: Condition
id: upload-condition
run: echo "Continue"
if: >-
${{
(
matrix.backends.env == 'stg' ||
(
matrix.backends.env == 'prod' &&
github.ref_name == 'main'
) ||
(
matrix.backends.env == 'lbbprod' &&
github.ref_name == 'main'
)
)
}}
- name: download manifest
if: steps.upload-condition.outcome == 'success'
uses: actions/download-artifact@v3
with:
name: tool-manifest-${{ matrix.tools }}
- name: POST Manifest to environment
if: steps.upload-condition.outcome == 'success'
run: |
set -xe
curl -H "Authorization: Bearer ${{ matrix.backends.api_key }}" --silent --max-time 60 --fail "${{ matrix.backends.url }}" -X POST -d @manifest.json | tee output.log
CID=$(cat output.log | jq -r '.cid')
echo "TOOL CID: ${CID}" >> $GITHUB_STEP_SUMMARY
- name: upload output.log
uses: actions/upload-artifact@v3
with:
name: tool-manifest-output-${{ matrix.tools }}
path: |
output.log