0.2.1 #7
Workflow file for this run
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: 📦 Package PyPI | |
| on: | |
| release: | |
| types: [published] | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| update-version: | |
| name: Update Version Files | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 📥 Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: ${{ github.event.release.target_commitish }} | |
| fetch-depth: 0 | |
| - name: 🔍 Determine branch | |
| id: get_branch | |
| run: | | |
| TARGET="${{ github.event.release.target_commitish }}" | |
| BRANCH="${TARGET#refs/heads/}" | |
| BRANCH="${BRANCH#refs/tags/}" | |
| if git rev-parse --verify "$BRANCH"^{tag} >/dev/null 2>&1 || [[ "$TARGET" == refs/tags/* ]]; then | |
| git fetch --all --tags | |
| TAG_NAME="${TARGET#refs/tags/}" | |
| BRANCH=$(git branch -r --contains "$TAG_NAME" | grep -E "(main|master|develop)" | head -1 | sed 's|origin/||' | xargs || \ | |
| git branch -r --contains "$TAG_NAME" | head -1 | sed 's|origin/||' | xargs || \ | |
| echo "master") | |
| fi | |
| echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
| echo "Using branch: $BRANCH" | |
| - name: 🔄 Checkout resolved branch | |
| run: | | |
| git checkout ${{ steps.get_branch.outputs.branch }} | |
| git pull origin ${{ steps.get_branch.outputs.branch }} | |
| - name: 🔍 Extract version from tag | |
| id: extract_version | |
| uses: ./.github/actions/extract-version | |
| with: | |
| tag: ${{ github.event.release.tag_name }} | |
| - name: 📝 Update version files | |
| uses: ./.github/actions/update-version | |
| with: | |
| version: ${{ steps.extract_version.outputs.version }} | |
| - name: 💾 Commit and push | |
| uses: ./.github/actions/commit-push | |
| with: | |
| message: "📦 PyPI: Update version to ${{ steps.extract_version.outputs.version }}" | |
| files: "LAST_VERSION pyproject.toml pycodeloop/__init__.py" | |
| branch: ${{ steps.get_branch.outputs.branch }} | |
| test: | |
| name: Run Tests | |
| needs: [update-version] | |
| uses: ./.github/workflows/test.yml | |
| secrets: inherit | |
| code-quality: | |
| name: Code Quality Checks | |
| needs: [update-version] | |
| uses: ./.github/workflows/code-quality.yml | |
| secrets: inherit | |
| deploy: | |
| name: Deploy to ${{ github.event.release.prerelease && 'TestPyPI' || 'PyPI' }} | |
| needs: [update-version, test, code-quality] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 📥 Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: 🔍 Determine branch | |
| id: get_branch_deploy | |
| run: | | |
| TARGET="${{ github.event.release.target_commitish }}" | |
| BRANCH="${TARGET#refs/heads/}" | |
| BRANCH="${BRANCH#refs/tags/}" | |
| if [[ "$TARGET" == refs/tags/* ]] || git rev-parse --verify "$BRANCH"^{tag} >/dev/null 2>&1; then | |
| TAG_NAME="${TARGET#refs/tags/}" | |
| BRANCH=$(git branch -r --contains "$TAG_NAME" | grep -E "(main|master|develop)" | head -1 | sed 's|origin/||' | xargs || \ | |
| git branch -r --contains "$TAG_NAME" | head -1 | sed 's|origin/||' | xargs || \ | |
| echo "master") | |
| fi | |
| echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
| echo "Using branch: $BRANCH" | |
| - name: 🔄 Checkout branch and pull latest | |
| run: | | |
| git checkout ${{ steps.get_branch_deploy.outputs.branch }} | |
| git pull origin ${{ steps.get_branch_deploy.outputs.branch }} | |
| - name: 🔍 Verify version | |
| uses: ./.github/actions/verify-version | |
| with: | |
| expected: ${{ github.event.release.tag_name }} | |
| - name: 📦 Build Package | |
| uses: ./.github/actions/build-package | |
| with: | |
| python-version: "3.10" | |
| - name: 📦 Publish Package to TestPyPI | |
| if: github.event.release.prerelease == true | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| skip-existing: true | |
| verbose: true | |
| - name: 📦 Publish Package to PyPI | |
| if: github.event.release.prerelease == false | |
| uses: pypa/gh-action-pypi-publish@release/v1 |