From 85331d1d530f9359dd287eb0dad494c9a4d40480 Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Thu, 4 Sep 2025 17:31:22 +0300 Subject: [PATCH 1/2] Publishing workflow --- .github/workflows/release.yaml | 72 ++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..41e54ba --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,72 @@ +# Copyright 2025 Canonical Ltd. +# See LICENSE file for licensing details. +name: Publish + +on: + workflow_dispatch: + +jobs: + build: + name: "Build package" + runs-on: ubuntu-latest + outputs: + VERSION: ${{ steps.export.outputs.VERSION }} + steps: + - name: "Checkout" + uses: actions/checkout@v5 + with: + fetch-depth: 0 + - name: "Install uv" + run: sudo snap install astral-uv --classic + - name: "Export package information" + id: export + run: | + VERSION=$(uv version --short) + if [ "$(git tag -l "${VERSION}")" ]; then + echo "Tag ${VERSION} already exists. Please bump the project to a greater version." + exit 1 + fi + echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" + - name: "Build package" + run: uv build + - name: "Store the distribution packages" + uses: actions/upload-artifact@v5 + with: + name: distfiles + path: dist/ + + upload-github: + name: "Publish to GitHub" + needs: [build] + runs-on: ubuntu-latest + steps: + - name: "Checkout" + uses: actions/checkout@v5 + - name: "Download all the dists" + uses: actions/download-artifact@v5 + with: + name: distfiles + path: dist/ + - name: "Create GitHub release" + run: | + git tag "${{ needs.build.outputs.VERSION }}" + git push origin "${{ needs.build.outputs.VERSION }}" + gh release create "${{ needs.build.outputs.VERSION }}" --generate-notes --title "${{ needs.build.outputs.VERSION }}" + gh release upload "${{ needs.build.outputs.VERSION }}" dist/*.{tar.gz,whl} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + upload-pypi: + name: "Publish to PyPI" + needs: [build] + runs-on: ubuntu-latest + steps: + - name: "Download all the dists" + uses: actions/download-artifact@v5 + with: + name: distfiles + path: dist/ + - name: "Publish to PyPI" + uses: pypa/gh-action-pypi-publish@release/v1 + permissions: + id-token: write diff --git a/pyproject.toml b/pyproject.toml index a05686d..6a114fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,8 +3,8 @@ [project] name = "postgresql-charms-single-kernel" -dynamic = ["version"] description = "Shared and reusable code for PostgreSQL-related charms" +version = "0.0.1" readme = "README.md" license = "Apache-2.0" authors = [ From 29fee8346fa5f28ace0543991dfed9c5211f57a6 Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Thu, 4 Sep 2025 17:47:43 +0300 Subject: [PATCH 2/2] Run CI before release --- .github/workflows/release.yaml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 41e54ba..3be3147 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,11 +3,24 @@ name: Publish on: - workflow_dispatch: + push: + branches: + - 16/edge + +concurrency: + # Prevent race conditions (if multiple commits have been pushed since the last release) + group: dpw-release-python-package-${{ github.ref }} + cancel-in-progress: true jobs: + ci-tests: + name: Tests + uses: ./.github/workflows/ci.yaml + secrets: inherit build: name: "Build package" + needs: + - ci-tests runs-on: ubuntu-latest outputs: VERSION: ${{ steps.export.outputs.VERSION }}