Skip to content

Commit

Permalink
🐎 ci: version number should be string
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-yang-biz committed Aug 25, 2022
1 parent a1d78aa commit 4df82c8
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 170 deletions.
37 changes: 18 additions & 19 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ name: dev build CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
# Triggers the workflow on push or pull request events
push:
branches:
- '*'
pull_request:
branches:
- '*'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand All @@ -29,7 +28,6 @@ jobs:
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}

# uncomment the following to pickup services
services:
redis:
image: redis
Expand Down Expand Up @@ -73,31 +71,32 @@ jobs:
python -m pip install --upgrade pip
pip install poetry tox tox-gh-actions
- name: Declare variables for convention
# declare env.package_version, env.package_version, env.package_name, env.repo_owner, env.repo_name, so you may use it in web hooks.
- name: Declare variables for convenient use
run: |
echo "package_version_short=`poetry version --short`.DEV.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
echo "package_version_full=`poetry version`.DEV.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
echo "package_version=`poetry version --short`" >> $GITHUB_ENV
echo "package_name=`poetry version | awk '{print $1}'`" >> $GITHUB_ENV
echo "repo_owner=${GITHUB_REPOSITORY%/*}" >> $GITHUB_ENV
echo "repo_name=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
shell: bash

- name: build documentation
run: |
poetry install -E doc
poetry run mkdocs build
git config --global user.name Docs deploy
git config --global user.email docs@dummy.bot.com
poetry run mike deploy "`poetry version --short`.dev"
poetry run mike set-default "`poetry version --short`.dev"
poetry run mike deploy -p -f --ignore "`poetry version --short`.dev"
poetry run mike set-default -p "`poetry version --short`.dev"
- name: publish documentation
uses: peaceiris/actions-gh-pages@v3
- uses: codecov/codecov-action@v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
publish_dir: ./site

fail_ci_if_error: true
files: coverage.xml
- name: Build wheels and source tarball
run: |
poetry version $(poetry version --short)-dev.$GITHUB_RUN_NUMBER
poetry lock
poetry build
- name: publish to Test PyPI
Expand All @@ -109,18 +108,18 @@ jobs:
skip_existing: true

- name: Dingtalk Robot Notify
if: always()
uses: leafney/dingtalk-action@v1.0.0
env:
env:
DINGTALK_ACCESS_TOKEN: ${{ secrets.DINGTALK_ACCESS_TOKEN }}
DINGTALK_SECRET: ${{ secrets.DINGTALK_SECRET }}
with:
msgtype: markdown
notify_when: 'success'
title: CI Notification | Success
text: |
### Build success
${{ env.package_version_full }} is built and published to test pypi
### Build Success
${{ env.package_name }}.${{ env.package_version }} built successfully and published to test pypi
### Change History
Please check change history at https://${{ env.repo_owner }}.github.io/${{ env.repo_name }}/history
### package download
Please download the pacakge at: https://test.pypi.org/project/${{ env.repo_name }}/
### Package Download
Please download the package at: https://test.pypi.org/project/${{ env.repo_name }}/
49 changes: 27 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# This workflow contains a single job called "build"
release:
name: Create Release
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

strategy:
matrix:
Expand All @@ -35,6 +35,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-versions }}
Expand All @@ -43,26 +44,28 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install tox-gh-actions poetry
echo "package_version_short=`poetry version --short`" >> $GITHUB_ENV
echo "package_version_full=`poetry version` >> $GITHUB_ENV
- name: build documentation
# declare env.package_version, env.package_version, env.package_name, env.repo_owner, env.repo_name, so you may use it in web hooks.
- name: Declare variables for convenient use
run: |
echo "package_version=`poetry version --short`" >> $GITHUB_ENV
echo "package_name=`poetry version | awk '{print $1}'`" >> $GITHUB_ENV
echo "repo_owner=${GITHUB_REPOSITORY%/*}" >> $GITHUB_ENV
echo "repo_name=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
shell: bash

- name: publish documentation
run: |
poetry install -E doc
poetry run mkdocs build
git config --global user.name Docs deploy
git config --global user.email docs@dummy.bot.com
poetry run mike deploy `poetry version --short`
poetry run mike set-default `poetry version --short`
- name: publish documentation
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
publish_dir: ./site
poetry run mike deploy -p -f --ignore `poetry version --short`
poetry run mike set-default -p `poetry version --short`
- name: Build wheels and source tarball
run: >-
run: |
poetry lock
poetry build
- name: Create Release
Expand All @@ -77,6 +80,8 @@ jobs:
draft: false
prerelease: false

- uses: codecov/codecov-action@v3

- name: publish to PYPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand All @@ -85,18 +90,18 @@ jobs:
skip_existing: true

