From cca56b31bcdf71dfdeda474c27e12bfda665ddd1 Mon Sep 17 00:00:00 2001 From: Alexander Bessman Date: Wed, 19 Feb 2025 22:18:25 +0100 Subject: [PATCH] Automate release process --- .github/workflows/{workflow.yml => lint.yml} | 2 +- .github/workflows/publish.yml | 26 +++++++++++++++ .github/workflows/release.yml | 34 ++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) rename .github/workflows/{workflow.yml => lint.yml} (98%) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/workflow.yml b/.github/workflows/lint.yml similarity index 98% rename from .github/workflows/workflow.yml rename to .github/workflows/lint.yml index bd15f5b..3c64fd0 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: pslab-python +name: lint on: - push diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..3cab7df --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,26 @@ +name: Publish + +on: + release: + types: [published] + + +jobs: + pypi-publish: + runs-on: ubuntu-latest + + environment: pypi + + permissions: + id-token: write + + steps: + - uses: actions/checkout@v4 + + - name: build wheel and sdist + run: | + pip install "flit>=3.2.0,<4.0.0" + flit build + + - name: publish + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9bf389b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Draft release + +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + +jobs: + set-body: + runs-on: ubuntu-latest + + steps: + - run: sudo apt install pcregrep + + - uses: actions/checkout@v4 + + - name: Parse changelog + id: parse-changelog + run: | + tag='${{ github.ref_name }}' + re_current_tag="## \[$tag\].*\n\n" # Match, but do not capture, current version tag, then... + re_changes_body='((.|\n)+?)' # capture everything including newlines... + re_previous_tag='## \[[0-9]+.[0-9]+.[0-9]+\]' # until previous version tag. + re_full="${re_current_tag}${re_changes_body}${re_previous_tag}" + echo 'match<> $GITHUB_OUTPUT + # Match multiple lines, output capture group 1. + pcregrep -M -o1 "$re_full" ./CHANGELOG.md >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + + - name: Set release body + uses: softprops/action-gh-release@v2 + with: + draft: true + body: ${{ steps.parse-changelog.outputs.match }}