| name: Release | |
| on: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| branches: [master] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11", "3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pytest | |
| - name: Run tests | |
| run: pytest tests/ -v | |
| get-next-version: | |
| needs: test | |
| uses: semantic-release-action/next-release-version/.github/workflows/next-release-version.yml@v4 | |
| update-version: | |
| needs: get-next-version | |
| runs-on: ubuntu-latest | |
| if: needs.get-next-version.outputs.new-release-published == 'true' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.11 | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Update version | |
| run: | | |
| echo "Updating version..." | |
| python scripts/update_version.py --next-version ${{ needs.get-next-version.outputs.new-release-version }} | |
| - name: Upload updated version file | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: version-file | |
| path: casbin_cli/__version__.py | |
| build-binaries: | |
| needs: update-version | |
| if: needs.get-next-version.outputs.new-release-published == 'true' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| platform: linux | |
| - os: windows-latest | |
| platform: windows | |
| - os: macos-latest | |
| platform: darwin | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.11 | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pyinstaller | |
| - name: Download version file | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: version-file | |
| path: casbin_cli/ | |
| - name: Verify file content | |
| run: | | |
| echo "Content of __version__.py after update:" | |
| cat casbin_cli/__version__.py | |
| - name: Build binary | |
| run: python scripts/build_binaries.py --platform ${{ matrix.platform }} | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binaries-${{ matrix.platform }} | |
| path: dist/casbin-python-cli-${{ matrix.platform }}-* | |
| release: | |
| needs: [test, build-binaries] | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/master' || github.event_name == 'pull_request' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.11 | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install wheel twine | |
| npm install -g semantic-release @semantic-release/changelog @semantic-release/exec @semantic-release/github @semantic-release/git | |
| - name: Download version file | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: version-file | |
| path: casbin_cli/ | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Move binaries to dist | |
| run: | | |
| mkdir -p dist | |
| find artifacts -name "casbin-python-cli-*" -type f -exec cp {} dist/ \; | |
| ls -la dist/ | |
| - name: Semantic Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| #PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} | |
| run: npx semantic-release |