diff --git a/.github/workflows/workflow-pyproject-release.md b/.github/workflows/workflow-pyproject-release.md new file mode 100644 index 0000000..a31e9e9 --- /dev/null +++ b/.github/workflows/workflow-pyproject-release.md @@ -0,0 +1,20 @@ +# Reusable Workflow for Python Package Release + +## Purpose + +Automate the release process for Python packages, using the version from +`pyproject.toml` to create a GitHub release. + +## Steps + + 1. Checkout the repository code + 2. Parse the version from `pyproject.toml` + 3. Create a new version tag + 4. Push the tag to the repository + 5. Automatically generate release notes and publish a new GitHub release + +## Input + +This workflow automatically uses the repository name and parses the version from +the `pyproject.toml` file. No additional input is required when calling the +workflow. diff --git a/.github/workflows/workflow-pyproject-release.yml b/.github/workflows/workflow-pyproject-release.yml new file mode 100644 index 0000000..2a43037 --- /dev/null +++ b/.github/workflows/workflow-pyproject-release.yml @@ -0,0 +1,41 @@ +name: Create Release + +on: + workflow_call: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure Git for GitHub Actions + run: | + git config --global user.email "actions@github.com" + git config --global user.name "GitHub Action" + + - name: Parse version from pyproject.toml + id: parse_version + run: | + version=$(grep -Po '(?<=^version = ")[^"]*' pyproject.toml) + echo "version=$version" >> $GITHUB_ENV + + - name: Tag the version and push + run: | + git tag -a v${{ env.version }} -m "Release ${{ env.version }}" + git push origin v${{ env.version }} + + - name: Create GitHub Release + uses: ncipollo/release-action@v1 + with: + tag: "v${{ env.version }}" + name: "${{ github.repository }} v${{ env.version }}" + body: "Release version ${{ env.version }} for ${{ github.repository }}." + allowUpdates: true + generateReleaseNotes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}