@@ -43,6 +43,7 @@ The usage of each workflow template.
4343* [ _ rw_organize_test_cov_reports.yaml_ ] ( #rw_organize_test_cov_reportsyaml )
4444* [ _ rw_upload_test_cov_report.yaml_ ] ( #rw_upload_test_cov_reportyaml )
4545* [ _ rw_pre-building_test.yaml_ ] ( #rw_pre-building_testyaml )
46+ * [ _ rw_checking_deployment_state.yaml_ ] ( #rw_checking_deployment_stateyaml )
4647* [ _ rw_build_git-tag_and_create_github-release.yaml_ ] ( #rw_build_git-tag_and_create_github-releaseyaml )
4748* [ _ rw_push_pypi.yaml_ ] ( #rw_push_pypiyaml )
4849
@@ -368,6 +369,96 @@ No, nothing at all.
368369
369370<hr>
370371
372+ ### _rw_checking_deployment_state_
373+
374+ * Description: Before truly deployment, e.g., release and push Python package to PyPI, it would check the release
375+ relative information to judge whether it should release or not.
376+ * Requirement: The target project must has one Python module named **_\_\_ pkg_info\_\_ .py_**. And the content of it
377+ should be like following:
378+ ` ` ` python
379+ __version__ = "0.2.3"
380+ ```
381+ * How to trigger it?:
382+
383+ It would use the package info module to get the current Package version info. And it would also try to install the
384+ Python package from PyPI to get the latest version of it. Finally, it would use this 2 version info to compare whether
385+ the project current version is same as the version in PyPI or not. If it is, it would skip. But if it isn't, it would
386+ start to run deployment process to release.
387+
388+ > [ !NOTE]
389+ > For the newborn project, it won't be released to PyPI before, it
390+ > would set its software version as 0.0.0 at default.
391+
392+ * Trigger condition:
393+
394+ 1 . Python file ** _ \_\_ pkg_info\_\_ .py_ ** has been updated.
395+ 2 . The property ** _ \_\_ version\_\_ _ ** has been updated. (aka the software version value)
396+ 3 . The software version value is different with the version in PyPI.
397+
398+ * Options:
399+
400+ | option name | data type | optional or required | function content |
401+ | --------------------------| -----------| ------------------------------------| ----------------------------------------------------------------------------------------------------------|
402+ | working-directory | string | Optional, Default value is _ ./_ | The working directory for this CI running. |
403+ | library-name | string | Required | The target library name for checking the version info. |
404+ | library-source-code-path | string | Required_ | The source code path of target library to check. |
405+ | library-default-version | string | Optional, Default value is _ 0.0.0_ | The default value of software version if it cannot get the software version info from installed library. |
406+
407+ * Output:
408+
409+ Yes, it has running result output. It would output the updating state about whether the version has been updated or not.
410+ And the CI workflow after-process could use this output result to judge whether it should run the deployment process or not.
411+
412+ | Upload-Artifact name | description |
413+ | ----------------------| -----------------------------------------------------------------------------------------------|
414+ | version_update_state | The version update state. It only has 2 states: ** VERSION UPDATE** and ** NO VERSION UPDATE** . |
415+
416+ * How to use it?
417+
418+ * ** _ cd.yaml_ ** usage case:
419+
420+ ``` yaml
421+ name : CD
422+
423+ on :
424+ # Run the deployment about publishing the Python source code to PyPI.
425+ push :
426+ branches :
427+ - " master"
428+ paths :
429+ # This deployment workflow would only be triggered by file change of module *__pkg_info__* because it has the package version info.
430+ # - ".github/workflows/cd.yaml" # For test or emergency scenario only
431+ - " **/__pkg_info__.py"
432+
433+ jobs :
434+ check_version-state :
435+ # name: Check the version update state
436+ uses : ./.github/workflows/rw_checking_deployment_state.yaml
437+ with :
438+ library-name : your-python-package-name
439+ library-source-code-path : ./your_source_code_directory
440+
441+ push_python_pkg_to_pypi :
442+ # name: Check about it could work finely by installing the Python package with setup.py file
443+ needs : check_version-state
444+ if : ${{ needs.check_version-state.outputs.version_update_state == 'VERSION UPDATE' }}
445+ uses : Chisanan232/GitHub-Action_Reusable_Workflows-Python/.github/workflows/rw_push_pypi.yaml@v7.2
446+ with :
447+ build-type : poetry
448+ release-type : ${{ needs.build_git-tag_and_create_github-release.outputs.python_release_version }}
449+ push-to-PyPI : official
450+ secrets :
451+ PyPI_user : ${{ secrets.PYPI_USERNAME }}
452+ PyPI_token : ${{ secrets.PYPI_PASSWORD }}
453+ ` ` `
454+
455+ The badge it generates:
456+
457+ [](https://github.com/Chisanan232/GitHub-Action-Template-Python/releases)
458+
459+ <hr>
460+
461+
371462### _rw_build_git-tag_and_create_github-release.yaml_
372463
373464* Description: Build a git tag on a specific commit in every git branch. And create GitHub release if current git branch is 'master'.
0 commit comments