Skip to content

Commit e33b3e0

Browse files
committed
add publish flow
1 parent 383eb82 commit e33b3e0

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

publish.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
me: Publish
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
ci:
9+
name: Run CI checks
10+
uses: ./.github/workflows/ci.yml
11+
secrets:
12+
NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}
13+
14+
publish:
15+
name: Publish
16+
runs-on: ubuntu-latest
17+
needs: ci
18+
if: github.ref == 'refs/heads/main' && github.repository == 'ngrok/ngrok-javascript'
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Setup node
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 18
26+
cache: yarn
27+
28+
- name: Install dependencies
29+
run: yarn install
30+
31+
- name: Download all artifacts
32+
uses: actions/download-artifact@v4
33+
with:
34+
path: artifacts
35+
36+
- name: Move artifacts
37+
run: yarn artifacts
38+
39+
- name: List packages
40+
run: ls -R ./npm
41+
shell: bash
42+
43+
- name: Publish
44+
run: |
45+
# extract version from Cargo.toml
46+
version=$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
47+
echo "Package version: $version"
48+
npm publish --access public
49+
# check version variable and publish accordingly
50+
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
51+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
52+
npm publish --access public
53+
elif [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
54+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
55+
npm publish --tag next --access public
56+
else
57+
echo "Not a release, skipping publish"
58+
fi
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
62+
63+
- name: Tag Release
64+
run: |
65+
git config user.name "GitHub Action"
66+
git config user.email [email protected]
67+
version=$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
68+
tag="v$version"
69+
echo "Tagging release: $tag"
70+
echo "Fetching all tags in the repository"
71+
git fetch --tags
72+
if git rev-parse "$tag" > /dev/null 2>&1; then
73+
echo "Tag $tag already exists, skipping tag creation."
74+
else
75+
echo "Tag $tag does not exist, pushing tag."
76+
git tag -a -m "Version ${version}" $tag
77+
git push --tags
78+
fi

0 commit comments

Comments
 (0)