Skip to content

Commit 97a3021

Browse files
authored
ci: use shared workflows and refactor them (#290)
- Use shared workflows and refactor them (apify/workflows#129). - Use the same setup we had in Crawlee before the automatic changelog - https://github.com/apify/crawlee-python/tree/c533a39c5e9ee80c3a333dd76cf9a4dd26061c95. - Currently, we are missing something here... Also, the transition to the automatic changelogs should be smoother. - Install Poetry to setup-python environment.
1 parent 1f1571d commit 97a3021

15 files changed

+256
-227
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Changelog entry check
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
check_changelog_entry:
8+
name: Changelog entry check
9+
runs-on: ubuntu-latest
10+
if: (!startsWith(github.event.pull_request.title, 'docs:'))
11+
env:
12+
PYTHON_VERSION: 3.12
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ env.PYTHON_VERSION }}
22+
23+
- name: Install dependencies
24+
run: |
25+
pipx install --python ${{ env.PYTHON_VERSION }} poetry
26+
make install-dev
27+
28+
- name: Execute changelog entry check
29+
run: make check-changelog-entry
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 }}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Version conflict check
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
check_version_conflict:
8+
name: Version conflict check
9+
runs-on: ubuntu-latest
10+
if: (!startsWith(github.event.pull_request.title, 'docs:'))
11+
env:
12+
PYTHON_VERSION: 3.12
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ env.PYTHON_VERSION }}
22+
23+
- name: Install dependencies
24+
run: |
25+
pipx install --python ${{ env.PYTHON_VERSION }} poetry
26+
make install-dev
27+
28+
- name: Execute version conflict check
29+
run: make check-version-conflict

.github/workflows/docs.yaml renamed to .github/workflows/build_and_deploy_docs.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@ jobs:
1515
pages: write
1616
id-token: write
1717
runs-on: ubuntu-latest
18+
env:
19+
NODE_VERSION: 20
20+
PYTHON_VERSION: 3.12
1821

1922
steps:
2023
- name: Checkout repository
2124
uses: actions/checkout@v4
2225
with:
2326
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
2427

25-
- name: Set up Node.js
28+
- name: Set up Node
2629
uses: actions/setup-node@v4
2730
with:
28-
node-version: 18
31+
node-version: ${{ env.NODE_VERSION }}
2932
cache: npm
3033
cache-dependency-path: website/package-lock.json
3134

32-
- name: Install Node.js dependencies
35+
- name: Install Node dependencies
3336
run: |
3437
npm install
3538
npm update @apify/docs-theme
@@ -48,11 +51,11 @@ jobs:
4851
- name: Set up Python
4952
uses: actions/setup-python@v5
5053
with:
51-
python-version: 3.9
54+
python-version: ${{ env.PYTHON_VERSION }}
5255

53-
- name: Install dependencies
56+
- name: Install Python dependencies
5457
run: |
55-
pipx install poetry
58+
pipx install --python ${{ matrix.python-version }} poetry
5659
make install-dev
5760
5861
- name: Build generated API reference

.github/workflows/check_version_availability.yaml

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

.github/workflows/integration_tests.yaml

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

.github/workflows/lint_and_type_checks.yaml

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

.github/workflows/run_checks.yaml

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Run code checks
2+
3+
on:
4+
# Trigger code checks on opening a new pull request.
5+
pull_request_target:
6+
7+
# Do not trigger code checks on push to the master branch, as they will be triggered
8+
# by the release workflow.
9+
10+
# Trigger code checks on workflow call (e.g. from run release workflow).
11+
workflow_call:
12+
13+
jobs:
14+
lint_check:
15+
name: Lint check
16+
uses: apify/workflows/.github/workflows/python/lint_check.yaml
17+
18+
type_check:
19+
name: Type check
20+
uses: apify/workflows/.github/workflows/python/type_check.yaml
21+
22+
unit_tests:
23+
name: Unit tests
24+
uses: apify/workflows/.github/workflows/python/unit_tests.yaml
25+
26+
# TODO: remove this once https://github.com/apify/apify-sdk-python/issues/241 is resolved
27+
changelog_entry_check:
28+
name: Changelog entry check
29+
uses: ./.github/workflows/_changelog_entry_check.yaml
30+
31+
# TODO: remove this once https://github.com/apify/apify-sdk-python/issues/241 is resolved
32+
version_conflict_check:
33+
name: Version conflict check
34+
uses: ./.github/workflows/_version_conflict_check.yaml
35+
36+
docs_check:
37+
name: Docs check
38+
uses: apify/workflows/.github/workflows/python/docs_check.yaml
39+
40+
integration_tests:
41+
name: Integration tests
42+
uses: apify/workflows/.github/workflows/python/integration_tests.yaml
43+
secrets: inherit

0 commit comments

Comments
 (0)