Skip to content

Commit 2986f55

Browse files
authored
ci: Update github workflows to match our release process in other Python repositories (#35)
- closes #31
1 parent 6de5a2f commit 2986f55

16 files changed

+274
-461
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Check PR title
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, edited, synchronize]
6+
7+
jobs:
8+
check_pr_title:
9+
name: Check PR title
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: amannn/[email protected]
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/check_version_availability.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/lint_and_type_checks.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/pre_release.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Create a pre-release
2+
3+
on:
4+
# Trigger a beta version release (pre-release) on push to the master branch.
5+
push:
6+
branches:
7+
- master
8+
tags-ignore:
9+
- "**" # Ignore all tags to prevent duplicate builds when tags are pushed.
10+
11+
# Or it can be triggered manually.
12+
workflow_dispatch:
13+
14+
jobs:
15+
release_metadata:
16+
if: "!startsWith(github.event.head_commit.message, 'docs') && !startsWith(github.event.head_commit.message, 'ci') && startsWith(github.repository, 'apify/')"
17+
name: Prepare release metadata
18+
runs-on: ubuntu-latest
19+
outputs:
20+
version_number: ${{ steps.release_metadata.outputs.version_number }}
21+
tag_name: ${{ steps.release_metadata.outputs.tag_name }}
22+
changelog: ${{ steps.release_metadata.outputs.changelog }}
23+
existing_changelog_path: CHANGELOG.md
24+
steps:
25+
- uses: apify/workflows/git-cliff-release@main
26+
id: release_metadata
27+
name: Prepare release metadata
28+
with:
29+
release_type: prerelease
30+
31+
run_code_checks:
32+
name: Run code checks
33+
uses: ./.github/workflows/run_code_checks.yaml
34+
35+
update_changelog:
36+
name: Update changelog
37+
needs: [release_metadata, run_code_checks]
38+
uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@main
39+
with:
40+
version_number: ${{ needs.release_metadata.outputs.version_number }}
41+
changelog: ${{ needs.release_metadata.outputs.changelog }}
42+
secrets:
43+
APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
44+
45+
publish_to_pypi:
46+
name: Publish to PyPI
47+
needs: [release_metadata, update_changelog]
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: write
51+
id-token: write # Required for OIDC authentication.
52+
environment:
53+
name: pypi
54+
url: https://pypi.org/project/apify-shared
55+
steps:
56+
- name: Prepare distribution
57+
uses: apify/workflows/prepare-pypi-distribution@main
58+
with:
59+
package_name: apify-shared
60+
is_prerelease: "yes"
61+
version_number: ${{ needs.release_metadata.outputs.version_number }}
62+
ref: ${{ needs.update_changelog.outputs.changelog_commitish }}
63+
# Publishes the package to PyPI using PyPA official GitHub action with OIDC authentication.
64+
- name: Publish package to PyPI
65+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/release.yaml

Lines changed: 69 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,91 @@
1-
name: Check & Release
1+
name: Create a release
22

33
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.
145
workflow_dispatch:
156
inputs:
167
release_type:
178
description: Release type
189
required: true
1910
type: choice
20-
default: alpha
11+
default: auto
2112
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: ""
2523

2624
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 }}
3470

3571
publish_to_pypi:
3672
name: Publish to PyPI
37-
needs: [lint_and_type_checks, unit_tests]
73+
needs: [release_metadata, update_changelog]
3874
runs-on: ubuntu-latest
3975
permissions:
4076
contents: write
41-
id-token: write
77+
id-token: write # Required for OIDC authentication.
4278
environment:
4379
name: pypi
44-
url: https://pypi.org/p/apify-shared
45-
80+
url: https://pypi.org/project/apify-shared
4681
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
5284
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
10191
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 }}

.github/workflows/run_checks.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Run code checks
2+
3+
on:
4+
# Trigger code checks on opening a new pull request.
5+
pull_request:
6+
7+
jobs:
8+
lint_check:
9+
name: Lint check
10+
uses: apify/workflows/.github/workflows/python_lint_check.yaml@main
11+
12+
type_check:
13+
name: Type check
14+
uses: apify/workflows/.github/workflows/python_type_check.yaml@main
15+
16+
unit_tests:
17+
name: Unit tests
18+
uses: apify/workflows/.github/workflows/python_unit_tests.yaml@main

.github/workflows/unit_tests.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)