-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (43 loc) · 1.39 KB
/
Copy pathversion-check.yml
File metadata and controls
55 lines (43 loc) · 1.39 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
name: Version Check
on:
push:
branches:
- master
- "develop/*"
permissions:
contents: read
jobs:
version-check:
name: Version Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
cache: npm
- name: Check package version availability
shell: bash
run: |
set -euo pipefail
package_name="$(node -p "require('./package.json').name")"
package_version="$(node -p "require('./package.json').version")"
package_spec="${package_name}@${package_version}"
echo "Checking npm registry for ${package_spec}"
set +e
npm_output="$(npm view "${package_spec}" version --registry=https://registry.npmjs.org 2>&1)"
npm_status=$?
set -e
if [ "${npm_status}" -eq 0 ]; then
echo "::error::${package_spec} already exists in the npm registry."
exit 1
fi
if echo "${npm_output}" | grep -Eiq "(E404|404 Not Found|not found)"; then
echo "${package_spec} is available for publishing."
exit 0
fi
echo "${npm_output}"
echo "::error::Unable to determine whether ${package_spec} exists in the npm registry."
exit "${npm_status}"