- name: Dingtalk Robot Notify
if: always()
uses: leafney/dingtalk-action@v1.0.0
env:
env:
DINGTALK_ACCESS_TOKEN: ${{ secrets.DINGTALK_ACCESS_TOKEN }}
DINGTALK_SECRET: ${{ secrets.DINGTALK_SECRET }}
with:
msgtype: markdown
notify_when: 'success'
title: Release ${{ package_version_full }}
title: CI Notification | Success
text: |
## ${{ package_version_full }} 已发布
${{ steps.build_changelog.outputs.changelog }}
## 变更历史
https://zillionare.github.io/cfg4py/history
## 下载
https://pypi.org/project/cfg4py
### Build Success
${{ env.package_version_full }} built successfully and published to pypi
### Change History
Please check change history at https://${{ env.repo_owner }}.github.io/${{ env.repo_name }}/history
### Package Download
Please download the pacakge at: https://pypi.org/project/${{ env.repo_name }}/
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
!!! Info
`(#{number})` means an issue of this project. You may check details of the issue by visiting https://github.com/zillionare/cfg4py/issues/_{number}_

## 0.9.4 (2022-08-25)
* lock apscheduler version to 3.9.1. APScheduler 4.0 has been refactored thus cause importing error.
## 0.9.3 (2022-06-03)

* on apple m1, it's not able to watch file changes, and cause cfg4py fail. This revision will disable hot-reload in such scenario and user can still use all other functions of cfg4py.
Expand Down
58 changes: 25 additions & 33 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
=====
Usage
=====

Quick Guide
-----------
## Quick Guide

To use Cfg4Py in a project:

.. code:: python

```python
import cfg4py

# create config object
Expand All @@ -26,33 +19,32 @@ To use Cfg4Py in a project:

# you CANNOT access settings like this way (this will raise exceptions):
print(cfg["services"])
```

Exhausted Guide
---------------

Step 1.
~~~~~~~
Use Cfg4Py tool to generate configuration templates:
## Exhausted Guide

.. code:: console
### Step 1.
Use Cfg4Py tool to generate configuration templates:

```console
cfg4py scaffold
```

The output is:

.. image:: static/scaffold.png
![](https://images.jieyu.ai/images/2020-10/scaffold.png)

You may need modify settings according to your enviroment.

Step 2.
~~~~~~~
Build config class, and import it into your project:
### Step 2.

.. code-block:: console
Build config class, and import it into your project:

``` console
cfg4py build /path/to/your/config/dir

.. code-block:: python
```
```python

from typing import TYPE_CHECKING
if TYPE_CHECKING:
Expand All @@ -64,15 +56,15 @@ Build config class, and import it into your project:

# now you should be able to get auto-complete hint while typing
cfg.?
```
### Step 3.

Step 3.
~~~~~~~
cfg4py will take care of setting's change automatically, all you need to do is put correct settings into one of
(defaults, dev, test, production) config file. And once you change the settings, it should take effect immediately.

To enable cascading config, you can configure a remote source by implemented a subclass of `RemoteConfigFetcher`. A redis fetcher is provided out-of-box:

.. code-block:: python
```python

from cfg4py import RedisConfigFetcher
from redis import StrictRedis
Expand All @@ -81,26 +73,26 @@ To enable cascading config, you can configure a remote source by implemented a s
fetcher = RedisConfigFetcher(key="my_app_config")
logger.info("configuring a remote fetcher")
cfg4py.config_remote_fetcher(fetcher, 1)
```

The settings in redis under `key` should be a json string, which can be converted into a dict object.

Step 4.
~~~~~~~~
### Step 4.
Before starting run your application, you should set __cfg4py_server_role__ to any of [DEV,TEST,PRODUCTION] (since 0.9.0, required only if you specified as `strict` mode). You can run the following command to get the help:

.. code-block:: bash
```console

cfg4py hint set_server_role

.. hint::
```

???+ info
since 0.9.0, you can skip this step, if you don't need adaptive deployment support.

Use cfg4py as a cheat sheet
----------------------------
## Use cfg4py as a cheat sheet
cfg4py does more than a config module, it can be a cheat sheet for many configurations. For example, want to change pip source (usually you'll if you're in china mainland):

.. code-block:: console
```console

cfg4py hint pip

Expand All @@ -109,6 +101,6 @@ cfg4py does more than a config module, it can be a cheat sheet for many configur
- aliyun: pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
- tencent: pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
- douban: pip config set global.index-url http://pypi.douban.com/simple/

```

for more, explore by yourself by typing `cfg4py hint`

0 comments on commit 4df82c8

Please sign in to comment.