Skip to content

Commit d724aed

Browse files
authored
Merge pull request #3 from jamdotdev/rui/chore/release-workflow
chore: introduces publish workflow on comment
2 parents a11ba97 + c199e7f commit d724aed

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Publish Package
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
# runs on main PRs targeting main
8+
- main
9+
10+
permissions:
11+
contents: write # To push version bump commit and tag
12+
13+
jobs:
14+
publish:
15+
if: github.event.pull_request.merged == true && (contains(github.event.pull_request.labels.*.name, 'release-major') || contains(github.event.pull_request.labels.*.name, 'release-minor') || contains(github.event.pull_request.labels.*.name, 'release-patch'))
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Determine version type from label
19+
id: version-type
20+
run: |
21+
LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}"
22+
if echo "$LABELS" | grep -q '"release-major"'; then
23+
echo "type=major" >> $GITHUB_OUTPUT
24+
elif echo "$LABELS" | grep -q '"release-minor"'; then
25+
echo "type=minor" >> $GITHUB_OUTPUT
26+
elif echo "$LABELS" | grep -q '"release-patch"'; then
27+
echo "type=patch" >> $GITHUB_OUTPUT
28+
else
29+
echo "::error::No valid release label found (release-major, release-minor, release-patch)."
30+
exit 1
31+
fi
32+
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
with:
36+
ref: "main"
37+
fetch-depth: 0
38+
token: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Setup Node
41+
uses: actions/setup-node@v3
42+
with:
43+
node-version: "18.15"
44+
cache: "yarn"
45+
registry-url: "https://registry.npmjs.org"
46+
47+
- name: Install dependencies
48+
run: yarn install --frozen-lockfile --non-interactive
49+
50+
- name: Build
51+
run: yarn build
52+
53+
- name: Configure Git
54+
run: |
55+
git config --local user.email "action@github.com"
56+
git config --local user.name "GitHub Action"
57+
58+
- name: Bump version
59+
id: bump-version
60+
run: |
61+
VERSION_TYPE="${{ steps.version-type.outputs.type }}"
62+
yarn version --"$VERSION_TYPE" --no-git-tag-version
63+
NEW_VERSION=$(node -p "require('./package.json').version")
64+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
65+
git add package.json
66+
git commit -m "chore: bump version to $NEW_VERSION"
67+
git push
68+
69+
- name: Create tag
70+
run: |
71+
NEW_VERSION=${{ steps.bump-version.outputs.new_version }}
72+
git tag v$NEW_VERSION
73+
git push --tags
74+
75+
- name: Create GitHub Release
76+
uses: actions/create-release@v1
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
with:
80+
tag_name: v${{ steps.bump-version.outputs.new_version }}
81+
release_name: v${{ steps.bump-version.outputs.new_version }}
82+
draft: false
83+
prerelease: false
84+
85+
- name: Publish to NPM
86+
run: yarn publish
87+
env:
88+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)