Semantic Release #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Semantic Release | |
on: | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
concurrency: release | |
permissions: | |
id-token: write | |
contents: write | |
steps: | |
- name: Check out the code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PAT_TOKEN }} | |
persist-credentials: false | |
- name: Install Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.8" | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
profile: minimal | |
override: true | |
- name: Install Dependencies | |
run: | | |
pip install maturin | |
pip install python-semantic-release toml | |
- name: Python Semantic Release | |
env: | |
GH_TOKEN: ${{ secrets.PAT_TOKEN }} | |
id: release | |
uses: python-semantic-release/[email protected] | |
with: | |
github_token: ${{ secrets.PAT_TOKEN }} | |
- name: Update Versions | |
if: steps.release.outputs.released == 'true' | |
run: | | |
NEW_VERSION="${{ steps.release.outputs.version }}" | |
sed -i "s/^version = .*/version = \"$NEW_VERSION\"/" pyproject.toml | |
sed -i "s/^version = .*/version = \"$NEW_VERSION\"/" Cargo.toml | |
# Debug steps start here | |
- name: Debug - Check file status | |
if: steps.release.outputs.released == 'true' | |
run: | | |
ls -l pyproject.toml Cargo.toml | |
git diff pyproject.toml Cargo.toml | |
- name: Debug - Force add files | |
if: steps.release.outputs.released == 'true' | |
run: git add -f pyproject.toml Cargo.toml | |
- name: Debug - Check Git status | |
if: steps.release.outputs.released == 'true' | |
run: git status | |
- name: Debug - Add files individually | |
if: steps.release.outputs.released == 'true' | |
run: | | |
git add pyproject.toml || echo "Failed to add pyproject.toml" | |
git add Cargo.toml || echo "Failed to add Cargo.toml" | |
- name: Debug - Check .git permissions | |
if: steps.release.outputs.released == 'true' | |
run: ls -la .git | |
# Debug steps end here | |
- name: Commit Changes | |
if: steps.release.outputs.released == 'true' | |
env: | |
PAT: ${{ secrets.PAT_TOKEN }} | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add pyproject.toml Cargo.toml | |
git commit -m "chore: update version to ${{ steps.release.outputs.version }} [skip ci]" || echo "No changes to commit" | |
- name: Push changes | |
if: steps.release.outputs.released == 'true' | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.PAT_TOKEN }} | |
branch: main | |
- name: Build and Publish with Maturin | |
if: steps.release.outputs.released == 'true' | |
env: | |
MATURIN_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
maturin build --release | |
maturin publish --username __token__ --password $MATURIN_PASSWORD |