-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (112 loc) · 4.22 KB
/
publish-state-lib.yml
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Publish Package to npmjs
on:
push:
branches:
- main
paths:
- 'prompt-shared-state/**'
permissions:
contents: write # Required for creating branches/PRs
pull-requests: write # Required for opening pull requests
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '23.x'
registry-url: 'https://registry.npmjs.org'
- name: Enable Corepack
run: corepack enable
- name: Determine version bump from commit message
id: version_bump
run: |
# Grab the latest commit message
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
# Default to patch.
VERSION_TYPE="patch"
# If the commit message contains '[major]' or '[minor]', set accordingly
if [[ "$COMMIT_MESSAGE" == *"[major]"* ]]; then
VERSION_TYPE="major"
elif [[ "$COMMIT_MESSAGE" == *"[minor]"* ]]; then
VERSION_TYPE="minor"
fi
echo "VERSION_TYPE=$VERSION_TYPE" >> "$GITHUB_OUTPUT"
- name: Install dependencies
run: |
cd prompt-shared-state
yarn install
- name: Bump version
run: |
cd prompt-shared-state
VERSION_TYPE="${{ steps.version_bump.outputs.VERSION_TYPE }}"
echo "Bumping version type: $VERSION_TYPE"
case "$VERSION_TYPE" in
major)
yarn version major
;;
minor)
yarn version minor
;;
*)
yarn version patch
;;
esac
- name: Commit version bump and push to new branch
id: commit_bump
run: |
# Configure git
git config user.name "github-actions"
git config user.email "[email protected]"
# Stage and commit changes if package.json or yarn.lock changed
git add prompt-shared-state/package.json prompt-shared-state/yarn.lock
if ! git diff --cached --exit-code; then
# Pull out the newly bumped version
NEW_VERSION=$(node -p "require('./prompt-shared-state/package.json').version")
COMMIT_MSG="chore: bump prompt-shared-state version to $NEW_VERSION [skip ci]"
# Commit
git commit -m "$COMMIT_MSG"
# Create and push version-bump branch
BRANCH_NAME="chore/bump-prompt-shared-state-$NEW_VERSION"
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
else
echo "No version bump commit required."
fi
- name: Create pull request
if: ${{ steps.commit_bump.outputs.branch_name != '' }}
uses: actions/github-script@v6
with:
script: |
const branchName = "${{ steps.commit_bump.outputs.branch_name }}";
const newVersion = "${{ steps.commit_bump.outputs.new_version }}";
const { data: pullRequest } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `chore: bump prompt-shared-state version to ${newVersion}`,
head: branchName,
base: 'main',
body: 'This pull request was automatically opened by the version bump workflow.',
draft: false
});
core.setOutput('pull_request_number', pullRequest.number);
- name: Build the package
if: ${{ steps.commit_bump.outputs.branch_name != '' }}
run: |
cd prompt-shared-state
yarn build
- name: Publish to npm
if: ${{ steps.commit_bump.outputs.branch_name != '' }}
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: |
echo "Publishing package to npm..."
cd prompt-shared-state
yarn npm publish