SNOW-1482571: Add CI pipeline for apps unit testing #52
Workflow file for this run
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: | |
types: | |
- opened | |
- edited | |
- labeled | |
- unlabeled | |
- synchronize | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- environment-file: local_test_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 changes | |
id: changed-files | |
run: | | |
if ${{ github.event_name == 'pull_request' }}; then | |
echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT | |
else | |
echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT | |
fi | |
- name: Determine tests to run | |
uses: actions/github-script@v7 | |
env: | |
CHANGED_FILES: ${{ steps.changed-files.outputs.changed_files }} | |
with: | |
script: | | |
const { CHANGED_FILES } = process.env | |
const fs = require('fs'); | |
const path = require('path'); | |
function getPytestPaths(dir) | |
{ | |
const files = fs.readdirSync(dir, { withFileTypes: true }); | |
for (const file of files) | |
{ | |
if (file.isDirectory()) | |
{ | |
//yield* getPytestPaths(path.join(dir, file.name)); | |
} | |
else | |
{ | |
extension = path.extname(file.name); | |
if (extension == '.py') | |
{ | |
//yield dir; | |
} | |
} | |
} | |
} | |
const paths = new Set(CHANGED_FILES.split(" ") | |
.map(x => x.substring(0, x.indexOf("/") + 1)) | |
.filter(x => x.length > 0 && !x.startsWith('.'))); | |
for (const rootPath of paths) | |
{ | |
/*for (const path of getPytestPaths(rootPath)) | |
{ | |
console.log(path); | |
}*/ | |
} | |
- name: Setup test environment | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
environment-file: ${{ matrix.environment-file }} | |
- name: Install dependencies | |
run: | | |
python -m pip install pytest | |
- name: Run tests | |
run: | | |
pytest | |