Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 14 additions & 95 deletions .github/workflows/_build-wheel-release-upload.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor existing build-wheel-release workflow via reusable workflows

Original file line number Diff line number Diff line change
Expand Up @@ -42,118 +42,37 @@ jobs:
uses: ./.github/workflows/_build-pdffit2-package.yml

update-changelog:
needs: [build-pure-python-package, build-non-pure-python-package]
# The always() function is necessary to ensure that we wait for both build jobs to complete, even if one of them is skipped.
# Without always(), if one of the needed jobs is skipped, the `update-changelog` job will not be executed.
if: "always() && !contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail update-changelog job if building failed
run: |
if [ "${{ needs.build-pure-python-package.result }}" == 'success' ] || [ "${{ needs.build-non-pure-python-package.result }}" == 'success' ]; then
echo "Ready to update CHANGELOG.rst..."
else
echo "Previous build-package job failed; exiting..."
exit 1
fi

- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
token: ${{ secrets.PAT_TOKEN }}

- name: Update CHANGELOG.rst with the latest news
run: |
wget https://raw.githubusercontent.com/scikit-package/release-scripts/v0/.github/workflows/update-changelog.py
python update-changelog.py "${{ github.ref_name }}"
rm update-changelog.py

- name: Commit the changes in CHANGELOG.rst
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: update changelog
branch: main
needs: [build-pure-python-package, build-non-pure-python-package]
uses: ./.github/workflows/_update_changelog.yml
secrets:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}

delete-create-new-tag:
# For a full release, we delete and create a new tag to reflect the latest changes in the CHANGELOG.rst.
# Recall that during the full release, the `main` branch's CHANGELOG.rst has been updated, and we want the
# tag to reflect the latest changes in the CHANGELOG.rst done by the update-changelog above.
# For more discussions, please read https://github.com/scikit-package/release-scripts/pull/120
needs: [update-changelog]
# Always run this job for a full release but fail if the update-changelog job previously failed.
if: "always() && !contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail delete-create-new-tag job if CHANGELOG update failed
run: |
if [ "${{ needs.update-changelog.result }}" == 'success' ]; then
echo "Ready to delete and create new tag containing the latest CHANGELOG.rst update in the main branch..."
else
echo "Previous update-changelog job failed; exiting..."
exit 1
fi
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: main
- name: Delete the tag
run: |
git fetch --tags
git tag -d "${{ github.ref_name }}"
git push origin ":${{ github.ref_name }}"
- name: Create a new tag (Expect commit SHA to match with that of main branch)
run: |
git tag "${{ github.ref_name }}"
git push origin "${{ github.ref_name }}"
needs: [update-changelog]
uses: ./.github/workflows/_delete_create_tag.yml
with:
update_changelog_result: ${{ needs.update-changelog.result }}

github-pre-release:
needs: [build-pure-python-package, build-non-pure-python-package]
if: "always() && contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail github-pre-release job if building job failed
run: |
if [ "${{ needs.build-pure-python-package.result }}" == 'success' ] || [ "${{ needs.build-non-pure-python-package.result }}" == 'success' ]; then
echo "Ready to pre-release on GitHub..."
else
echo "Previous build-package job failed; exiting..."
exit 1
fi

- name: Generate GH release notes for pre-release
uses: softprops/action-gh-release@v2
with:
prerelease: true
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
needs: [build-pure-python-package, build-non-pure-python-package]
uses: ./.github/workflows/_github_pre_release.yml

github-release:
needs: [delete-create-new-tag]
if: "always() && !contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail github-release job if CHANGELOG update failed
run: |
if [ "${{ needs.delete-create-new-tag.result }}" == 'success' ]; then
echo "Ready to release on GitHub..."
else
echo "Previous update-changelog job failed; exiting..."
exit 1
fi
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: main
- name: Generate GH release notes for release
run: |
wget https://raw.githubusercontent.com/scikit-package/release-scripts/v0/.github/workflows/get-latest-changelog.py
python get-latest-changelog.py "${{ github.ref_name }}"
- name: Release
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.txt
token: ${{ secrets.GITHUB_TOKEN }}
needs: [delete-create-new-tag]
uses: ./.github/workflows/_github_release.yml
with:
delete-create-new-tag-result: ${{ needs.delete-create-new-tag.result }}

pypi-publish:
needs: [github-pre-release, github-release]
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/_delete_create_tag.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal reusable workflow for deleting and creating a new tag.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Compile news items into CHANGELOG.rst

on:
workflow_call:
inputs:
update_changelog_result:
description: 'Whether the previous update-changelog job succeeded'
required: true
type: string

