diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6acd8eecc..48a2db94e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,18 +6,45 @@ name: Publish Python Package to PyPI on: push: - tags: - - '*.*.*' + branches: + - main +permissions: + contents: write jobs: build_and_publish: name: Publish a new version of pypdf runs-on: ubuntu-latest + if: "${{ startsWith(github.event.head_commit.message, 'REL: ') }}" steps: # Ensure it's on PyPI - name: Checkout Repository uses: actions/checkout@v4 + - name: Extract version from commit message + id: extract_version + run: | + VERSION=$(echo "${{ github.event.head_commit.message }}" | grep -oP '(?<=REL: )\d+\.\d+\.\d+') + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Extract tag message from commit message + id: extract_message + run: | + VERSION="${{ steps.extract_version.outputs.version }}" + delimiter="$(openssl rand -hex 8)" + MESSAGE=$(echo "${{ github.event.head_commit.message }}" | sed "0,/REL: $VERSION/s///" ) + echo "message<<${delimiter}" >> $GITHUB_OUTPUT + echo "$MESSAGE" >> $GITHUB_OUTPUT + echo "${delimiter}" >> $GITHUB_OUTPUT + + - name: Create Git Tag + run: | + VERSION="${{ steps.extract_version.outputs.version }}" + MESSAGE="${{ steps.extract_message.outputs.message }}" + git config user.name github-actions + git config user.email github-actions@github.com + git tag "$VERSION" -m "$MESSAGE" + git push origin $VERSION - name: Set up Python uses: actions/setup-python@v5