ci: autogenerate changelog (#330) · EngineerKhan/crawlee-python@9a76ac4 · GitHub
Skip to content

Commit 9a76ac4

Browse files
authored
ci: autogenerate changelog (apify#330)
- closes apify#18
1 parent c533a39 commit 9a76ac4

10 files changed

Lines changed: 285 additions & 164 deletions

‎.github/pull_request_template.md‎

Lines changed: 0 additions & 1 deletion

‎.github/workflows/_publish_to_pypi.yaml‎

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ jobs:
3030
- name: Determine release type
3131
id: determine-release-type
3232
run: |
33-
if [[ ${{ github.event_name }} = release ]]; then
33+
if [[ ${{ github.event_name }} = workflow_dispatch ]]; then
3434
release_type="final"
3535
elif [[ ${{ github.event_name }} = push ]]; then
3636
release_type="beta"
37-
elif [[ ${{ github.event_name }} = workflow_dispatch ]]; then
38-
release_type=${{ github.event.inputs.release_type }}
3937
fi
4038
echo "release_type=${release_type}" >> $GITHUB_OUTPUT
4139
@@ -51,29 +49,3 @@ jobs:
5149
# Publishes the package to PyPI using PyPA official GitHub action with OIDC authentication.
5250
- name: Publish package to PyPI
5351
uses: pypa/gh-action-pypi-publish@release/v1
54-
55-
# If this workflow is not triggered by a GitHub release event, manually create and push a Git tag.
56-
- name: Create Git tag with the published version
57-
if: github.event_name != 'release'
58-
run: |
59-
GIT_TAG=v$(python ./scripts/print_current_package_version.py)
60-
echo "Current package version retrieved: ${GIT_TAG}"
61-
62-
echo "Creating Git tag: ${GIT_TAG}"
63-
git tag "$GIT_TAG"
64-
echo "Git tag ${GIT_TAG} created successfully."
65-
66-
echo "Pushing Git tag ${GIT_TAG} to the remote repository."
67-
git push origin tag "$GIT_TAG"
68-
echo "Git tag ${GIT_TAG} pushed successfully."
69-
70-
# If triggered by a release, upload build artifacts to the associated GitHub release.
71-
- name: Upload the build artifacts to release
72-
if: github.event_name == 'release'
73-
run: |
74-
echo "Uploading build artifacts to GitHub release: ${{ github.ref_name }}"
75-
gh release upload ${{ github.ref_name }} dist/*
76-
echo "Build artifacts uploaded successfully."
77-
78-
env:
79-
GH_TOKEN: ${{ github.token }}
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/action-semantic-pull-request@v5.5.2
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/run_code_checks.yaml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ jobs:
2323
name: Run unit tests
2424
uses: ./.github/workflows/_unit_tests.yaml
2525

26-
check_changelog_entry:
27-
name: Check changelog entry
28-
uses: ./.github/workflows/_check_changelog_entry.yaml
29-
3026
check_version_conflict:
3127
name: Check version conflict
3228
uses: ./.github/workflows/_check_version_conflict.yaml

‎.github/workflows/run_release.yaml‎

Lines changed: 102 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ on:
88
tags-ignore:
99
- "**" # Ignore all tags to prevent duplicate builds when tags are pushed.
1010

11-
# Trigger a stable version release when a GitHub release is published.
12-
release:
13-
types: [published]
14-
15-
# Allows manual workflow runs from GitHub's UI, with the ability to specify the type of release.
11+
# Trigger a stable version release via GitHub's UI, with the ability to specify the type of release.
1612
workflow_dispatch:
1713
inputs:
1814
release_type:
1915
description: Release type
2016
required: true
2117
type: choice
22-
default: alpha
18+
default: auto
2319
options:
24-
- alpha
25-
- beta
26-
- final
20+
- auto
21+
- custom
22+
custom_version:
23+
description: The custom version to bump to (only for "custom" type)
24+
required: false
25+
type: string
26+
default: ''
2727

2828
jobs:
2929
run_code_checks:
@@ -36,20 +36,109 @@ jobs:
3636
name: Check whether to release
3737
if: |
3838
github.event_name == 'workflow_dispatch' ||
39-
github.event_name == 'release' ||
4039
(
4140
github.event_name == 'push' &&
4241
!startsWith(github.event.head_commit.message, 'docs') &&
4342
!startsWith(github.event.head_commit.message, 'chore')
4443
)
4544
runs-on: ubuntu-latest
45+
outputs:
46+
version_number: ${{ steps.version_number.result }}
4647
steps:
47-
- name: Dummy step
48-
run: "true"
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
53+
- name: Locally remove beta tags
54+
run: |
55+
git tag | grep 'b[0-9]' | xargs git tag --delete
56+
57+
- name: Install git-cliff
58+
run: cargo install git-cliff
59+
60+
- name: Determine version number
61+
id: version_number
62+
run: |
63+
if [[ ${{ event.inputs.release_type }} = custom ]]; then
64+
echo result=$(echo ${{ event.inputs.custom_version }} | sed s/^v//) >> $GITHUB_OUTPUT
65+
else
66+
echo result=$(git-cliff --bumped-version | sed s/^v//)
67+
68+
update_changelog:
69+
name: Update changelog
70+
needs: [run_code_checks, should_release]
71+
runs-on: ubuntu-latest
72+
permissions:
73+
contents: write
74+
id-token: write # Required for OIDC authentication.
75+
outputs:
76+
changelog_commitish: ${{ steps.push.commitish }}
77+
steps:
78+
- name: Checkout repository
79+
uses: actions/checkout@v4
80+
with:
81+
fetch-depth: 0
82+
83+
- name: Locally remove beta tags
84+
run: |
85+
git tag | grep 'b[0-9]' | xargs git tag --delete
86+
87+
- name: Install git-cliff
88+
run: cargo install git-cliff
89+
90+
- name: Set up git
91+
run: |
92+
git config --global user.name "Apify Release Bot"
93+
git config --global user.email "noreply@apify.com"
94+
95+
- name: Generate changelog with git-cliff
96+
run: |
97+
if [[ ${{ github.event_name }} = workflow_dispatch ]]; then
98+
git-cliff --tag v${{ needs.should_release.outputs.version }} > CHANGELOG.md
99+
else
100+
git-cliff --with-tag-message v${{ needs.should_release.outputs.version }} > CHANGELOG.md
101+
fi
102+
103+
- name: Commit and push the result
104+
id: push
105+
run: |
106+
git commit -am "chore(release): Update changelog [skip ci]"
107+
git push origin master
108+
echo commitish=$(git rev-parse HEAD) >> $GITHUB_OUTPUT
109+
110+
create_github_release:
111+
name: Create github release
112+
if: github.event_name == 'workflow_dispatch'
113+
needs: [update_changelog]
114+
runs-on: ubuntu-latest
115+
steps:
116+
- name: Checkout
117+
uses: actions/checkout@v4
118+
with:
119+
fetch-depth: 0
120+
121+
- name: Locally remove beta tags
122+
run: |
123+
git tag | grep 'b[0-9]' | xargs git tag --delete
124+
125+
- name: Install git-cliff
126+
run: cargo install git-cliff
127+
128+
- name: Generate release notes with git-cliff
129+
run: git-cliff --tag "v${{ steps.version_number.outputs.result }}" --unreleased --strip all > release_notes.md
130+
131+
- name: Create release
132+
uses: softprops/action-gh-release@v2
133+
with:
134+
tag_name: v${{ needs.should_release.outputs.version }}
135+
name: ${{ needs.should_release.outputs.version }}
136+
target_commitish: ${{ needs.update_changelog.outputs.changelog_commitish }}
137+
body_path: release_notes.md
49138

50139
publish_to_pypi:
51140
name: Publish to PyPI
52-
needs: [run_code_checks, should_release]
141+
needs: [create_github_release]
53142
uses: ./.github/workflows/_publish_to_pypi.yaml
54143

55144
# TODO: add job for publish package to Conda

‎.pre-commit-config.yaml‎

Lines changed: 0 additions & 6 deletions

0 commit comments

Comments
 (0)