chore: Upgrade Python requirements #1113
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: Release | |
| on: | |
| pull_request: | |
| types: | |
| - closed | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: 'Version to release from (e.g. 2.5.3)' | |
| required: false | |
| default: 'main' | |
| dry_run: | |
| description: 'Skip publishing to PyPI' | |
| required: false | |
| default: true | |
| type: boolean | |
| env: | |
| TUTOR_ROOT: ./.ci/ | |
| jobs: | |
| release: | |
| if: > | |
| github.event_name == 'workflow_dispatch' || | |
| (github.event.pull_request.merged == true && startsWith(github.head_ref, 'bot/v')) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Resolve ref | |
| id: resolve_ref | |
| run: | | |
| REF="${{ inputs.ref || github.ref }}" | |
| if echo "$REF" | grep -Eq '^v?[0-9]+\.[0-9]+\.[0-9]+$'; then | |
| REF="bot/v${REF#v}" | |
| fi | |
| echo "ref=${REF}" >> $GITHUB_OUTPUT | |
| - name: Checkout | |
| uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| with: | |
| ref: ${{ steps.resolve_ref.outputs.ref }} | |
| fetch-depth: 0 | |
| - name: Read version from package | |
| id: read_version | |
| run: | | |
| RAW_V=$(grep -Eo "[0-9]+\.[0-9]+\.[0-9]+" tutoraspects/__about__.py | head -n 1) | |
| echo "raw_version=${RAW_V}" >> $GITHUB_OUTPUT | |
| echo "tag=v${RAW_V}" >> $GITHUB_OUTPUT | |
| - name: Check if version already exists on PyPI | |
| if: github.event_name == 'pull_request' || inputs.dry_run == false | |
| run: | | |
| VERSION="${{ steps.read_version.outputs.raw_version }}" | |
| STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/tutor-contrib-aspects/${VERSION}/json") | |
| if [ "$STATUS" = "200" ]; then | |
| echo "::error::Version ${VERSION} is already published on PyPI. Aborting." | |
| exit 1 | |
| fi | |
| echo "Version ${VERSION} not found on PyPI, proceeding." | |
| - name: Create GitHub tag | |
| if: github.event_name == 'pull_request' || inputs.dry_run == false | |
| run: | | |
| TAG="${{ steps.read_version.outputs.tag }}" | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "Tag $TAG already exists, skipping." | |
| else | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "$TAG" | |
| git push origin "$TAG" | |
| fi | |
| - name: Extract release notes | |
| id: release_notes | |
| run: | | |
| EOF_SECTOR="EOF_${RANDOM}${RANDOM}" | |
| echo "NOTES<<${EOF_SECTOR}" >> $GITHUB_OUTPUT | |
| awk '/^## v/{if(found) exit; found=1; next} found{print}' CHANGELOG.md >> $GITHUB_OUTPUT | |
| echo "${EOF_SECTOR}" >> $GITHUB_OUTPUT | |
| - name: Create GitHub release | |
| if: github.event_name == 'pull_request' || inputs.dry_run == false | |
| uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1.21.0 | |
| with: | |
| tag: ${{ steps.read_version.outputs.tag }} | |
| name: Release ${{ steps.read_version.outputs.tag }} | |
| body: ${{ steps.release_notes.outputs.NOTES }} | |
| skipBodyUpdate: true | |
| makeLatest: ${{ contains(github.event.pull_request.labels.*.name, 'make-latest') || 'false' }} | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: pip install -r requirements/pip.txt | |
| - name: Build package | |
| run: make build-pythonpackage | |
| - name: Validate package | |
| run: | | |
| pip install twine | |
| twine check dist/* | |
| - name: Publish to PyPI | |
| if: > | |
| github.event_name == 'pull_request' || | |
| (github.event_name == 'workflow_dispatch' && inputs.dry_run == false) | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| user: __token__ | |
| password: ${{ secrets.PYPI_UPLOAD_TOKEN }} |