Skip to content

Commit 86f3d9d

Browse files
Add pipeline for CLI + NA integration tests
1 parent 9693c6f commit 86f3d9d

File tree

12 files changed

+148
-26
lines changed

12 files changed

+148
-26
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: 'Modified Apps'
2+
description: 'Gets the modified apps root folder'
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- name: Get changed files
7+
id: changed-files-step
8+
run: $GITHUB_ACTION_PATH/modified_files.sh
9+
shell: bash
10+
env:
11+
GITHUB_ACTION_PATH: ${{ github.action_path }}
12+
GITHUB_EVENT_NAME: ${{ github.event_name }}
13+
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
14+
GITHUB_EVENT_AFTER: ${{ github.event.after }}
15+
- name: Get changed apps
16+
uses: actions/github-script@v7
17+
id: changed-apps-step
18+
env:
19+
CHANGED_FILES: ${{ steps.changed-files-step.outputs.changed_files }}
20+
with:
21+
script: |
22+
const { CHANGED_FILES } = process.env;
23+
const paths = new Set(CHANGED_FILES.split(" ")
24+
.map(x => x.substring(0, x.indexOf("/") + 1))
25+
.filter(x => x.length > 0 && !x.startsWith('.')));
26+
core.setOutput('changedApps', [...paths].join(','));
27+
outputs:
28+
modified_apps:
29+
description: 'The modified apps folders.'
30+
value: ${{ steps.changed-apps-step.outputs.changedApps }}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if [ $GITHUB_EVENT_NAME == 'pull_request' ]; then
2+
echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
3+
else
4+
echo "changed_files=$(git diff --name-only $GITHUB_EVENT_BEFORE $GITHUB_EVENT_AFTER | xargs)" >> $GITHUB_OUTPUT
5+
fi

.github/workflows/ci-integration.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: native-app-examples-integration
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- labeled
9+
- unlabeled
10+
- synchronize
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
env:
19+
SNOWFLAKE_CONNECTIONS_DEFAULT_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
20+
SNOWFLAKE_CONNECTIONS_DEFAULT_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
21+
SNOWFLAKE_CONNECTIONS_DEFAULT_USER: ${{ secrets.SNOWFLAKE_USER }}
22+
SNOWFLAKE_CONNECTIONS_DEFAULT_ROLE: ${{ secrets.SNOWFLAKE_ROLE }}
23+
SNOWFLAKE_CONNECTIONS_DEFAULT_WAREHOSE: ${{ secrets.SNOWFLAKE_WAREHOUSE }}
24+
defaults:
25+
run:
26+
shell: bash -l {0}
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
31+
- name: Set PIPX_BIN_DIR # This step will be removed after fixing a bug in snowflake-cli-action@v1
32+
run: echo "PIPX_BIN_DIR=$HOME/.local/bin" >> $GITHUB_ENV
33+
- name: Get modified apps
34+
id: modified-apps-step
35+
uses: ./.github/actions/modified_apps
36+
- name: Set up Snowflake CLI
37+
uses: Snowflake-Labs/[email protected]
38+
with:
39+
cli-version: "latest"
40+
default-config-file-path: "config.toml"
41+
- name: Verify Snowflake Connection
42+
run: |
43+
snow --version
44+
snow connection test
45+
- name: Run Integration
46+
run: |
47+
set -e
48+
modified_apps=${{ steps.modified-apps-step.outputs.modified_apps }}
49+
IFS=',' read -ra modified_apps_array <<< "$modified_apps"
50+
for app in "${modified_apps_array[@]}"; do
51+
cd $app
52+
if [ -f ci.sh ]; then
53+
sh ci.sh
54+
else
55+
snow app run
56+
snow app teardown
57+
fi
58+
cd ..
59+
done

