|
| 1 | +name: CI-CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - "v[0-9]+.[0-9]+.[0-9]+" |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + |
| 13 | +jobs: |
| 14 | + constants: |
| 15 | + name: Constants |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + package_name: ${{ steps.output.outputs.package_name }} |
| 19 | + package_version: ${{ steps.output.outputs.package_version }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + - uses: actions/setup-python@v4 |
| 23 | + with: |
| 24 | + python-version: '3.11' |
| 25 | + - id: output |
| 26 | + run: | |
| 27 | + echo package_name=$(python -c 'import tomllib;from pathlib import Path;print(tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))["tool"]["poetry"]["name"])') >> $GITHUB_OUTPUT |
| 28 | + echo package_version=$(python -c 'import tomllib;from pathlib import Path;print(tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))["tool"]["poetry"]["version"])') >> $GITHUB_OUTPUT |
| 29 | + lint: |
| 30 | + name: Lint |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v3 |
| 34 | + - uses: actions/setup-python@v4 |
| 35 | + with: |
| 36 | + python-version: '3.11' |
| 37 | + - name: Install tox |
| 38 | + run: python -m pip install tox |
| 39 | + - name: Run linting |
| 40 | + run: tox -e lint |
| 41 | + test: |
| 42 | + name: Test |
| 43 | + runs-on: ubuntu-latest |
| 44 | + strategy: |
| 45 | + matrix: |
| 46 | + python-version: |
| 47 | + - "3.8" |
| 48 | + - "3.9" |
| 49 | + - "3.10" |
| 50 | + - "3.11" |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v3 |
| 53 | + - name: Set up Python ${{ matrix.python-version }} |
| 54 | + uses: actions/setup-python@v4 |
| 55 | + with: |
| 56 | + python-version: ${{ matrix.python-version }} |
| 57 | + - name: Install tox |
| 58 | + run: python -m pip install tox |
| 59 | + - name: Run testing |
| 60 | + run: tox -e test |
| 61 | + release-test-pypi: |
| 62 | + runs-on: ubuntu-latest |
| 63 | + if: startsWith(github.ref, 'refs/tags/') |
| 64 | + needs: |
| 65 | + - test |
| 66 | + - lint |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v3 |
| 69 | + - uses: actions/setup-python@v4 |
| 70 | + with: |
| 71 | + python-version: '3.11' |
| 72 | + - name: Install poetry |
| 73 | + run: python -m pip install poetry |
| 74 | + - name: Publish |
| 75 | + run: | |
| 76 | + poetry config repositories.test-pypi https://test.pypi.org/legacy/ |
| 77 | + poetry publish --build -u __token__ -p ${{ secrets.test_pypi_password }} -r test-pypi |
| 78 | + test-release-test-pypi: |
| 79 | + runs-on: ubuntu-latest |
| 80 | + if: startsWith(github.ref, 'refs/tags/') |
| 81 | + needs: |
| 82 | + - release-test-pypi |
| 83 | + - constants |
| 84 | + strategy: |
| 85 | + matrix: |
| 86 | + python-version: |
| 87 | + - "3.8" |
| 88 | + - "3.9" |
| 89 | + - "3.10" |
| 90 | + - "3.11" |
| 91 | + steps: |
| 92 | + - name: Set up Python ${{ matrix.python-version }} |
| 93 | + uses: actions/setup-python@v4 |
| 94 | + with: |
| 95 | + python-version: ${{ matrix.python-version }} |
| 96 | + - name: Run check |
| 97 | + run: | |
| 98 | + for i in 1 2 3 4 5; do python -m pip install flake8 ${{ needs.constants.outputs.package_name }}==${{ needs.constants.outputs.package_version }} --extra-index-url https://test.pypi.org/simple/ && break || sleep 10; done |
| 99 | + echo '"""Docstring."""' > source.py |
| 100 | + flake8 source.py |
| 101 | + release-pypi: |
| 102 | + runs-on: ubuntu-latest |
| 103 | + if: startsWith(github.ref, 'refs/tags/') |
| 104 | + needs: |
| 105 | + - test-release-test-pypi |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v3 |
| 108 | + - uses: actions/setup-python@v4 |
| 109 | + with: |
| 110 | + python-version: '3.11' |
| 111 | + - name: Install poetry |
| 112 | + run: python -m pip install poetry |
| 113 | + - name: Publish |
| 114 | + run: poetry publish --build -u __token__ -p ${{ secrets.pypi_password }} |
| 115 | + release-github: |
| 116 | + runs-on: ubuntu-latest |
| 117 | + if: startsWith(github.ref, 'refs/tags/') |
| 118 | + needs: |
| 119 | + - release-pypi |
| 120 | + steps: |
| 121 | + - name: Get version from tag |
| 122 | + id: tag_name |
| 123 | + run: | |
| 124 | + echo current_version=${GITHUB_REF#refs/tags/v} >> $GITHUB_OUTPUT |
| 125 | + shell: bash |
| 126 | + - uses: actions/checkout@v3 |
| 127 | + - name: Get latest Changelog Entry |
| 128 | + id: changelog_reader |
| 129 | + uses: mindsers/changelog-reader-action@v2 |
| 130 | + with: |
| 131 | + version: v${{ steps.tag_name.outputs.current_version }} |
| 132 | + path: ./CHANGELOG.md |
| 133 | + - name: Create Release |
| 134 | + id: create_release |
| 135 | + uses: actions/create-release@v1 |
| 136 | + env: |
| 137 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 138 | + with: |
| 139 | + tag_name: ${{ steps.changelog_reader.outputs.version }} |
| 140 | + release_name: Release ${{ steps.changelog_reader.outputs.version }} |
| 141 | + body: ${{ steps.changelog_reader.outputs.changes }} |
| 142 | + prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }} |
| 143 | + draft: ${{ steps.changelog_reader.outputs.status == 'unreleased' }} |
| 144 | + test-release-pypi: |
| 145 | + runs-on: ubuntu-latest |
| 146 | + if: startsWith(github.ref, 'refs/tags/') |
| 147 | + needs: |
| 148 | + - release-pypi |
| 149 | + - constants |
| 150 | + strategy: |
| 151 | + matrix: |
| 152 | + python-version: |
| 153 | + - "3.8" |
| 154 | + - "3.9" |
| 155 | + - "3.10" |
| 156 | + - "3.11" |
| 157 | + steps: |
| 158 | + - name: Set up Python ${{ matrix.python-version }} |
| 159 | + uses: actions/setup-python@v4 |
| 160 | + with: |
| 161 | + python-version: ${{ matrix.python-version }} |
| 162 | + - name: Run check |
| 163 | + run: | |
| 164 | + for i in 1 2 3 4 5; do python -m pip install flake8 ${{ needs.constants.outputs.package_name }}==${{ needs.constants.outputs.package_version }} && break || sleep 10; done |
| 165 | + echo '"""Docstring."""' > source.py |
| 166 | + flake8 source.py |
0 commit comments