-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (94 loc) · 3.54 KB
/
apps.yaml
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
name: PyApps Tests
on:
push:
branches:
- main
paths:
- 'components/**'
- 'scripts/create_seed.py'
pull_request:
branches:
- main
paths:
- 'components/**'
- 'scripts/create_seed.py'
jobs:
test_pyapps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
#https://stackoverflow.com/questions/74265821/get-modified-files-in-github-actions
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}'
- run: |
echo -n "${{ secrets.ENV_FILE }}" >> $GITHUB_ENV
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pipenv'
- name: Install pipenv
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
- run: pipenv install --dev --verbose
- name: Get changed files
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: Run tests
run: |
echo "Changed Files:"
echo "${{ steps.changed-files.outputs.changed_files }}"
echo ""
for file in ${{ steps.changed-files.outputs.changed_files }}; do
if [[ $file == *.py ]]; then
echo "Processing File: $file"
directory=$(dirname "$file")
directory="$directory"
echo "Directory: $directory"
case $directory in
"components/airflow/dags")
test_files="test_airflow_addons.py test_airflow.py"
;;
"components/data_validation")
test_files="test_validation.py"
;;
"components/docs_app/docker")
test_files="test_docsapp.py"
;;
"components/ml_train/scripts")
test_files="test_train.py"
;;
"components/ml_serve/docker")
test_files="test_serve.py"
;;
"components/scripts")
test_files="test_create_seed.py"
;;
*)
echo "No relevant test files found for $file"
continue
;;
esac
echo "Test Files: $test_files"
echo "Running Tests..."
IFS=' ' read -ra test_files_array <<< "$test_files"
for test_file in "${test_files_array[@]}"; do
echo "Running pytest for $test_file"
pipenv run python -m pytest "tests/$test_file" --trace
done
echo ""
fi
done
- name: Format-Lint-Sort
run: |
if [[ $(git diff-tree --no-commit-id --name-only --diff-filter=ACMRT -r ${{ github.sha }} -- '*.py' | xargs) ]]; then
pipenv run python -m black --check $(git diff-tree --no-commit-id --name-only --diff-filter=ACMRT -r "$GITHUB_SHA" -- '*.py' | xargs)
pipenv run python -m isort $(git diff-tree --no-commit-id --name-only --diff-filter=ACMRT -r "$GITHUB_SHA" -- '*.py' | xargs)
fi