-
Notifications
You must be signed in to change notification settings - Fork 5.8k
162 lines (144 loc) · 6.11 KB
/
sync-S3-KB.yml
File metadata and controls
162 lines (144 loc) · 6.11 KB
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
name: syncS3andKB
on:
push:
branches: ["main"]
workflow_dispatch:
inputs:
sdk_name:
description: 'SDK Name'
required: true
default: 'python'
type: choice
options:
- javascriptv3
- dotnetv4
- javav2
- rustv1
- gov2
- swift
- python
- ruby
- php
- cpp
- kotlin
- steering_docs
- specs
- coding-standards
permissions:
id-token: write
jobs:
run_job_with_aws:
runs-on: ubuntu-latest
strategy:
matrix:
sdk_name: ${{ github.event_name == 'push' && fromJSON('["javascriptv3","dotnetv4","javav2","rustv1","gov2","swift","python","ruby","php","cpp","kotlin","steering_docs","specs","coding-standards"]') || fromJSON(format('["{0}"]', github.event.inputs.sdk_name)) }}
env:
sdk_name: ${{ matrix.sdk_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }} # once merged, update trust policy of the role to point to main branch
aws-region: us-west-2
- name: Set SDK and language mapping for S3
run: |
if [ "$sdk_name" == "javascriptv3" ]; then
echo "S3_LANGUAGE=javascript" >> $GITHUB_ENV
elif [ "$sdk_name" == "dotnetv4" ]; then
echo "S3_LANGUAGE=dotnet" >> $GITHUB_ENV
elif [ "$sdk_name" == "javav2" ]; then
echo "S3_LANGUAGE=java" >> $GITHUB_ENV
elif [ "$sdk_name" == "rustv1" ]; then
echo "S3_LANGUAGE=rust" >> $GITHUB_ENV
elif [ "$sdk_name" == "gov2" ]; then
echo "S3_LANGUAGE=go" >> $GITHUB_ENV
elif [ "$sdk_name" == "steering_docs" ]; then
echo "S3_LANGUAGE=steering-docs" >> $GITHUB_ENV
elif [ "$sdk_name" == "coding-standards" ]; then
echo "S3_LANGUAGE=coding-standards" >> $GITHUB_ENV
elif [ "$sdk_name" == "specs" ]; then
echo "S3_LANGUAGE=final-specs" >> $GITHUB_ENV
else
echo "S3_LANGUAGE=$sdk_name" >> $GITHUB_ENV
fi
- name: Filter SPECIFICATION.md files for specs
if: ${{ github.event.inputs.sdk_name == 'specs' }}
run: |
find ./scenarios -name "SPECIFICATION.md" | while read file; do
mkdir -p "./filtered_specs/$(dirname "$file")"
cp "$file" "./filtered_specs/$file"
done
- name: Clone and filter for coding standards
if: ${{ github.event.inputs.sdk_name == 'coding-standards' }}
run: |
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.wiki.git wiki-repo
mkdir -p ./filtered-wiki
find ./wiki-repo -type f -name "*[Gg]uidelines*.md" -o -name "*[Ss]tandards*.md" | while read file; do
cp "$file" ./filtered-wiki/
done
- name: Extract and copy premium examples in temp. dir.
if: ${{ contains(fromJSON('["javascriptv3","dotnetv4","javav2","rustv1","gov2","swift","python","ruby","php","cpp","kotlin"]'), github.event.inputs.sdk_name) }}
run: |
MARKDOWN_FILE="./$sdk_name/premium-ex.md"
if [ ! -f "$MARKDOWN_FILE" ]; then
echo "Premium examples file not found: $MARKDOWN_FILE"
exit 1
fi
extract_paths() {
local level="$1"
local section_found=false
while IFS= read -r line; do
if [[ "$line" =~ ^##[[:space:]]*${level}:[[:space:]]*$ ]]; then
section_found=true
continue
elif [[ "$line" =~ ^##[[:space:]] ]] && [ "$section_found" = true ]; then
break
elif [ "$section_found" = true ] && [[ "$line" =~ ^/ ]]; then
echo "$line"
fi
done < "$MARKDOWN_FILE"
}
for level in "basics" "feature-scenario" "complex-feature-scenario"; do
paths=$(extract_paths "$level")
if [ -n "$paths" ]; then
mkdir -p "./extracted_snippets/$level"
while IFS= read -r path; do
if [ -n "$path" ]; then
source_path="./$sdk_name$path"
if [ -e "$source_path" ]; then
cp -r "$source_path" "./extracted_snippets/$level/"
fi
fi
done <<< "$paths"
fi
done
- name: Upload/Sync to S3 (SDK languages)
if: ${{ contains(fromJSON('["javascriptv3","dotnetv4","javav2","rustv1","gov2","swift","python","ruby","php","cpp","kotlin"]'), github.event.inputs.sdk_name) }}
run: |
for level in "basics" "feature-scenario" "complex-feature-scenario"; do
if [ -d "./extracted_snippets/$level" ]; then
aws s3 sync "./extracted_snippets/$level/" "s3://$S3_LANGUAGE-premium-bucket/$level/" --delete
echo "Uploaded $level examples to S3"
fi
done
- name: Upload/Sync to S3 (Other directories)
if: ${{ contains(fromJSON('["steering_docs","coding-standards","specs"]'), github.event.inputs.sdk_name) }}
run: |
if [ "$sdk_name" == "steering_docs" ]; then
aws s3 sync "./$sdk_name/" "s3://$S3_LANGUAGE-bucket/" --delete
elif [ "$sdk_name" == "coding-standards" ]; then
aws s3 sync "./filtered-wiki/" "s3://$S3_LANGUAGE-bucket/" --delete
else
aws s3 sync "./filtered_specs/" "s3://$S3_LANGUAGE-bucket/" --delete
fi
- name: Sync Knowledge Base Data Source
run: |
aws lambda invoke \
--function-name KB_Updater \
--payload "{\"language\":\"$S3_LANGUAGE\",\"region\":\"us-west-2\"}" \
--cli-binary-format raw-in-base64-out \
response.json
echo "Knowledge Base sync initiated"
cat response.json