Flexonze / django-auto-actions

Automatically generates basic Django admin actions based on your models' fields
MIT License
14 stars 4 forks source link

Add GitHub Actions Pipeline for Tests & Linting #1

Closed GabLeRoux closed 6 days ago

GabLeRoux commented 6 days ago

This PR introduces a GitHub Actions workflow that automates the following tasks:

Both jobs are triggered on push, ensuring continuous integration for testing and linting.

Closes #3

GabLeRoux commented 6 days ago

Note that this is not working 100% yet: CleanShot 2024-09-23 at 11 15 50

Run python manage.py migrate
  python manage.py migrate
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.11.10/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.11.10/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.10/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.10/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.10/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.11.10/x64/lib
python: can't open file '/home/runner/work/django-auto-actions/django-auto-actions/manage.py': [Errno 2] No such file or directory
Error: Process completed with exit code 2.

Also, going forward with this implementation, you will need to create an account and connect Codecov to this repository (free for open source projects). There are other options out there if you prefer, I just went ahead with this one ;)

edit: I removed the migrate part and workflow reaches the tests now :+1:

GabLeRoux commented 6 days ago
Run coverage run --source='.' runtests.py
  coverage run --source='.' runtests.py
  coverage xml
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.11.10/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.11.10/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.10/x64
    Python[2](https://github.com/GabLeRoux/django-auto-actions/actions/runs/10997437987/job/30532964444#step:8:2)_ROOT_DIR: /opt/hostedtoolcache/Python/[3](https://github.com/GabLeRoux/django-auto-actions/actions/runs/10997437987/job/30532964444#step:8:3).11.10/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.10/x6[4](https://github.com/GabLeRoux/django-auto-actions/actions/runs/10997437987/job/30532964444#step:8:4)
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.11.10/x64/lib
Migrations for 'django_auto_actions':
  django_auto_actions/migrations/0001_initial.py
    + Create model TestModel
Operations to perform:
  Synchronize unmigrated apps: messages, staticfiles
  Apply all migrations: admin, auth, contenttypes, django_auto_actions, sessions, sites
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.000[5](https://github.com/GabLeRoux/django-auto-actions/actions/runs/10997437987/job/30532964444#step:8:5)_alter_user_last_login_null... OK
  Applying auth.000[6](https://github.com/GabLeRoux/django-auto-actions/actions/runs/10997437987/job/30532964444#step:8:6)_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying django_auto_actions.0001_initial... OK
  Applying sessions.0001_initial... OK
  Applying sites.0001_initial... OK
  Applying sites.0002_alter_domain_unique... OK
Creating test database for alias 'default' ('test_django_auto_actions')...
Found 6 test(s).
Operations to perform:
  Synchronize unmigrated apps: messages, staticfiles
  Apply all migrations: admin, auth, contenttypes, django_auto_actions, sessions, sites
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.000[7](https://github.com/GabLeRoux/django-auto-actions/actions/runs/10997437987/job/30532964444#step:8:7)_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying django_auto_actions.0001_initial... OK
  Applying sessions.0001_initial... OK
  Applying sites.0001_initial... OK
  Applying sites.0002_alter_domain_unique... OK
System check identified no issues (0 silenced).
test_actions_can_be_excluded (django_auto_actions.tests.test_main.AutoActionsMixinTest.test_actions_can_be_excluded) ... ok
test_actions_generated (django_auto_actions.tests.test_main.AutoActionsMixinTest.test_actions_generated) ... ok
test_boolean_fields_actions (django_auto_actions.tests.test_main.AutoActionsMixinTest.test_boolean_fields_actions) ... ok
test_date_fields_actions (django_auto_actions.tests.test_main.AutoActionsMixinTest.test_date_fields_actions) ... ok
test_datetime_fields_actions (django_auto_actions.tests.test_main.AutoActionsMixinTest.test_datetime_fields_actions) ... ok
test_time_fields_actions (django_auto_actions.tests.test_main.AutoActionsMixinTest.test_time_fields_actions) ... ok

----------------------------------------------------------------------
Ran 6 tests in 0.037s

OK
Destroying test database for alias 'default' ('test_django_auto_actions')...
Traceback (most recent call last):
  File "/home/runner/work/django-auto-actions/django-auto-actions/runtests.py", line [8](https://github.com/GabLeRoux/django-auto-actions/actions/runs/10997437987/job/30532964444#step:8:8)8, in <module>
    runtests()
  File "/home/runner/work/django-auto-actions/django-auto-actions/runtests.py", line 82, in runtests
    shutil.rmtree(folder)
  File "/opt/hostedtoolcache/Python/3.11.[10](https://github.com/GabLeRoux/django-auto-actions/actions/runs/10997437987/job/30532964444#step:8:10)/x64/lib/python3.11/shutil.py", line 742, in rmtree
    onerror(os.lstat, path, sys.exc_info())
  File "/opt/hostedtoolcache/Python/3.[11](https://github.com/GabLeRoux/django-auto-actions/actions/runs/10997437987/job/30532964444#step:8:11).10/x64/lib/python3.11/shutil.py", line 740, in rmtree
    orig_st = os.lstat(path, dir_fd=dir_fd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/work/django-auto-actions/django_auto_actions/django_auto_actions/migrations'
Name                          Stmts   Miss  Cover   Missing
-----------------------------------------------------------
django_auto_actions/main.py      48      0   100%
-----------------------------------------------------------
TOTAL                            48      0   100%
Error: Process completed with exit code 1.

That part seems specific to the project and runtests.py.

Maybe we can update runtests.py and not consider it a failure if it fails to delete the migrations folder? 🤔

GabLeRoux commented 6 days ago

Note: you can see the actions execution on my fork's Actions tab here: https://github.com/GabLeRoux/django-auto-actions/actions

Flexonze commented 6 days ago

TYSM @GabLeRoux! I've added the CODECOV_TOKEN, not sure if I need to do anything else for it to work.

There is a lot of shenanigans going on in runtests.py and _tests/testmain.py since it is not really a Django app, but I need to create Django models/admins in the tests.

Maybe we can update runtests.py and not consider it a failure if it fails to delete the migrations folder? 🤔

Yes that would be a nice improvement

GabLeRoux commented 6 days ago

Perfect, I'll update this so the tests can pass. I think adding CODECOV_TOKEN was the only required step for it to work. We'll see 🙌

GabLeRoux commented 6 days ago

Github Actions execution

Github Actions summary

satisfied

Codecov summary

🚀

GabLeRoux commented 6 days ago

I find it weird that django_auto_actions shows 0%, but maybe it's normal. 🤷 This is ready to merge :shipit:

Flexonze commented 6 days ago

I find it weird that django_auto_actions shows 0%, but maybe it's normal. 🤷 This is ready to merge :shipit:

Hmm I find it weird too. _django_autoactions/main.py is supposed to be 100% covered. Also I would expect setup.py and runtests.py to not affect code coverage. I added them to the omit section in .coveragerc in this commit.

GabLeRoux commented 6 days ago

Here's a handy tip for anyone looking to test pipeline changes without pushing to GitHub every time: I recommend using act. It lets you run GitHub Actions locally, making the process faster and more efficient.

To use it, the command is straightforward:

act -j test

Or, if you need to specify the Docker socket:

act --container-daemon-socket="unix:///var/run/docker.sock" -j test

This approach can save you time and make your workflow smoother! 🚀

Flexonze commented 6 days ago

Thanks again for this! I'm merging it. I'll try to see what I can do for the coverage report in another PR.