-
Notifications
You must be signed in to change notification settings - Fork 4
88 lines (74 loc) · 3.08 KB
/
bump-package.yml
File metadata and controls
88 lines (74 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Bump package version
on:
workflow_call:
inputs:
workspace:
required: true
type: string
description: 'Yarn workspace name'
path:
required: true
type: string
description: 'Package directory relative to repo root'
jobs:
bump:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Check if package was modified and version needs bump
id: check
run: |
# Exit cleanly if the package directory was not touched in this PR
if git diff --quiet ${{ github.event.pull_request.base.sha }} HEAD -- ${{ inputs.path }}; then
echo "No changes detected in ${{ inputs.path }}."
echo "should-bump=false" >> $GITHUB_OUTPUT
exit 0
fi
# Compare old (base) and new (HEAD) version strings
OLD_VERSION=$(git show ${{ github.event.pull_request.base.sha }}:${{ inputs.path }}/package.json | jq -r '.version')
NEW_VERSION=$(jq -r '.version' ${{ inputs.path }}/package.json)
if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
echo "Version already bumped by developer ($OLD_VERSION → $NEW_VERSION)."
echo "should-bump=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "should-bump=true" >> $GITHUB_OUTPUT
- name: Determine bump level from conventional commits
id: level
if: steps.check.outputs.should-bump == 'true'
run: |
# Gather full commit messages (subject + body) only for commits touching this package
COMMITS=$(git log ${{ github.event.pull_request.base.sha }}..HEAD --format=%B -- ${{ inputs.path }})
if echo "$COMMITS" | grep -qE '^[a-z]+(\([^)]+\))?!:'; then
LEVEL=major
elif echo "$COMMITS" | grep -qE 'BREAKING[- ]CHANGE'; then
LEVEL=major
elif echo "$COMMITS" | grep -qE '^feat(\([^)]*\))?:'; then
LEVEL=minor
else
LEVEL=patch
fi
echo "level=$LEVEL" >> $GITHUB_OUTPUT
echo "Bumping ${{ inputs.workspace }} with $LEVEL level"
- uses: actions/setup-node@v4
if: steps.check.outputs.should-bump == 'true'
with:
node-version-file: '.nvmrc'
- run: corepack enable
if: steps.check.outputs.should-bump == 'true'
- run: yarn
if: steps.check.outputs.should-bump == 'true'
- name: Bump ${{ inputs.workspace }} version
if: steps.check.outputs.should-bump == 'true'
run: yarn workspace ${{ inputs.workspace }} version ${{ steps.level.outputs.level }}
- uses: EndBug/add-and-commit@v9
if: steps.check.outputs.should-bump == 'true'
with:
author_name: github-actions
author_email: 41898282+github-actions[bot]@users.noreply.github.com
message: 'chore: bump ${{ inputs.workspace }} version'
pull: '--rebase --autostash'