-
Notifications
You must be signed in to change notification settings - Fork 8
72 lines (62 loc) · 2.01 KB
/
npm-publish.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
name: npm-publish
on:
push:
branches:
- main
paths:
- 'package.json'
jobs:
npm-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- uses: actions/setup-node@v4
with:
node-version: 21
- name: Get version from package.json
id: package_version
run: echo "VERSION=$(jq -r .version package.json)" >> $GITHUB_ENV
- name: Check if the tag exists
id: tag_check
run: |
if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then
echo "EXISTS=true" >> $GITHUB_ENV
else
echo "EXISTS=false" >> $GITHUB_ENV
fi
- name: Install Dependencies
if: env.EXISTS == 'false'
run: |
npm install
- name: 👷 Build again just in case
if: env.EXISTS == 'false'
run: |
rm -rf ./dist
npm run build
- name: Commit the clean build for the tag
if: env.EXISTS == 'false'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
commit_message=$'👷 MRjs Publish - Auto Dist For ${{ env.VERSION }} 👷\n\nChanges at '"${GITHUB_SHA}"
git add .
git commit -m "$commit_message"
- name: Create Git tag
if: env.EXISTS == 'false'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git tag v${{ env.VERSION }}
git push origin v${{ env.VERSION }}
- name: Debug token availability
if: env.EXISTS == 'false'
run: |
echo "Token length: ${#NPM_MJRS_PUBLISH}"
- name: Publish to npm
if: env.EXISTS == 'false'
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_MJRS_PUBLISH }}