Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ on:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
workflow_dispatch:
workflow_call:
inputs:
ref:
required: false
type: string
default: ${{ github.sha }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- uses: actions/setup-python@v5
with:
Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Bump PR Version

on:
pull_request:
types: [labeled]
branches:
- main

jobs:
bump-version:
if: startsWith(github.event.label.name, 'bump:')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Bump version in pyproject.toml
id: bump
env:
BUMP_LABEL: ${{ github.event.label.name }}
run: |
python - <<'EOF'
import os
import re

path = "pyproject.toml"
with open(path) as f:
content = f.read()

match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"$', content, re.MULTILINE)
major, minor, patch = (int(x) for x in match.groups())

bump = os.environ["BUMP_LABEL"].removeprefix("bump:")
if bump == "major":
major, minor, patch = major + 1, 0, 0
elif bump == "minor":
minor, patch = minor + 1, 0
elif bump == "patch":
patch += 1
else:
raise SystemExit(f"Unknown bump label: {bump}")

new_version = f"{major}.{minor}.{patch}"
content = content[:match.start()] + f'version = "{new_version}"' + content[match.end():]

with open(path, "w") as f:
f.write(content)

with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"new_version={new_version}\n")
EOF

- name: Commit and push
env:
NEW_VERSION: ${{ steps.bump.outputs.new_version }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore: bump version to ${NEW_VERSION}"
git push origin "HEAD:${HEAD_REF}"
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release

on:
push:
branches:
- main

jobs:
test:
uses: ./.github/workflows/test.yml

build:
uses: ./.github/workflows/build.yml

publish:
needs: [test, build]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

tag:
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- name: Read version
id: version
run: |
version=$(python -c "import re; print(re.search(r'^version = \"(.+)\"\$', open('pyproject.toml').read(), re.MULTILINE).group(1))")
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Tag release
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "v${VERSION}"
git push origin "v${VERSION}"
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ on:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
workflow_dispatch:
workflow_call:
inputs:
ref:
required: false
type: string
default: ${{ github.sha }}

jobs:
test:
Expand All @@ -16,6 +25,8 @@ jobs:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "0.1.0"
description = "python-can interface plugin for a configurable binary serial CAN protocol"
readme = "README.md"
keywords = ["can", "python-can", "serial", "plugin"]
requires-python = ">=3.8"
requires-python = ">=3.12"
dependencies = [
"python-can>=4.4,<5",
"pyserial>=3.5",
Expand Down
Loading