|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + version_number: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + |
| 10 | +jobs: |
| 11 | + publish_to_pypi: |
| 12 | + name: Publish to PyPI |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + id-token: write # Required for OIDC authentication. |
| 17 | + environment: |
| 18 | + name: pypi |
| 19 | + url: https://pypi.org/project/crawlee |
| 20 | + env: |
| 21 | + PYTHON_VERSION: 3.12 |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Python |
| 28 | + uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: ${{ env.PYTHON_VERSION }} |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + run: | |
| 34 | + pipx install --python ${{ env.PYTHON_VERSION }} poetry |
| 35 | + make install-dev |
| 36 | +
|
| 37 | + # Determines the release type based on the event that triggered the workflow. |
| 38 | + - name: Determine release type |
| 39 | + id: determine-release-type |
| 40 | + run: | |
| 41 | + if [[ ${{ github.event_name }} = release ]]; then |
| 42 | + release_type="final" |
| 43 | + elif [[ ${{ github.event_name }} = push ]]; then |
| 44 | + release_type="beta" |
| 45 | + elif [[ ${{ github.event_name }} = workflow_dispatch ]]; then |
| 46 | + release_type=${{ github.event.inputs.release_type }} |
| 47 | + fi |
| 48 | + echo "release_type=${release_type}" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + # Updates the version number for pre-releases in the project's configuration. |
| 51 | + - name: Set pre-release version |
| 52 | + if: steps.determine-release-type.outputs.release_type != 'final' |
| 53 | + run: python ./scripts/update_version_for_prerelease.py ${{ steps.determine-release-type.outputs.release_type }} |
| 54 | + |
| 55 | + # Builds the package. |
| 56 | + - name: Build package |
| 57 | + run: make build |
| 58 | + |
| 59 | + # Publishes the package to PyPI using PyPA official GitHub action with OIDC authentication. |
| 60 | + - name: Publish package to PyPI |
| 61 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 62 | + |
| 63 | + # If this workflow is not triggered by a GitHub release event, manually create and push a Git tag. |
| 64 | + - name: Create Git tag with the published version |
| 65 | + if: github.event_name != 'release' |
| 66 | + run: | |
| 67 | + GIT_TAG=v$(python ./scripts/print_current_package_version.py) |
| 68 | + echo "Current package version retrieved: ${GIT_TAG}" |
| 69 | +
|
| 70 | + echo "Creating Git tag: ${GIT_TAG}" |
| 71 | + git tag "$GIT_TAG" |
| 72 | + echo "Git tag ${GIT_TAG} created successfully." |
| 73 | +
|
| 74 | + echo "Pushing Git tag ${GIT_TAG} to the remote repository." |
| 75 | + git push origin tag "$GIT_TAG" |
| 76 | + echo "Git tag ${GIT_TAG} pushed successfully." |
| 77 | +
|
| 78 | + # If triggered by a release, upload build artifacts to the associated GitHub release. |
| 79 | + - name: Upload the build artifacts to release |
| 80 | + if: github.event_name == 'release' |
| 81 | + run: | |
| 82 | + echo "Uploading build artifacts to GitHub release: ${{ github.ref_name }}" |
| 83 | + gh release upload ${{ github.ref_name }} dist/* |
| 84 | + echo "Build artifacts uploaded successfully." |
| 85 | +
|
| 86 | + env: |
| 87 | + GH_TOKEN: ${{ github.token }} |
0 commit comments