.github/workflows/ci.yml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,20 @@ jobs:
3030
uses: actions/setup-python@v3
3131
with:
3232
python-version: "3.10"
33-
- name: Get changed files
34-
id: changed-files
35-
run: |
36-
if ${{ github.event_name == 'pull_request' }}; then
37-
echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
38-
else
39-
echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
40-
fi
33+
- name: Get modified apps
34+
id: modified-apps-step
35+
uses: ./.github/actions/modified_apps
4136
- name: Determine tests to run
4237
uses: actions/github-script@v7
4338
id: tests_to_run
4439
env:
45-
CHANGED_FILES: ${{ steps.changed-files.outputs.changed_files }}
40+
MODIFIED_APPS: ${{ steps.modified-apps-step.outputs.modified_apps }}
4641
with:
4742
script: |
48-
const { CHANGED_FILES } = process.env;
43+
const { MODIFIED_APPS } = process.env;
4944
const fs = require('fs');
5045
const path = require('path');
46+
var has_python_tests = false;
5147
5248
function getPytestPaths(dir, callback)
5349
{
@@ -63,25 +59,29 @@ jobs:
6359
extension = path.extname(file.name);
6460
6561
if (extension == '.py')
66-
{
67-
callback(dir);
62+
{
63+
callback(dir, file.name);
6864
}
6965
}
7066
}
7167
}
7268
73-
const paths = new Set(CHANGED_FILES.split(" ")
74-
.map(x => x.substring(0, x.indexOf("/") + 1))
75-
.filter(x => x.length > 0 && !x.startsWith('.')));
69+
const paths = MODIFIED_APPS.length > 0 ? MODIFIED_APPS.split(",") : []
7670
7771
const pytestPaths = new Set()
7872
const pytestArgs = new Set()
7973
for (const rootPath of paths)
8074
{
8175
let subFoldersWithPythonFiles = 0;
82-
getPytestPaths(rootPath, x =>
76+
getPytestPaths(rootPath, (folder, fileName) =>
8377
{
84-
pytestPaths.add(x);
78+
pytestPaths.add(folder);
79+
80+
if (fileName.startsWith('test'))
81+
{
82+
has_python_tests = true
83+
}
84+
8585
subFoldersWithPythonFiles++
8686
})
8787
@@ -91,21 +91,23 @@ jobs:
9191
}
9292
}
9393
94-
core.setOutput('pytestPaths', [...pytestPaths].join(' '));
95-
core.setOutput('pytestArgs', [...pytestArgs].join(' '));
94+
core.setOutput('pytestPaths', has_tests ? [...pytestPaths].join(' ') : "");
95+
core.setOutput('pytestArgs', has_tests ? [...pytestArgs].join(' ') : "");
9696
9797
- name: Setup test environment
9898
uses: conda-incubator/setup-miniconda@v2
9999
with:
100+
miniconda-version: "latest"
100101
environment-file: ${{ matrix.environment-file }}
101102
- name: Install dependencies
102103
run: |
103104
printf "[pytest]\npythonpath=${{ steps.tests_to_run.outputs.pytestPaths }}" > pytest.ini
104105
python -m pip install pytest
105106
- name: Run tests
106107
run: |
107-
args=${{ steps.tests_to_run.outputs.pytestArgs }}
108-
pythonpath=${{ steps.tests_to_run.outputs.pytestPaths }}
108+
args="${{ steps.tests_to_run.outputs.pytestArgs }}"
109+
pythonpath="${{ steps.tests_to_run.outputs.pytestPaths }}"
110+
109111
if [ -z "${args}" ] || [ -z "${pythonpath}" ]; then
110112
echo “Nothing to test”
111113
else

account-privileges/app/setup_script.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ GRANT USAGE ON PROCEDURE core.app_update_table(NUMBER) TO APPLICATION ROLE app_p
6767

6868
-- 5. Create a streamlit object using the code you wrote in you wrote in src/module-ui, as shown below.
6969
-- The `from` value is derived from the stage path described in snowflake.yml
70-
CREATE STREAMLIT core.ui
70+
CREATE OR REPLACE STREAMLIT core.ui
7171
FROM '/streamlit/'
7272
MAIN_FILE = 'ui.py';
7373

account-privileges/ci.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
snow sql -f 'prepare/references.sql'
2+
snow app run
3+
snow app teardown

config.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
default_connection_name = "default"
2+
3+
[connections]
4+
[connections.default]
5+
account = ""
6+
user = ""
7+
password = ""
8+
role = ""
9+
warehouse = ""

data-mapping/app/manifest.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
manifest_version: 1
22
artifacts:
3-
readme: README.md
43
setup_script: setup_script.sql
54
default_streamlit: ui."Dashboard"
65

data-mapping/ci.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sh prepare_data.sh
2+
snow app run
3+
snow app teardown

reference-usage/ci.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
snow sql -f 'prepare/provider.sql'
2+
snow app run
3+
snow app teardown

0 commit comments

Comments
 (0)