-
Notifications
You must be signed in to change notification settings - Fork 19
163 lines (155 loc) · 5.33 KB
/
generate_missing_mappings.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
name: Generate and commit taxonomy mapping changes to requested PR
on:
issue_comment:
types: [created]
concurrency:
group: "generate_mappings"
cancel-in-progress: false
jobs:
generate_missing_mappings:
if: |
contains('["OWNER", "CONTRIBUTOR", "COLLABORATOR", "MEMBER"]', github.event.comment.author_association) &&
github.event.issue.pull_request &&
github.event.comment.body == '/generate_mappings'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
# Checkout only the changed data files
- uses: actions/checkout@v4
- name: Checkout PR
run: gh pr checkout ${{ github.event.issue.number }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Keep only data/*.yml files
run: |
git fetch origin main:main
git reset --hard origin/main
git checkout HEAD@{1} -- 'data/**/*.yml'
# Setup dependencies
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Set up Podman
run: |
sudo apt-get update
sudo apt-get -y install podman
- name: Launch Qdrant server
run: |
port=6333
podman run -d -p ${port}:${port} qdrant/qdrant
echo "Waiting for Qdrant server to be ready..."
sleep 25
- uses: cue-lang/[email protected]
with:
version: 'v0.7.0'
- name: Install b3sum
run: |
curl -L https://github.com/BLAKE3-team/BLAKE3/releases/download/1.5.3/b3sum_linux_x64_bin -o b3sum
chmod +x b3sum
sudo mv b3sum /usr/local/bin/
- name: Seed database
run: make --file=Makefile seed
- name: Generate missing mappings
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_BASE: ${{ secrets.OPENAI_API_BASE }}
run: |
make --file=Makefile generate_mappings
- name: Clean cache and re-generate mapping distribution files
run: |
make --file=Makefile clean
VERBOSE=1 make --file=Makefile build
- name: Create distribution manifest
run: |
target="dist"
manifest="manifest.b3"
manifest_sig="${manifest}.sig"
find "$target" -type f -print0 | sort -z | xargs -0 b3sum > "$manifest"
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed "$manifest" > "$manifest_sig"
- uses: actions/upload-artifact@v4
with:
name: generated-mappings
path: |
dist/*/integrations
data/integrations
tmp/summary_message.txt
manifest.b3
manifest.b3.sig
commit_changes:
runs-on: ubuntu-latest
needs: generate_missing_mappings
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Checkout PR
run: gh pr checkout ${{ github.event.issue.number }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Verify and apply distribution files
- uses: actions/download-artifact@v4
with:
name: generated-mappings
path: .
- name: Install b3sum
run: |
curl -L https://github.com/BLAKE3-team/BLAKE3/releases/download/1.5.3/b3sum_linux_x64_bin -o b3sum
chmod +x b3sum
sudo mv b3sum /usr/local/bin/
- name: Verify file integrity
run: |
manifest="manifest.b3"
manifest_sig="${manifest}.sig"
verify_sig="verify.b3.sig"
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed "$manifest" > "$verify_sig"
echo "Vetting $manifest_sig with generated $verify_sig"
if ! (cmp -s "$manifest_sig" "$verify_sig"); then
echo "Error: Integrity failure. Invalid key used to generate ${verify_sig}."
exit 1
fi
rm -f "$manifest_sig" "$verify_sig"
echo "Vetting $manifest"
if ! (b3sum --check "$manifest"); then
echo "Error: Integrity failure. Files are inconsistent with ${manifest}."
exit 1
fi
rm -f "$manifest"
- name: Commit mapping changes
id: commit_changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add dist/*/integrations
git add data/integrations
commit_output=$(git commit -m "🤖 Update missing mappings" || echo "No changes to commit")
echo "$commit_output"
echo "commit_message<<EOF" >> $GITHUB_ENV
echo "$commit_output" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
git push || echo "No changes to push"
- name: Read summary message
id: read_content
run: |
if [ -f tmp/summary_message.txt ]; then
summary_message=$(cat tmp/summary_message.txt)
else
summary_message="Found 0 unmapped Shopify category."
fi
echo "summary_message<<EOF" >> $GITHUB_ENV
echo "$summary_message" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Add mapping grading comment to PR
if: env.commit_message != 'No changes to commit'
uses: actions/github-script@v6
with:
script: |
const body = process.env.summary_message;
github.rest.issues.createComment({
issue_number: ${{ github.event.issue.number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})