Skip to content

Commit

Permalink
ci(github-actions): add GH workflow for automatic draft release from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
tomassebestik committed Sep 11, 2024
1 parent c10feea commit e74e660
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
# This workflow builds the Python package and stores it as an artifact for testing during development.
# It only triggers when the 'PR Draft-Release' label is applied to a pull request.
# The built package is NOT pushed to PyPI but is instead stored in a draft GitHub release for reviewers to test.
name: Build draft release, store in GitHub repo only

on:
pull_request: {types: [opened, synchronize, reopened, labeled]}
workflow_dispatch:

jobs:
build-draft-release:
runs-on: ubuntu-latest
if: github.event.label.name == 'PR Draft-Release'
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
outputs: # Define the output of the job (the version)
version: ${{ steps.get_version.outputs.version }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |-
python -m pip install --upgrade pip
pip install build wheel # Ensure both sdist and wheel are built
- name: Get version from Git tag
id: get_version # Set an ID so we can reference it in outputs
run: echo "::set-output name=version::$(git describe --tags --abbrev=0 | sed 's/^v//')"

- name: Build package
run: python -m build # This builds both tar.gz and wheel because wheel is installed

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: python-package-${{ matrix.python-version }}
path: dist/*

create-draft-release:
runs-on: ubuntu-latest
needs: build-draft-release # This job runs after all matrix jobs complete

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: dist/

- name: Create package from all artifacts
run: |-
mkdir -p final_package
cp dist/* final_package/
- name: Upload package to GitHub Release
uses: ncipollo/release-action@v1
with:
artifacts: 'final_package/**' # Upload all collected artifacts
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ needs.build-draft-release.outputs.version }}-pr${{ github.event.number }} # Access version from build-draft-release
name: 'Pre-release for PR #${{ github.event.number }} - Version ${{ needs.build-draft-release.outputs.version }}' # Use version for name
body: 'Automated pre-release build for PR #${{ github.event.number }} - Version ${{ needs.build-draft-release.outputs.version }}'
draft: true # Keeps the release as draft until published
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

---

## Unreleased

### ✨ New features

- **changelog**: custom template for release notes (GH action) *(Tomas Sebestik - c10feea)*

---

## v1.0.1 (2024-09-10)

### 🐛 Bug fixes
Expand Down

0 comments on commit e74e660

Please sign in to comment.