-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (85 loc) · 3.03 KB
/
deploy-package.yml
File metadata and controls
102 lines (85 loc) · 3.03 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Deploy Package
on:
push:
branches:
- main
paths:
- "packages/msw-dev-tool/**"
- ".github/workflows/deploy-package.yml"
- "package.json"
- "pnpm-lock.yaml"
jobs:
release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Set up pnpm
uses: pnpm/action-setup@v2
with:
version: 9.10.0
- name: Config identity
run: |
git config --global user.email "${{ secrets.ADMIN_EMAIL }}"
git config --global user.name "${{ secrets.ADMIN_NAME }}"
- name: Install dependencies
working-directory: packages/msw-dev-tool
run: pnpm install
- name: Build
working-directory: packages/msw-dev-tool
run: npm run build
- name: Get NPM package version
id: get_version
working-directory: packages/msw-dev-tool
run: |
PACKAGE_NAME="msw-dev-tool"
VERSION=$(npm view $PACKAGE_NAME version)
if [ -z "$VERSION" ]; then
echo "ERROR: Cannot get $PACKAGE_NAME version from npm registry."
exit 1
fi
echo "NPM version: $VERSION"
echo "npm_version=$VERSION" >> $GITHUB_ENV
- name: Compare and Update package.json version
working-directory: packages/msw-dev-tool
run: |
CURRENT_VERSION=$(cat package.json | jq -r '.version')
NPM_VERSION=${{ env.npm_version }}
# Compare version
function version_gt() {
test "$(printf '%s\n' "$1" "$2" | sort -V | head -n 1)" != "$1"
}
if version_gt "$CURRENT_VERSION" "$NPM_VERSION"; then
echo "Local version: ($CURRENT_VERSION) is higher then registry version: ($NPM_VERSION). Maintain local version."
elif [ "$CURRENT_VERSION" != "$NPM_VERSION" ]; then
echo "Registry version: ($NPM_VERSION) is higher then ($CURRENT_VERSION). Update local version."
npm version $NPM_VERSION --no-git-tag-version
else
echo "Versions are the same, no need to update."
fi
- name: Clean working tree
working-directory: packages/msw-dev-tool
run: |
if [ -z "$(git status --porcelain)" ]; then
echo "Working tree is clean. Skipping git add and commit."
else
git add .
git commit -m "fix: clean working tree"
fi
- name: Bump version and create new tag
working-directory: packages/msw-dev-tool
run: |
npm version patch -m "chore(release): bump version to %s"
- name: Create .npmrc file
working-directory: packages/msw-dev-tool
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Publish to npm
working-directory: packages/msw-dev-tool
run: npm publish