|
1 | | -name: Check & Release |
| 1 | +name: Create a release |
2 | 2 |
|
3 | 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 |
| 4 | + # Trigger a stable version release via GitHub's UI, with the ability to specify the type of release. |
14 | 5 | workflow_dispatch: |
15 | 6 | inputs: |
16 | 7 | release_type: |
17 | 8 | description: Release type |
18 | 9 | required: true |
19 | 10 | type: choice |
20 | | - default: alpha |
| 11 | + default: auto |
21 | 12 | options: |
22 | | - - alpha |
23 | | - - beta |
24 | | - - final |
| 13 | + - auto |
| 14 | + - custom |
| 15 | + - patch |
| 16 | + - minor |
| 17 | + - major |
| 18 | + custom_version: |
| 19 | + description: The custom version to bump to (only for "custom" type) |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + default: "" |
25 | 23 |
|
26 | 24 | 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 |
| 25 | + release_metadata: |
| 26 | + name: Prepare release metadata |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + version_number: ${{ steps.release_metadata.outputs.version_number }} |
| 30 | + tag_name: ${{ steps.release_metadata.outputs.tag_name }} |
| 31 | + changelog: ${{ steps.release_metadata.outputs.changelog }} |
| 32 | + release_notes: ${{ steps.release_metadata.outputs.release_notes }} |
| 33 | + steps: |
| 34 | + - uses: apify/workflows/git-cliff-release@main |
| 35 | + name: Prepare release metadata |
| 36 | + id: release_metadata |
| 37 | + with: |
| 38 | + release_type: ${{ inputs.release_type }} |
| 39 | + custom_version: ${{ inputs.custom_version }} |
| 40 | + existing_changelog_path: CHANGELOG.md |
| 41 | + |
| 42 | + run_code_checks: |
| 43 | + name: Run code checks |
| 44 | + uses: ./.github/workflows/run_code_checks.yaml |
| 45 | + |
| 46 | + update_changelog: |
| 47 | + name: Update changelog |
| 48 | + needs: [release_metadata, run_code_checks] |
| 49 | + uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@main |
| 50 | + with: |
| 51 | + version_number: ${{ needs.release_metadata.outputs.version_number }} |
| 52 | + changelog: ${{ needs.release_metadata.outputs.changelog }} |
| 53 | + secrets: |
| 54 | + APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} |
| 55 | + |
| 56 | + create_github_release: |
| 57 | + name: Create github release |
| 58 | + needs: [release_metadata, update_changelog] |
| 59 | + runs-on: ubuntu-latest |
| 60 | + env: |
| 61 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + steps: |
| 63 | + - name: Create release |
| 64 | + uses: softprops/action-gh-release@v2 |
| 65 | + with: |
| 66 | + tag_name: ${{ needs.release_metadata.outputs.tag_name }} |
| 67 | + name: ${{ needs.release_metadata.outputs.version_number }} |
| 68 | + target_commitish: ${{ needs.update_changelog.outputs.changelog_commitish }} |
| 69 | + body: ${{ needs.release_metadata.outputs.release_notes }} |
34 | 70 |
|
35 | 71 | publish_to_pypi: |
36 | 72 | name: Publish to PyPI |
37 | | - needs: [lint_and_type_checks, unit_tests] |
| 73 | + needs: [release_metadata, update_changelog] |
38 | 74 | runs-on: ubuntu-latest |
39 | 75 | permissions: |
40 | 76 | contents: write |
41 | | - id-token: write |
| 77 | + id-token: write # Required for OIDC authentication. |
42 | 78 | environment: |
43 | 79 | name: pypi |
44 | | - url: https://pypi.org/p/apify-shared |
45 | | - |
| 80 | + url: https://pypi.org/project/apify-shared |
46 | 81 | steps: |
47 | | - - name: Checkout repository |
48 | | - uses: actions/checkout@v3 |
49 | | - |
50 | | - - name: Set up Python |
51 | | - uses: actions/setup-python@v4 |
| 82 | + - name: Prepare distribution |
| 83 | + uses: apify/workflows/prepare-pypi-distribution@main |
52 | 84 | 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 |
| 85 | + package_name: apify-shared |
| 86 | + is_prerelease: "" |
| 87 | + version_number: ${{ needs.release_metadata.outputs.version_number }} |
| 88 | + ref: ${{ needs.update_changelog.outputs.changelog_commitish }} |
| 89 | + # Publishes the package to PyPI using PyPA official GitHub action with OIDC authentication. |
| 90 | + - name: Publish package to PyPI |
101 | 91 | 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