jobs:
delete-create-new-tag:
runs-on: ubuntu-latest
steps:
- name: Fail delete-create-new-tag job if CHANGELOG update failed
run: |
if [ "${{ inputs.update_changelog_result }}" == 'success' ]; then
echo "Ready to delete and create new tag containing the latest CHANGELOG.rst update in the main branch..."
else
echo "Previous update-changelog job failed; exiting..."
exit 1
fi
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: main
- name: Delete the tag
run: |
git fetch --tags
git tag -d "${{ github.ref_name }}"
git push origin ":${{ github.ref_name }}"
- name: Create a new tag (Expect commit SHA to match with that of main branch)
run: |
git tag "${{ github.ref_name }}"
git push origin "${{ github.ref_name }}"
15 changes: 15 additions & 0 deletions .github/workflows/_github_pre_release.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal reusable workflow for GH pre-release

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Pre-release on GitHub

on:
workflow_call:

jobs:
github-pre-release:
runs-on: ubuntu-latest
steps:
- name: Generate GH release notes for pre-release
uses: softprops/action-gh-release@v2
with:
prerelease: true
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
35 changes: 35 additions & 0 deletions .github/workflows/_github_release.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal reusable workflow for GH release

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release on GitHub

on:
workflow_call:
inputs:
delete-create-new-tag-result:
description: 'Whether the previous delete-create-new-tag job succeeded'
required: true
type: string

jobs:
github-release:
runs-on: ubuntu-latest
steps:
- name: Fail github-release job if CHANGELOG update failed
run: |
if [ "${{ inputs.delete-create-new-tag-result }}" == 'success' ]; then
echo "Ready to release on GitHub..."
else
echo "Previous update-changelog job failed; exiting..."
exit 1
fi
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: main
- name: Generate GH release notes for release
run: |
wget https://raw.githubusercontent.com/scikit-package/release-scripts/v0/.github/workflows/get-latest-changelog.py
python get-latest-changelog.py "${{ github.ref_name }}"
- name: Release
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.txt
token: ${{ secrets.GITHUB_TOKEN }}
47 changes: 47 additions & 0 deletions .github/workflows/_release-on-github-on-tag-push.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main workflow for releasing on GH based on tag - This is the main feature introduced in this PR

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release on GitHub with tag pushed to remote repository

on:
workflow_call:
inputs:
maintainer_github_username:
description: GitHub username authorized to start GitHub/PyPI release'
required: true
type: string
secrets:
PAT_TOKEN:
description: 'GitHub Personal Access Token'
required: true

jobs:
tag-privilege-check:
uses: ./.github/workflows/_release_tag_privilege_check.yml
with:
maintainer_github_username: ${{ inputs.maintainer_github_username }}

update-changelog:
if: "always() && !contains(github.ref, 'rc')"
needs: [tag-privilege-check]
uses: ./.github/workflows/_update_changelog.yml
secrets:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}

delete-create-new-tag:
# Please see the comments provided in _build-whel-release-upload.yml
if: "always() && !contains(github.ref, 'rc')"
needs: [update-changelog]
uses: ./.github/workflows/_delete_create_tag.yml
with:
update_changelog_result: ${{ needs.update-changelog.result }}

github-pre-release:
if: "always() && contains(github.ref, 'rc')"
needs: [tag-privilege-check]
uses: ./.github/workflows/_github_pre_release.yml


github-release:
if: "always() && !contains(github.ref, 'rc')"
needs: [delete-create-new-tag]
uses: ./.github/workflows/_github_release.yml
with:
delete-create-new-tag-result: ${{ needs.delete-create-new-tag.result }}
30 changes: 30 additions & 0 deletions .github/workflows/_update_changelog.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal reusable workflow for compiling changelog

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Compile news items into CHANGELOG.rst

on:
workflow_call:
secrets:
PAT_TOKEN:
description: 'GitHub Personal Access Token'
required: true

jobs:
update-changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
token: ${{ secrets.PAT_TOKEN }}

- name: Update CHANGELOG.rst with the latest news
run: |
wget https://raw.githubusercontent.com/scikit-package/release-scripts/v0/.github/workflows/update-changelog.py
python update-changelog.py "${{ github.ref_name }}"
rm update-changelog.py

- name: Commit the changes in CHANGELOG.rst
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: update changelog
branch: main
23 changes: 23 additions & 0 deletions news/gh-release-workflow.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Author _release-on-github-on-tag-push.yml to release on GitHub with tag push.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
2 changes: 1 addition & 1 deletion news/update-url.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

**Changed:**

* Modifiy Billingegroup/release-scripts to scikit-package-scripts in URLs as the repository has been migrated.
* Modify Billingegroup/release-scripts to scikit-package-scripts in URLs as the repository has been migrated.

**Deprecated:**

Expand Down
Loading