|
| 1 | +name: CICD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize] |
| 9 | + branches: |
| 10 | + - main |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + name: Run Tests, Pre-Commits, and Build Python package |
| 16 | + uses: ./.github/workflows/ci.yml |
| 17 | + |
| 18 | + check-version: |
| 19 | + needs: build |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + outputs: |
| 24 | + version: ${{ steps.get_version.outputs.VERSION }} |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v3 |
| 27 | + |
| 28 | + - name: Set up Python and Poetry |
| 29 | + uses: ./.github/actions/python-poetry |
| 30 | + with: |
| 31 | + cache: true |
| 32 | + |
| 33 | + - name: Get version from pyproject.toml |
| 34 | + id: get_version |
| 35 | + run: | |
| 36 | + echo ::set-output name=VERSION::$(poetry version -s) |
| 37 | +
|
| 38 | + - name: Get latest release version |
| 39 | + id: get_latest_release |
| 40 | + run: | |
| 41 | + latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) |
| 42 | + echo ::set-output name=LATEST_VERSION::${latest_release#v} |
| 43 | +
|
| 44 | + - name: Compare versions |
| 45 | + run: | |
| 46 | + current_version="${{ steps.get_version.outputs.VERSION }}" |
| 47 | + latest_version="${{ steps.get_latest_release.outputs.LATEST_VERSION }}" |
| 48 | + if [ "$(printf '%s\n' "$latest_version" "$current_version" | sort -V | tail -n1)" != "$current_version" ]; then |
| 49 | + echo "Error: Current version ($current_version) is not higher than the latest release ($latest_version)" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + create-release: |
| 54 | + needs: check-version |
| 55 | + runs-on: ubuntu-latest |
| 56 | + permissions: |
| 57 | + contents: write |
| 58 | + id-token: write |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v3 |
| 61 | + with: |
| 62 | + fetch-depth: 0 |
| 63 | + |
| 64 | + - name: Create and push tag |
| 65 | + run: | |
| 66 | + git config --local user.email "action@github.com" |
| 67 | + git config --local user.name "GitHub Action" |
| 68 | + git tag -a v${{ needs.check-version.outputs.version }} -m "Release v${{ needs.check-version.outputs.version }}" |
| 69 | + git push origin v${{ needs.check-version.outputs.version }} |
| 70 | +
|
| 71 | + - name: Create GitHub Release |
| 72 | + uses: actions/create-release@v1 |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + with: |
| 76 | + tag_name: v${{ needs.check-version.outputs.version }} |
| 77 | + release_name: Release v${{ needs.check-version.outputs.version }} |
| 78 | + draft: false |
| 79 | + prerelease: false |
| 80 | + |
| 81 | + publish-to-pypi: |
| 82 | + needs: [build, check-version, create-release] |
| 83 | + name: Publish Python package to PyPI |
| 84 | + runs-on: ubuntu-latest |
| 85 | + permissions: |
| 86 | + contents: read |
| 87 | + steps: |
| 88 | + - uses: actions/checkout@v3 |
| 89 | + |
| 90 | + - name: Set up Python and Poetry |
| 91 | + uses: ./.github/actions/python-poetry |
| 92 | + with: |
| 93 | + cache: true # Enable caching if your custom action supports it |
| 94 | + |
| 95 | + - name: Download wheel |
| 96 | + uses: actions/download-artifact@v4 |
| 97 | + with: |
| 98 | + name: ${{ github.event.repository.name }} |
| 99 | + path: dist/ |
| 100 | + |
| 101 | + - name: Publish to PyPI |
| 102 | + env: |
| 103 | + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} |
| 104 | + run: | |
| 105 | + poetry config pypi-token.pypi $PYPI_TOKEN |
| 106 | + poetry publish |
0 commit comments