Skip to content

Commit

Permalink
Cleanup release flow (#14)
Browse files Browse the repository at this point in the history
* Update the changelog

* Move from rst to md for CHANGELOG

* Change formatting

* Update release flow

* Fixup create pull request

* No need for auto-commit, create pull request deals with that

* Cleanup the drafting template

* Add bumpversion configuration

* Make workflow manual

* Fixup tokens

* For PERSONAL ONLY: Use testpypi
  • Loading branch information
tsvi committed Jun 21, 2024
1 parent 11f4a7e commit 24779f1
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 114 deletions.
9 changes: 0 additions & 9 deletions .github/release-drafter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,4 @@ version-resolver:
- 'patch'
default: patch
template: |
## Get it
Install it with pip
```bash
pip install hdate==$RESOLVED_VERSION
```
See it on pypi: [https://pypi.org/project/hdate](https://pypi.org/project/hdate/$RESOLVED_VERSION/)
## Changes
$CHANGES
3 changes: 2 additions & 1 deletion .github/workflows/release-draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ on:

jobs:
update_release_draft:
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
with:
# (Optional) specify config name to use, relative to .github/.
config-name: release-drafter.yaml
Expand Down
76 changes: 53 additions & 23 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,73 @@
name: Release

on:
release:
types: [published]
workflow_dispatch:
inputs:
version_bump:
description: 'Version part to bump (major, minor, patch)'
required: true
default: 'patch'

jobs:
publish-release:

if: contains(github.repository_owner.permissions.admins, github.event.sender.login)
runs-on: ubuntu-latest

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

steps:
- uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.RELEASE_KEY }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: pip install bump-my-version

- name: Get version
- name: Fetch Draft Release Notes
id: fetch_release_notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "VERSION=$(/usr/bin/git tag --list | sed 's|.*v\([0-9\.]*\).*|\1|')" >> $GITHUB_ENV
DRAFT_RELEASE=$(gh api repos/${{ github.repository }}/releases -q '[.[] | select(.draft==true)] | first')
DRAFT_NOTES=$(echo $DRAFT_RELEASE | jq -r '.body')
DRAFT_ID=$(echo $DRAFT_RELEASE | jq -r '.id')
echo "::set-output name=notes::$DRAFT_NOTES"
gh api repos/${{ github.repository }}/releases/$DRAFT_ID -X DELETE
- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.tag_name }}
release-notes: ${{ github.event.release.body }}

- name: Bump version
run: bump-my-version bump ${{ github.event.inputs.version_bump }} -v

- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sed 's/^version = ".*"/version = "'"$VERSION"'"/' -i pyproject.toml
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add pyproject.toml
git commit -m "releasing v$VERSION"
git tag -f "v$VERSION"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Push tags
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tags: true
force: true
TAG_NAME=$(bump-my-version show current_version)
gh release create v$TAG_NAME --title "Release v$TAG_NAME" --notes "${{ steps.fetch_release_notes.outputs.notes }}"
- name: Set up PDM
uses: pdm-project/setup-pdm@v4

- name: Build and publish to pypi
run: pdm publish
run: pdm publish -r testpypi
env:
PDM_PUBLISH_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
PDM_PUBLISH_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }}

- name: Upload the wheel to the Github release
run: |
TAG_NAME=$(bump-my-version show current_version)
pdm build
gh release upload -R ${{ github.repository }} v$TAG_NAME dist/*
Loading

0 comments on commit 24779f1

Please sign in to comment.