Merge pull request #28 from fasteiner/codex/add-oauth-authentication-… #53
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: Create Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - Dev | |
| permissions: | |
| contents: write | |
| jobs: | |
| create-release: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| python_changed: ${{ steps.check-python-changes.outputs.python_changed }} | |
| effective_version: ${{ steps.effective-version.outputs.effective_version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required for GitVersion to work correctly | |
| - name: Install GitVersion | |
| uses: GitTools/actions/gitversion/setup@v0 | |
| with: | |
| versionSpec: '5.x' | |
| - name: Determine Version | |
| id: gitversion | |
| uses: GitTools/actions/gitversion/execute@v0 | |
| - name: Extract Release Notes from Changelog | |
| id: extract-changelog | |
| uses: release-flow/keep-a-changelog-action@v3.0.0 | |
| with: | |
| command: query | |
| version: unreleased | |
| - name: Check for Python file changes | |
| id: check-python-changes | |
| run: | | |
| git fetch origin main | |
| CHANGED_FILES=$(git diff --name-only HEAD^ HEAD) | |
| echo "Changed files: $CHANGED_FILES" | |
| if echo "$CHANGED_FILES" | grep -E '\.py$'; then | |
| echo "python_changed=true" >> $GITHUB_ENV | |
| echo "::set-output name=python_changed::true" | |
| else | |
| echo "python_changed=false" >> $GITHUB_ENV | |
| echo "::set-output name=python_changed::false" | |
| fi | |
| - name: Set Version Bump Type from GitVersion | |
| id: version-bump | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| VERSION_INCREMENT="${{ steps.gitversion.outputs.MajorMinorPatch }}" | |
| TAG="${{ steps.gitversion.outputs.PreReleaseLabel }}" | |
| BUMP_TYPE="patch" | |
| if [[ "${{ env.python_changed }}" == "true" ]]; then | |
| if [[ "$VERSION_INCREMENT" =~ ^[1-9][0-9]*\.0\.0$ ]]; then | |
| BUMP_TYPE="major" | |
| elif [[ "$VERSION_INCREMENT" =~ ^[0-9]+\.[1-9][0-9]*\.0$ ]]; then | |
| BUMP_TYPE="minor" | |
| elif [[ "$VERSION_INCREMENT" =~ ^[0-9]+\.[0-9]+\.[1-9][0-9]*$ ]]; then | |
| BUMP_TYPE="patch" | |
| fi | |
| if [[ -n "$TAG" ]]; then | |
| BUMP_TYPE="pre${BUMP_TYPE}" | |
| fi | |
| else | |
| echo "No Python files changed → forcing patch bump." | |
| fi | |
| echo "Version bump detected: $BUMP_TYPE" | |
| echo "bump_type=$BUMP_TYPE" >> $GITHUB_ENV | |
| - name: Determine Effective Version | |
| id: effective-version | |
| run: | | |
| if [[ "${{ env.python_changed }}" == "true" ]]; then | |
| EFFECTIVE_VERSION="${{ steps.gitversion.outputs.semVer }}" | |
| else | |
| PREV_TAG=$(git describe --tags --abbrev=0) | |
| echo "Previous tag: $PREV_TAG" | |
| MAJOR=$(echo $PREV_TAG | cut -d. -f1) | |
| MINOR=$(echo $PREV_TAG | cut -d. -f2) | |
| PATCH=$(echo $PREV_TAG | cut -d. -f3) | |
| NEW_PATCH=$((PATCH + 1)) | |
| EFFECTIVE_VERSION="$MAJOR.$MINOR.$NEW_PATCH" | |
| echo "Forcing patch bump: $EFFECTIVE_VERSION" | |
| fi | |
| echo "effective_version=$EFFECTIVE_VERSION" >> $GITHUB_ENV | |
| echo "::set-output name=effective_version::$EFFECTIVE_VERSION" | |
| - name: Update CHANGELOG.md | |
| if: github.ref == 'refs/heads/main' | |
| uses: release-flow/keep-a-changelog-action@v3.0.0 | |
| with: | |
| command: bump | |
| version: ${{ env.bump_type }} | |
| - name: Commit Updated CHANGELOG.md | |
| if: github.ref == 'refs/heads/main' | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "Update CHANGELOG for release ${{ steps.effective-version.outputs.effective_version }}" | |
| file_pattern: "CHANGELOG.md" | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.x" | |
| - name: Install Required Python Packages | |
| run: pip install build tomlkit | |
| - name: Update Version in pyproject.toml | |
| run: | | |
| python - <<EOF | |
| import tomlkit | |
| pyproject_file = "pyproject.toml" | |
| with open(pyproject_file, "r", encoding="utf-8") as f: | |
| data = tomlkit.load(f) | |
| data["project"]["version"] = "${{ steps.effective-version.outputs.effective_version }}" | |
| data["tool"]["poetry"]["version"] = "${{ steps.effective-version.outputs.effective_version }}" | |
| with open(pyproject_file, "w", encoding="utf-8") as f: | |
| tomlkit.dump(data, f) | |
| EOF | |
| - name: Commit Updated pyproject.toml | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "Update pyproject.toml for release ${{ steps.effective-version.outputs.effective_version }}" | |
| file_pattern: "pyproject.toml" | |
| - name: Build release distributions | |
| if: env.python_changed == 'true' | |
| run: | | |
| python -m pip install build | |
| python -m build | |
| - name: Create Git Tag | |
| run: | | |
| git tag ${{ steps.effective-version.outputs.effective_version }} | |
| git push origin ${{ steps.effective-version.outputs.effective_version }} | |
| - name: Create GitHub Release | |
| if: env.python_changed == 'true' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ steps.effective-version.outputs.effective_version }} | |
| name: Release v${{ steps.effective-version.outputs.effective_version }} | |
| body: "${{ steps.extract-changelog.outputs.release-notes }}" | |
| draft: false | |
| prerelease: ${{ github.ref == 'refs/heads/Dev' }} | |
| files: | | |
| dist/*.whl | |
| dist/*.tar.gz | |
| - name: Upload distributions | |
| if: env.python_changed == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-dists | |
| path: dist/ | |
| pypi-publish: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - create-release | |
| if: github.ref == 'refs/heads/main' && needs.create-release.outputs.python_changed == 'true' | |
| permissions: | |
| id-token: write | |
| environment: | |
| name: pypi | |
| steps: | |
| - name: Retrieve release distributions | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: release-dists | |
| path: dist/ | |
| - name: Publish release distributions to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist/ |