-
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (77 loc) · 3.46 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Palex publish workflow
on:
workflow_dispatch:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '21'
registry-url: 'https://registry.npmjs.org/'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Handle Version for Manual Trigger
if: github.event_name == 'workflow_dispatch'
run: |
if ! npm view $(node -p "require('./package.json').name")@$(node -p "require('./package.json').version") version; then
echo "Version does not exist, proceeding with publishing."
else
echo "Version exists, bumping version."
git config --global user.email "git@edm115.eu.org"
git config --global user.name "EDM115"
npm version patch -m "Bump version to %s due to existing version in registry"
git push --follow-tags
fi
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Set NPM Version for Release Trigger
if: github.event_name == 'release'
run: |
RELEASE_VERSION=$(echo ${{ github.event.release.tag_name }} | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+')
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$RELEASE_VERSION" != "" ]; then
if ! npm view $(node -p "require('./package.json').name")@$RELEASE_VERSION version; then
if [ "v$CURRENT_VERSION" != "$RELEASE_VERSION" ]; then
echo "Release version does not exist in registry and differs from package.json, setting it."
npm version $RELEASE_VERSION --no-git-tag-version
git config --global user.email "git@edm115.eu.org"
git config --global user.name "EDM115"
git commit -am "Update version to $RELEASE_VERSION"
git push
else
echo "Release version matches package.json but not in registry, safe to publish."
fi
else
echo "Release version exists in registry, bumping version."
npm version patch -m "Bump version to %s due to existing version in registry"
git push --follow-tags
fi
else
echo "Release tag does not follow semantic versioning, reverting to manual trigger logic."
# Fallback to manual trigger logic if release tag is not valid
if ! npm view $(node -p "require('./package.json').name")@"v$CURRENT_VERSION" version; then
echo "Current package.json version does not exist in registry, safe to publish."
else
echo "Current package.json version exists in registry, bumping version."
npm version patch -m "Bump version to %s due to existing version in registry"
git push --follow-tags
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to GitHub Packages
run: npm publish --registry https://npm.pkg.github.com/
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}