-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (123 loc) · 4.32 KB
/
publish-npm-github.yml
File metadata and controls
135 lines (123 loc) · 4.32 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Given some branch e.g. main or rel/**, publishes package(s) to NPM and creates a GitHub release
name: Publish to NPM & Create GitHub Release
on:
workflow_call:
inputs:
branch:
required: false
type: string
description: Branch to checkout (main or rel/**)
default: main
packages:
required: false
type: string
description: |
JSON array of package scopes/names to publish (e.g., '["com.onesignal.unity.core", "com.onesignal.unity.android"]')
If empty, publishes the root package.json
default: "[]"
toolchain:
required: false
type: string
description: Toolchain to use for install & build ("bun" or "vite-plus")
default: bun
secrets:
GH_PUSH_TOKEN:
required: false
description: GitHub token with push permissions for release creation
permissions:
id-token: write # Required for OIDC
contents: write
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ inputs.branch }}
- name: Setup Bun
if: inputs.toolchain == 'bun'
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup Vite+
if: inputs.toolchain == 'vite-plus'
uses: voidzero-dev/setup-vp@v1
with:
cache: true
run-install: true
- name: Install & Build (Bun)
if: inputs.toolchain == 'bun'
run: |
bun install --frozen-lockfile
bun run build
- name: Build (Vite+)
if: inputs.toolchain == 'vite-plus'
run: vp pack
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Get version
id: get_version
run: |
CURRENT_VERSION=$(node -e "console.log(require('./package.json').version)")
PACKAGE_NAME=$(node -e "console.log(require('./package.json').name)")
if git rev-parse "$CURRENT_VERSION" >/dev/null 2>&1; then
echo "Tag $CURRENT_VERSION already exists, nothing to do"
exit 0
else
echo "Tag $CURRENT_VERSION does not exist, proceeding with release creation"
fi
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
- name: Publish
run: |
VERSION='${{ steps.get_version.outputs.version }}'
PACKAGES='${{ inputs.packages }}'
if [ "$PACKAGES" = "[]" ] || [ -z "$PACKAGES" ]; then
# Publish root package
PACKAGE_NAME='${{ steps.get_version.outputs.package_name }}'
if npm view ${PACKAGE_NAME}@${VERSION} > /dev/null 2>&1; then
echo "Version $VERSION already published, skipping publish"
else
if [[ $VERSION =~ alpha ]]; then
npm publish --tag alpha
elif [[ $VERSION =~ beta ]]; then
npm publish --tag beta
else
npm publish
fi
fi
else
# Publish multiple packages
echo "$PACKAGES" | jq -r '.[]' | while read PACKAGE_NAME; do
if npm view ${PACKAGE_NAME}@${VERSION} > /dev/null 2>&1; then
echo "Version $VERSION already published for $PACKAGE_NAME, skipping"
else
echo "Publishing $PACKAGE_NAME@$VERSION"
if [[ $VERSION =~ alpha ]]; then
npm publish $PACKAGE_NAME --tag alpha --access public
elif [[ $VERSION =~ beta ]]; then
npm publish $PACKAGE_NAME --tag beta --access public
else
npm publish $PACKAGE_NAME --access public
fi
fi
done
fi
create_github_release:
name: Create GitHub Release
needs: publish
if: needs.publish.outputs.version != ''
uses: ./.github/workflows/github-release.yml
secrets:
GH_PUSH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}
with:
version: ${{ needs.publish.outputs.version }}