-
Notifications
You must be signed in to change notification settings - Fork 5
192 lines (171 loc) · 6.67 KB
/
flow-ci.yml
File metadata and controls
192 lines (171 loc) · 6.67 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
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
192
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Flow CI
on:
pull_request:
types: [opened, reopened, synchronize]
paths:
- 'flows/**'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
flow-diff:
runs-on: ubuntu-latest
name: Flow Diff
steps:
- name: Checkout PR Code
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
path: submitted-changes
- name: Get Changed Flow Files
id: files
run: |
cd submitted-changes
files=$(git diff --name-only $(git merge-base HEAD origin/${{ github.event.pull_request.base.ref }}) HEAD | grep 'flows/.*\.json$' || true)
if [ -z "$files" ]; then
echo "flowA=" >> $GITHUB_OUTPUT
echo "flowB=" >> $GITHUB_OUTPUT
echo "has_flows=false" >> $GITHUB_OUTPUT
else
bare=$(echo "$files" | tr '\n' ',' | sed 's/,$//')
flowA=$(echo "$bare" | sed 's|[^,]\+|original-code/&|g')
flowB=$(echo "$bare" | sed 's|[^,]\+|submitted-changes/&|g')
echo "flowA=$flowA" >> $GITHUB_OUTPUT
echo "flowB=$flowB" >> $GITHUB_OUTPUT
echo "has_flows=true" >> $GITHUB_OUTPUT
fi
- name: Checkout Original Code
if: steps.files.outputs.has_flows == 'true'
uses: actions/checkout@v6
with:
fetch-depth: 2
path: original-code
- name: Reset to Base
if: steps.files.outputs.has_flows == 'true'
run: cd original-code && git checkout HEAD^
- name: Snowflake Flow Diff
if: steps.files.outputs.has_flows == 'true'
uses: Snowflake-Labs/snowflake-flow-diff@v0
id: flowdiff
with:
flowA: ${{ steps.files.outputs.flowA }}
flowB: ${{ steps.files.outputs.flowB }}
checkstyle: true
checkstyle-rules: submitted-changes/.github/checkstyle/flow-checkstyle-rules.yaml
flow-tests:
runs-on: ubuntu-latest
name: Flow Validation Tests
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install Dependencies
run: pip install -r flows/requirements.txt
- name: Detect Changed Flow Buckets
id: buckets
run: |
CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD)
BUCKETS=()
for file in $CHANGED_FILES; do
if [[ "$file" == flows/*/tests/*.py || "$file" == flows/*/*.json ]]; then
bucket=$(echo "$file" | cut -d'/' -f2)
BUCKETS+=("$bucket")
fi
done
UNIQUE_BUCKETS=($(printf '%s\n' "${BUCKETS[@]}" | sort -u))
if [ ${#UNIQUE_BUCKETS[@]} -eq 0 ]; then
echo "has_tests=false" >> $GITHUB_OUTPUT
else
PATHS=""
for bucket in "${UNIQUE_BUCKETS[@]}"; do
if [ -d "flows/$bucket/tests" ]; then
PATHS="$PATHS flows/$bucket/tests"
fi
done
echo "test_paths=$PATHS" >> $GITHUB_OUTPUT
echo "has_tests=true" >> $GITHUB_OUTPUT
fi
- name: Run Flow Validation Tests
if: steps.buckets.outputs.has_tests == 'true'
run: pytest ${{ steps.buckets.outputs.test_paths }} -v
deploy-hint:
runs-on: ubuntu-latest
name: Post Deploy Instructions
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Check for test YAML configs
id: check
run: |
CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD)
HAS_CONFIG=false
CONFIGS=""
for file in $CHANGED_FILES; do
if [[ "$file" == flows/*/*.json ]]; then
bucket=$(echo "$file" | cut -d'/' -f2)
flow_base=$(basename "$file" .json)
test_name=$(echo "$flow_base" | tr '-' '_')
yaml_path="flows/$bucket/tests/test_${test_name}.yaml"
if [ -f "$yaml_path" ]; then
HAS_CONFIG=true
CONFIGS="$CONFIGS $yaml_path"
fi
fi
done
echo "has_config=$HAS_CONFIG" >> "$GITHUB_OUTPUT"
echo "configs=$CONFIGS" >> "$GITHUB_OUTPUT"
- name: Comment deploy instructions
if: steps.check.outputs.has_config == 'true'
uses: actions/github-script@v9
with:
script: |
const marker = '<!-- flow-deploy-hint -->';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c =>
c.user.type === 'Bot' && c.body.includes(marker)
);
if (existing) return;
let body = marker + '\n';
body += '### :rocket: Flow Deploy Available\n\n';
body += 'This PR modifies flow definitions that have a CI test configuration. ';
body += 'A maintainer (`admin` or `maintain` permission) can deploy and test the flow ';
body += 'on an ephemeral Snowflake runtime by commenting:\n\n';
body += '> **`deploy this flow`** or **`deploy the flow`**\n\n';
body += 'This will:\n';
body += '1. Create a dedicated ephemeral runtime\n';
body += '2. Deploy the changed flow(s)\n';
body += '3. Run validation tests\n';
body += '4. Tear down the runtime and report results\n\n';
body += 'To keep the runtime alive for debugging, add `do not clean` to the comment.';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});