SNOW-1449792: Adding pipeline to integrate modified apps into Snowflake #148
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: native-app-examples | |
on: [ pull_request, push ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- environment-file: shared_python_ci_env.yml | |
defaults: | |
run: | |
shell: bash -l {0} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.10" | |
- name: Get modified apps | |
id: modified-apps-step | |
uses: ./.github/actions/modified_apps | |
- name: Determine tests to run | |
uses: actions/github-script@v7 | |
id: tests_to_run | |
env: | |
MODIFIED_APPS: ${{ steps.modified-apps-step.outputs.modified_apps }} | |
with: | |
script: | | |
const { MODIFIED_APPS } = process.env; | |
const fs = require('fs'); | |
const path = require('path'); | |
var has_python_tests = false; | |
function getPytestPaths(dir, callback) | |
{ | |
const files = fs.readdirSync(dir, { withFileTypes: true }); | |
for (const file of files) | |
{ | |
if (file.isDirectory()) | |
{ | |
getPytestPaths(path.join(dir, file.name), callback); | |
} | |
else | |
{ | |
extension = path.extname(file.name); | |
if (extension == '.py') | |
{ | |
callback(dir, file.name); | |
} | |
} | |
} | |
} | |
const paths = MODIFIED_APPS.length > 0 ? MODIFIED_APPS.split(",") : [] | |
const pytestPaths = new Set() | |
const pytestArgs = new Set() | |
for (const rootPath of paths) | |
{ | |
let subFoldersWithPythonFiles = 0; | |
getPytestPaths(rootPath, (folder, fileName) => | |
{ | |
pytestPaths.add(folder); | |
if (fileName.startsWith('test')) | |
{ | |
has_python_tests = true | |
} | |
subFoldersWithPythonFiles++ | |
}) | |
if (subFoldersWithPythonFiles > 0) | |
{ | |
pytestArgs.add(rootPath) | |
} | |
} | |
core.setOutput('pytestPaths', has_python_tests ? [...pytestPaths].join(' ') : ""); | |
core.setOutput('pytestArgs', has_python_tests ? [...pytestArgs].join(' ') : ""); | |
- name: Setup test environment | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
miniconda-version: "latest" | |
environment-file: ${{ matrix.environment-file }} | |
- name: Install dependencies | |
run: | | |
printf "[pytest]\npythonpath=${{ steps.tests_to_run.outputs.pytestPaths }}" > pytest.ini | |
python -m pip install pytest | |
- name: Run tests | |
run: | | |
args="${{ steps.tests_to_run.outputs.pytestArgs }}" | |
pythonpath="${{ steps.tests_to_run.outputs.pytestPaths }}" | |
if [ -z "${args}" ] || [ -z "${pythonpath}" ]; then | |
echo “Nothing to test” | |
else | |
pytest $args | |
fi | |