Skip to content

create a separate publish workflow #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 5 additions & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ env:
APP_NAME: ngrok
MACOSX_DEPLOYMENT_TARGET: '10.13'
on:
workflow_call:
secrets:
NGROK_AUTHTOKEN:
required: true
push:
branches:
- '**'
Expand Down Expand Up @@ -505,63 +509,4 @@ jobs:
with:
name: bindings-universal-apple-darwin
path: ${{ env.APP_NAME }}.*.node
if-no-files-found: error

publish:
if: github.ref == 'refs/heads/main' && github.repository == 'ngrok/ngrok-javascript'
name: Publish
runs-on: ubuntu-latest
needs:
- udeps
- fmt
- clippy
- build-freebsd
- test-windows-msvc-binding
- test-linux-x64-gnu-binding
- test-linux-x64-musl-binding
- test-linux-aarch64-gnu-binding
- test-linux-aarch64-musl-binding
- test-linux-arm-gnueabihf-binding
- universal-macOS
steps:
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn

- name: Install dependencies
run: yarn install

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Move artifacts
run: yarn artifacts

- name: List packages
run: ls -R ./npm
shell: bash

- name: Publish
run: |
echo "git log:"
git log -1 --pretty=%B
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
npm publish --access public
elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
npm publish --tag next --access public
else
echo "Not a release, skipping publish"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
if-no-files-found: error
81 changes: 81 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Publish

on:
workflow_dispatch:

jobs:
ci:
name: Run CI checks
uses: ./.github/workflows/ci.yml
secrets:
NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}

publish:
name: Publish
runs-on: ubuntu-latest
needs: ci
steps:
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn

- name: Install dependencies
run: yarn install

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Move artifacts
run: yarn artifacts

- name: List packages
run: ls -R ./npm
shell: bash

- name: Publish
run: |
# extract version from Cargo.toml
version=$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
echo "Package version: $version"

# npm auth
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc

# check if version already exists, if not, publish it
if npm view "@ngrok/ngrok@${version}" > /dev/null 2>&1; then
echo "@ngrok/ngrok@${version} already exists on npm. Skipping publish."
elif [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Publishing release version $version"
npm publish --access public
elif [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Publishing version $version with tag 'next'"
npm publish --tag next --access public
else
echo "Not a release, skipping publish"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Tag Release
run: |
git config user.name "GitHub Action"
git config user.email [email protected]
version=$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
tag="v$version"
echo "Tagging release: $tag"
echo "Fetching all tags in the repository"
git fetch --tags
if git rev-parse "$tag" > /dev/null 2>&1; then
echo "Tag $tag already exists, skipping tag creation."
else
echo "Tag $tag does not exist, pushing tag."
git tag -a -m "Version ${version}" $tag
git push --tags
fi
Loading