Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-your-project-with-github-actions-workflows for releases with automated tagging
  • Loading branch information
paulstretenowich committed Nov 5, 2024
1 parent f5673b0 commit 6038786
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 6 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/Tag-and-Release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Tag and Release Workflow

on:
pull_request:
types:
- closed

jobs:
release:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
os: [ubuntu-latest, macos-latest]

# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write

if: startsWith(github.event.pull_request.title, 'Release:')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Git
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
- name: Get tag
id: get_tag
run: |
git branch --show-current
git pull
pdm install --prod --no-lock --no-editable
echo "version=$(pdm show --version)" >> $GITHUB_OUTPUT
- name: Tag the commit
run: |
next_version=${{ steps.get_tag.outputs.version }}
git tag -a "$next_version" -m "Version $next_version"
git push --follow-tags
- name: Create changelog diff
id: changelog_diff
run: |
sed -n '/#### \[2.0.1\]/,/^#### /p' CHANGELOG.md | sed '$d' > release_notes.md
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag.outputs.version }}
release_name: Release ${{ steps.get_tag.outputs.version }}
body_path: ./release_notes.md
draft: false
prerelease: false
- name: Delete release_notes file
run: rm release_notes.md
55 changes: 55 additions & 0 deletions .github/workflows/Update-Version-and-create-Realeases-PR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Update version and create Release's PR Workflow

on:
workflow_dispatch:
inputs:
version:
description: 'Version name'
required: true
default: 'minor'
type: choice
options:
- major
- minor
- patch

jobs:
version:
runs-on: ubuntu-latest

# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Setup Node.js
with:
node-version: 18
- name: Setup Git
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Update the version
id: update_version
run: |
echo ${{ github.event.inputs.version }}" > pt_cli/__version__.py
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
- name: Update Changelog
run: |
npm install -g auto-changelog
auto-changelog -v ${{ steps.update_version.outputs.version }}
- name: Create pull request
id: create_pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: release/${{ steps.update_version.outputs.version }}
title: "Release: Candidate Version ${{ steps.update_version.outputs.version }} Pull Request"
body: "This pull request contains the updated __version__.py file with the new release version"
base: main
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ pt-cli = "pt_cli.cli:main"
allow-direct-references = true

[tool.pdm.version]
# source = "file"
# path = "pt_cli/__version__.py"
source = "scm"
version_format = "pt_cli.version:format_version"
write_to = "pt_cli/__version__.py"
write_template = "__version__ = '{}'"
source = "file"
path = "pt_cli/__version__.py"
# source = "scm"
# version_format = "pt_cli.version:format_version"
# write_to = "pt_cli/__version__.py"
# write_template = "__version__ = '{}'"
# tag_filter = "main/*"
# tag_regex = "^main/.*([0-9].[0-9].[0-9])$"

0 comments on commit 6038786

Please sign in to comment.