forked from bellshade/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (95 loc) · 3.7 KB
/
pythonapp.yml
File metadata and controls
100 lines (95 loc) · 3.7 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
# doctesting untuk testing python
# jika pull request fail dengan python testing
# akan di review oleh contributor
# jika tidak ada perubahan maka pull request akan ditutup
name: python testing
on:
# target dari branch yang akan di pull request
# atau di commit langsung
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
# untuk build terdapat 3 environment os
# macOS, windows, linux
runs-on: ubuntu-latest
steps:
# menggunakan checkout untuk cek kode
- uses: actions/checkout@v2
# menggunakan environment python versi 3.9
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: "3.9"
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt')}}
# testing bash dengan perintah echo
- name: salam
run: |
echo "Halo!"
echo "Mulai testing..."
echo "harap tunggu sebentar... :)"
# install requirement yang diperlukan
# sebelum testing semua kode
# bisa dilihat requirement yang dibutuhkan
# pada file 'requirements.txt'
- name: Install dependencies
run: |
echo "Mulai jalankan install requirement"
python -m pip install --upgrade pip
pip install -r requirements.txt -r dev-requirements.txt
# memformat kode secara otomatis dengan black
# tujuannya agar kode lebih mudah dibaca
- name: Format otomatis
run: |
echo "Mulai format otomatis"
isort . --profile=black
black .
# ketika sudah di format maka kode akan mengcommit kembali
# dan commit akan otomatis menggunakan github bot yang sudah tersedia
# disini kondisi jika file tersebut ada perubahan maka akan di format
- name: Cek modifikasi file
id: git-check
run: echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "tidak"; else echo "ya"; fi)
- name: Push perubahan
if: steps.git-check.outputs.modified == 'ya' && github.event_name == 'push'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git pull
git commit -am "style: format otomatis dengan black dan isort"
git push
# test python dengan menggunakan pytest dengan perintah lanjutan
# yaitu document testing
- name: Test Python
run: |
echo "Mulai Jalankan testing docstring"
pytest . --doctest-modules --ignore=Basic/ --cov-report=term-missing:skip-covered
# test lint python jika black gagal reformat kode
- name: Test Lint Python
run: |
echo "Mulai Jalankan testing flake8"
flake8 .
# mypy adalah unit testing diluar dari official python
# yang berfungsi jika mengecek kode apakah terdapat kode
# yang bersifat tidak berguna, terlalu rumit, atau kesalahan import
- name: Test mypy
run: mypy --ignore-missing-imports --install-types --non-interactive .
# FIXME : kendala error beberapa directory mypy
# mulai test coverage dan menampilkan hasil presentasi scanning dari pytest
- name: Test coverage
run: |
echo "Mulai testing coverage"
coverage run --source . -m pytest --doctest-modules --ignore=Basic/
# membuat report untuk upload ke codecoverage
# kendala server github tidak respon pada coverage
# untuk sementara dinonaktifkan
# - name: Hasil coverage
# run: |
# echo "Laporan coverage"
# coverage report -m