From 992056f87d9c2f50a4b0aa31db35d9887d81893c Mon Sep 17 00:00:00 2001 From: Tawanda Kembo Date: Sat, 27 Jul 2024 18:53:26 +0200 Subject: [PATCH] ci: streamline release and publishing process - Combine tag, release, and publish actions into a single workflow - Automate CHANGELOG.md updates with each release - Remove separate release-drafter and python-publish workflows - Ensure PyPI publishing occurs after successful release creation This change improves the automation of our release process, ensuring consistent versioning, documentation, and distribution. --- .github/workflows/python-publish.yml | 27 ---------------- .github/workflows/release-drafter.yml | 17 ---------- .github/workflows/tag-and-release.yml | 45 +++++++++++++++++++++------ 3 files changed, 36 insertions(+), 53 deletions(-) delete mode 100644 .github/workflows/python-publish.yml delete mode 100644 .github/workflows/release-drafter.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml deleted file mode 100644 index 3c41e66..0000000 --- a/.github/workflows/python-publish.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Upload Python Package - -on: - push: - tags: - - 'v*' - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* \ No newline at end of file diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml deleted file mode 100644 index bf9a1bf..0000000 --- a/.github/workflows/release-drafter.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Release Drafter - -on: - push: - branches: - - main - pull_request: - types: [closed] - -jobs: - update_release_draft: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: release-drafter/release-drafter@v5 - with: - config-name: .github/release-drafter.yml \ No newline at end of file diff --git a/.github/workflows/tag-and-release.yml b/.github/workflows/tag-and-release.yml index bfbfd71..05eb170 100644 --- a/.github/workflows/tag-and-release.yml +++ b/.github/workflows/tag-and-release.yml @@ -1,4 +1,4 @@ -name: Tag and Release +name: Tag, Release, and Publish on: push: @@ -12,7 +12,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 # Fetch all history for all tags and branches + fetch-depth: 0 - name: Set up Git run: | @@ -36,18 +36,45 @@ jobs: echo "$NOTES" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT + - name: Update CHANGELOG.md + run: | + echo "# Changelog" > CHANGELOG.md + echo "" >> CHANGELOG.md + echo "## ${{ steps.bump_version.outputs.NEW_VERSION }}" >> CHANGELOG.md + echo "" >> CHANGELOG.md + echo "${{ steps.generate_notes.outputs.RELEASE_NOTES }}" >> CHANGELOG.md + echo "" >> CHANGELOG.md + git add CHANGELOG.md + git commit -m "Update CHANGELOG.md for ${{ steps.bump_version.outputs.NEW_VERSION }}" + git push + - name: Create Release uses: ncipollo/release-action@v1 with: tag: ${{ steps.bump_version.outputs.NEW_VERSION }} name: Release ${{ steps.bump_version.outputs.NEW_VERSION }} - body: | - Changes in this Release: - ${{ steps.generate_notes.outputs.RELEASE_NOTES }} - - For full details, see [CHANGELOG](https://github.com/tawanda-kembo/code-collator/blob/main/CHANGELOG.md). + body: ${{ steps.generate_notes.outputs.RELEASE_NOTES }} draft: false prerelease: false token: ${{ secrets.GITHUB_TOKEN }} - replacesArtifacts: false - bodyFile: "CHANGELOG.md" \ No newline at end of file + + publish-to-pypi: + needs: tag-and-release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file