|
| 1 | +name: Check & Release |
| 2 | + |
| 3 | +on: |
| 4 | + # Push to master will publish a beta version |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + tags-ignore: |
| 9 | + - '**' |
| 10 | + # A release via GitHub releases will publish a stable version |
| 11 | + release: |
| 12 | + types: [published] |
| 13 | + # Workflow dispatch will publish whatever you choose |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + release_type: |
| 17 | + description: 'Release type' |
| 18 | + required: true |
| 19 | + type: choice |
| 20 | + default: 'alpha' |
| 21 | + options: |
| 22 | + - 'alpha' |
| 23 | + - 'beta' |
| 24 | + - 'final' |
| 25 | + |
| 26 | +jobs: |
| 27 | + lint_and_type_checks: |
| 28 | + name: Run lint and type_checks |
| 29 | + uses: ./.github/workflows/lint_and_type_checks.yaml |
| 30 | + |
| 31 | + unit_tests: |
| 32 | + name: Run unit tests |
| 33 | + uses: ./.github/workflows/unit_tests.yaml |
| 34 | + |
| 35 | + publish_to_pypi: |
| 36 | + name: Publish to PyPI |
| 37 | + needs: [lint_and_type_checks, unit_tests] |
| 38 | + runs-on: ubuntu-latest |
| 39 | + permissions: |
| 40 | + contents: write |
| 41 | + id-token: write |
| 42 | + environment: |
| 43 | + name: pypi |
| 44 | + url: https://pypi.org/p/apify-client |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout repository |
| 48 | + uses: actions/checkout@v3 |
| 49 | + |
| 50 | + - name: Set up Python |
| 51 | + uses: actions/setup-python@v4 |
| 52 | + with: |
| 53 | + python-version: 3.8 |
| 54 | + |
| 55 | + - name: Install dependencies |
| 56 | + run: make install-dev |
| 57 | + |
| 58 | + - # Determine if this is a prerelease or latest release |
| 59 | + name: Determine release type |
| 60 | + id: get-release-type |
| 61 | + run: | |
| 62 | + if [ ${{ github.event_name }} = release ]; then |
| 63 | + release_type="final" |
| 64 | + elif [ ${{ github.event_name }} = push ]; then |
| 65 | + release_type="beta" |
| 66 | + elif [ ${{ github.event_name }} = workflow_dispatch ]; then |
| 67 | + release_type=${{ github.event.inputs.release_type }} |
| 68 | + fi |
| 69 | +
|
| 70 | + if [ ${release_type} = final ]; then |
| 71 | + docker_image_tag="latest" |
| 72 | + elif [ ${release_type} = beta ]; then |
| 73 | + docker_image_tag="beta" |
| 74 | + else |
| 75 | + docker_image_tag="" |
| 76 | + fi |
| 77 | +
|
| 78 | + echo "release_type=${release_type}" >> $GITHUB_OUTPUT |
| 79 | + echo "docker_image_tag=${docker_image_tag}" >> $GITHUB_OUTPUT |
| 80 | +
|
| 81 | + - # Check whether the released version is listed in CHANGELOG.md |
| 82 | + name: Check whether the released version is listed in the changelog |
| 83 | + if: steps.get-release-type.outputs.release_type != 'alpha' |
| 84 | + run: make check-changelog-entry |
| 85 | + |
| 86 | + - # Check version consistency and increment pre-release version number for prereleases (must be the last step before build) |
| 87 | + name: Bump pre-release version |
| 88 | + if: steps.get-release-type.outputs.release_type != 'final' |
| 89 | + run: python ./scripts/update_version_for_prerelease.py ${{ steps.get-release-type.outputs.release_type }} |
| 90 | + |
| 91 | + - # Build a source distribution and a python3-only wheel |
| 92 | + name: Build distribution files |
| 93 | + run: make build |
| 94 | + |
| 95 | + - # Check whether the package description will render correctly on PyPI |
| 96 | + name: Check package rendering on PyPI |
| 97 | + run: make twine-check |
| 98 | + |
| 99 | + - # Publish package to PyPI using their official GitHub action |
| 100 | + name: Publish package to PyPI |
| 101 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 102 | + |
| 103 | + - # Tag the current commit with the version tag if this is not made from the release event (releases are tagged with the release process) |
| 104 | + name: Tag Version |
| 105 | + if: github.event_name != 'release' |
| 106 | + run: | |
| 107 | + git_tag=v`python ./scripts/print_current_package_version.py` |
| 108 | + git tag $git_tag |
| 109 | + git push origin $git_tag |
| 110 | +
|
| 111 | + - # Upload the build artifacts to the release |
| 112 | + name: Upload the build artifacts to release |
| 113 | + if: github.event_name == 'release' |
| 114 | + run: gh release upload ${{ github.ref_name }} dist/* |
| 115 | + env: |
| 116 | + GH_TOKEN: ${{ github.token }} |
0 commit comments