Skip to content

unified SBOM

unified SBOM #2

name: Synchronise PR Version (Poetry)
on:
workflow_call:
inputs:
pr-number:
required: true
type: number
trunk-branch:
required: true
type: string
default: main
secrets:
bot-id:
required: true
bot-key:
required: true
concurrency:
group: ${{ github.workflow }}-${{ inputs.pr-number }}
cancel-in-progress: true
jobs:
synchronise-version:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ inputs.pr-number }}
TRUNK_BRANCH: ${{ inputs.trunk-branch }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ inputs.trunk-branch }}
- name: Retrieve PR details
id: pr-details
run: |
VERSION_LABEL=$(gh pr view $PR_NUMBER --json labels --jq '.labels | map(select(.name == "v:major" or .name == "v:minor" or .name == "v:patch")) | sort_by(.name) | .[0].name')
PR_BRANCH=$(gh pr view $PR_NUMBER --json headRefName --jq .headRefName)
echo "Pull request branch: $PR_BRANCH"
echo "Pull Request Version label: $VERSION_LABEL"
echo "pr_branch=$PR_BRANCH" >> $GITHUB_OUTPUT
echo "version_label=$VERSION_LABEL" >> $GITHUB_OUTPUT
- name: Retrieve ${{ inputs.trunk-branch }} branch version
id: trunk-details
run: |
TRUNK_VERSION=$(python - << 'PY'
import tomllib
with open('pyproject.toml', 'rb') as f:
data = tomllib.load(f)
version = (data.get('tool', {}).get('poetry', {}) or {}).get('version') or (data.get('project', {}) or {}).get('version')
if not version:
raise SystemExit('Could not find version in pyproject.toml under [tool.poetry] or [project]')
print(version)
PY
)
echo "Version on `$TRUNK_BRANCH`: $TRUNK_VERSION"
echo "trunk_version=$TRUNK_VERSION" >> $GITHUB_OUTPUT
- name: Checkout PR
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ steps.pr-details.outputs.pr_branch }}
- uses: actions/setup-python@v6
with:
python-version: "3.14"
check-latest: true
- name: Install poetry
run: |
pipx install poetry
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Update version
id: update
if: ${{ steps.pr-details.outputs.version_label }}
env:
TRUNK_VERSION: ${{ steps.trunk-details.outputs.trunk_version }}
VERSION_LABEL: ${{ steps.pr-details.outputs.version_label }}
run: |
get_next_version() {
local base="$1"
local increment_type="$2"
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
local MAJOR=$(echo $base | sed -e "s#$RE#\1#")
local MINOR=$(echo $base | sed -e "s#$RE#\2#")
local PATCH=$(echo $base | sed -e "s#$RE#\3#")
case "$increment_type" in
major)
((MAJOR += 1))
((MINOR = 0))
((PATCH = 0))
;;
minor)
((MINOR += 1))
((PATCH = 0))
;;
patch)
((PATCH += 1))
;;
esac
local NEXT_VERSION="$MAJOR.$MINOR.$PATCH"
echo "$NEXT_VERSION"
}
next_version=$(get_next_version $TRUNK_VERSION ${VERSION_LABEL:2})
current_version=$(python -c 'import tomllib; data = tomllib.load(open("pyproject.toml", "rb")); version = (data.get("tool", {}).get("poetry", {}) or {}).get("version") or (data.get("project", {}) or {}).get("version");\
if not version: raise SystemExit("Could not find version in pyproject.toml under [tool.poetry] or [project]");\
print(version)')

Check failure on line 108 in .github/workflows/synchronise-pr-version-poetry.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/synchronise-pr-version-poetry.yml

Invalid workflow file

You have an error in your yaml syntax on line 108
if [ "$next_version" != "$current_version" ]; then
poetry version $next_version
echo "new_version=$next_version" >> $GITHUB_OUTPUT
else
echo "Version does not need updating"
fi
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.bot-id }}
private-key: ${{ secrets.bot-key }}
- uses: planetscale/ghcommit-action@v0.2.20
with:
commit_message: "Updating version to ${{ steps.update.outputs.new_version }}"
repo: ${{ github.repository }}
branch: ${{ steps.pr-details.outputs.pr_branch }}
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Remove stale
run: |
gh pr edit $PR_NUMBER --remove-label v:stale || true