Repository navigation
67 lines (67 loc) · 2.52 KB
/
Copy pathpublish.yml
File metadata and controls
67 lines (67 loc) · 2.52 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
name: flipdishbytes.api-client-javascript.publish
on:
pull_request:
push:
branches:
- master
permissions:
id-token: write
contents: read
jobs:
build-and-publish:
concurrency:
group: npm-publish-${{ github.ref }}
cancel-in-progress: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: 24
- name: Install dependencies
run: npm install
- name: Build package
run: npm run build
- name: Get current version from npm
id: current_version
run: |
CURRENT_VERSION=$(npm view @flipdish/api-client-javascript version 2>/dev/null)
if [ -z "$CURRENT_VERSION" ] || [ "$CURRENT_VERSION" = "undefined" ]; then
echo "::error::npm view returned no version for @flipdish/api-client-javascript - registry lookup failed or package missing"
exit 1
fi
echo "Current version from npm: $CURRENT_VERSION"
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Calculate new version
id: new_version
run: |
CURRENT_VERSION=${{ steps.current_version.outputs.version }}
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
NEW_VERSION="$major.$minor.$((patch + 1))"
echo "NEW_VERSION: $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Install moreutils
run: |
sudo apt-get install -qy moreutils
- name: Update version in package.json
run: |
jq --arg version "${{ steps.new_version.outputs.version }}" '.version = $version' package.json | sponge package.json
echo "Updated package version to $(node -p "require('./package.json').version")"
- name: Dry run publish to npm
if: github.event_name == 'pull_request'
run: |
# Run npm publish dry-run and capture output
output=$(npm publish --access public --dry-run 2>&1)
echo "$output"
# Check for real npm errors ("npm error" / "npm ERR!"), not error-named files
# (this package legitimately contains files like ValidationErrorResult.js)
if echo "$output" | grep -E "^npm error|^npm ERR!" > /dev/null; then
echo "Dry run failed"
exit 1
fi
shell: bash
- name: Publish to npm
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
npm -v
npm publish --access public