Release #2
This file contains hidden or 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: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: 'Version bump type' | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out develop | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: develop | |
| fetch-depth: 0 | |
| token: ${{ secrets.RELEASE_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Install Poetry | |
| run: | | |
| curl -sSL https://install.python-poetry.org | python3 - | |
| echo "$HOME/.local/bin" >> $GITHUB_PATH | |
| - name: Install dependencies | |
| run: poetry install --all-extras | |
| - name: Run tests | |
| env: | |
| FLASHPOINT_API_KEY: dummy | |
| IPQS_API_KEY: dummy | |
| SPYCLOUD_API_ATO_KEY: dummy | |
| TWILIO_API_SID: dummy | |
| TWILIO_API_SECRET: dummy | |
| URLSCAN_API_KEY: dummy | |
| PYTHONPATH: . | |
| run: poetry run pytest --ignore=dev_env | |
| - name: Bump version | |
| id: bump | |
| run: | | |
| python3 << 'PYEOF' | |
| import re, os | |
| bump_type = "${{ inputs.bump }}" | |
| with open("pyproject.toml", "r") as f: | |
| content = f.read() | |
| match = re.search(r'^version\s*=\s*"(\d+)\.(\d+)\.(\d+)"', content, re.MULTILINE) | |
| major, minor, patch = int(match.group(1)), int(match.group(2)), int(match.group(3)) | |
| if bump_type == "major": | |
| major, minor, patch = major + 1, 0, 0 | |
| elif bump_type == "minor": | |
| minor, patch = minor + 1, 0 | |
| else: | |
| patch += 1 | |
| new_version = f"{major}.{minor}.{patch}" | |
| content = re.sub( | |
| r'^(version\s*=\s*")(\d+\.\d+\.\d+)(")', | |
| rf"\g<1>{new_version}\g<3>", | |
| content, | |
| count=1, | |
| flags=re.MULTILINE, | |
| ) | |
| with open("pyproject.toml", "w") as f: | |
| f.write(content) | |
| with open(os.environ["GITHUB_OUTPUT"], "a") as f: | |
| f.write(f"new_version={new_version}\n") | |
| print(f"Bumped version to {new_version}") | |
| PYEOF | |
| - name: Commit version bump to develop | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add pyproject.toml | |
| git commit -m "ci: bump version to ${{ steps.bump.outputs.new_version }} [skip ci]" | |
| git push origin develop | |
| - name: Merge develop into main | |
| run: | | |
| git checkout main | |
| git merge --ff-only develop | |
| git push origin main | |
| - name: Create tag | |
| run: | | |
| git tag "v${{ steps.bump.outputs.new_version }}" | |
| git push origin "v${{ steps.bump.outputs.new_version }}" | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: "v${{ steps.bump.outputs.new_version }}" | |
| generate_release_notes: true | |
| - name: Build package | |
| run: poetry build | |
| - name: Publish to PyPI | |
| env: | |
| PYPI_TOKEN: ${{ secrets.PYPI_PUBLISH }} | |
| run: | | |
| poetry config pypi-token.pypi $PYPI_TOKEN | |
| poetry publish |