-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
113 lines (106 loc) · 4.35 KB
/
action.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
name: 'Vectara Documentation Indexer'
branding:
icon: 'search'
color: 'purple'
description: 'Send markdown files to Vectara for indexing'
inputs:
vectaraAccountNumber:
description: 'Vectara Account Number'
required: true
vectaraCorpusID:
description: 'Vectara Corpus ID'
required: true
vectaraClientID:
description: 'Vectara OAuth 2.0 Client ID'
required: true
vectaraClientSecret:
description: 'Vectara OAuth 2.0 Client Secret'
required: true
vectaraIndexingEndpoint:
description: 'Vectara Indexing Endpoint'
default: 'api.vectara.io'
required: false
vectaraAuthEndpoint:
description: 'Vectara Authentication Endpoint'
default: ''
required: false
incrementalIndexing:
description: 'Whether to just do an incremental index. Set to false to index all content the first time'
default: 'true'
required: false
filesPattern:
description: 'Vectara Authentication Endpoint'
default: '**'
required: false
runs:
using: "composite"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get JWT token
id: jwt-token
shell: bash
run: |
bash $GITHUB_ACTION_PATH/get_jwt_token.sh
env:
INPUT_VECTARA_AUTH_ENDPOINT: ${{ inputs.vectaraAuthEndpoint }}
INPUT_VECTARA_ACCOUNT_NUMBER: ${{ inputs.vectaraAccountNumber }}
INPUT_VECTARA_CLIENT_ID: ${{ inputs.vectaraClientID }}
INPUT_VECTARA_CLIENT_SECRET: ${{ inputs.vectaraClientSecret }}
- name: Get changed files
id: changed-files
uses: eskibars/changed-files@v0.1.0
if: inputs.incrementalIndexing == 'true'
with:
files: |
${{ inputs.filesPattern }}
- name: Get all files
id: all-files
uses: eskibars/changed-files@v0.1.0
if: inputs.incrementalIndexing == 'false'
with:
base_sha: 4b825dc642cb6eb9a060e54bf8d69288fbee4904
files: |
${{ inputs.filesPattern }}
- name: Delete any documentation that has changed
shell: bash
id: delete-docs
run: |
for file in ${{ steps.changed-files.outputs.deleted_files }} ${{ steps.all-files.outputs.deleted_files }}; do
PAYLOAD={"customer-id":"${{ inputs.vectaraAccountNumber }}","corpus-id":"${{ inputs.vectaraCorpusID }}","document-id":"$file"}
echo "::debug::Delete-Payload: $PAYLOAD"
curl -XPOST "https://${{ inputs.vectaraIndexingEndpoint }}/v1/delete-doc" -d $PAYLOAD \
-H "Content-type: application/json" \
-H "Authorization: Bearer $JWT_TOKEN" \
-H "customer-id: ${{ inputs.vectaraAccountNumber }}"
done
- name: Index any documentation that has been created
shell: bash
id: index-docs
run: |
for file in ${{ steps.changed-files.outputs.added_files }} ${{ steps.all-files.outputs.added_files }}; do
FULL_FILE_PATH=$GITHUB_WORKSPACE/$file
echo "::debug::Full file path: $FULL_FILE_PATH"
echo "::debug::File stats: $(ls -al $FULL_FILE_PATH)"
curl -XPOST "https://${{ inputs.vectaraIndexingEndpoint }}/v1/upload?o=${{ inputs.vectaraCorpusID }}&c=${{ inputs.vectaraAccountNumber }}" \
-H "Authorization: Bearer $JWT_TOKEN" -F file=@$FULL_FILE_PATH
done
- name: Index any documentation that has been modified
shell: bash
id: update-docs
run: |
for file in ${{ steps.changed-files.outputs.modified_files }} ${{ steps.all-files.outputs.modified_files }}; do
#delete then add
PAYLOAD={"customer-id":"${{ inputs.vectaraAccountNumber }}","corpus-id":"${{ inputs.vectaraCorpusID }}","document-id":"$file"}
echo "::debug::Update-Payload: $PAYLOAD"
curl -XPOST "https://${{ inputs.vectaraIndexingEndpoint }}/v1/delete-doc" -d $PAYLOAD \
-H "Content-type: application/json" \
-H "Authorization: Bearer $JWT_TOKEN" \
-H "customer-id: ${{ inputs.vectaraAccountNumber }}"
FULL_FILE_PATH=$GITHUB_WORKSPACE/$file
echo "::debug::Full file path: $FULL_FILE_PATH"
echo "::debug::File stats: $(ls -al $FULL_FILE_PATH)"
curl -XPOST "https://${{ inputs.vectaraIndexingEndpoint }}/v1/upload?o=${{ inputs.vectaraCorpusID }}&c=${{ inputs.vectaraAccountNumber }}" \
-H "Authorization: Bearer $JWT_TOKEN" -F file=@$FULL_FILE_PATH
done