Skip to content

Commit c929a81

Browse files
committed
Trigger auto-publish of unstable builds
1 parent 2b3716f commit c929a81

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
name: Publish unstable builds to npm
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
# kill in-progress action if another one is triggered
9+
concurrency:
10+
group: publish-unstable
11+
cancel-in-progress: true
12+
13+
jobs:
14+
# don't publish if source code has not changed
15+
paths-filter:
16+
name: Detect files changed
17+
runs-on: ubuntu-latest
18+
outputs:
19+
src-only: "${{ steps.changes.outputs.src-only }}"
20+
steps:
21+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
22+
with:
23+
persist-credentials: false
24+
- uses: dorny/paths-filter/@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
25+
id: changes
26+
with:
27+
filters: |
28+
src:
29+
- 'src/**'
30+
- 'package.json'
31+
- 'tsconfig.json'
32+
- 'index.d.ts'
33+
- 'index.js'
34+
35+
# pause for 30 minutes to avoid publishing more than 2x per hour
36+
debounce:
37+
name: Publish max 2x per hour
38+
if: steps.changes.outputs.src == 'true'
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Debounce 30 minutes
42+
uses: zachary95/github-actions-debounce
43+
with:
44+
wait: 1800
45+
46+
# run tests prior to publish to ensure some stability
47+
test:
48+
name: Run tests
49+
needs: debounce
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
53+
with:
54+
persist-credentials: false
55+
ref: main
56+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
57+
with:
58+
node-version: "22.x"
59+
registry-url: "https://registry.npmjs.org"
60+
- run: npm install -g npm
61+
- run: npm install
62+
- run: npm test
63+
64+
# if tests pass, publish unstable
65+
publish:
66+
name: Publish unstable
67+
needs: test
68+
runs-on: ubuntu-latest
69+
steps:
70+
- name: npm publish
71+
run: |
72+
# set unstable version value
73+
unstable_tag=$(echo "unstable.$(date --utc +%Y%m%d%H%M%S)")
74+
latest=$(npm view @elastic/elasticsearch --json | jq -r '.["dist-tags"].latest')
75+
next=$(yes | npx semver -i minor "$latest")
76+
unstable_version=$(echo "$next-$unstable_tag")
77+
78+
# overwrite package.json with unstable version value
79+
mv package.json package.json.bak
80+
jq --arg v "$unstable_version" ".version = $v" package.json.bak > package.json
81+
rm package.json.bak
82+
83+
# publish to npm
84+
npm publish --provenance --access public --tag "unstable"
85+
env:
86+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)