Skip to content

fix: publish npm main package under scope #4

fix: publish npm main package under scope

fix: publish npm main package under scope #4

Workflow file for this run

name: release
on:
push:
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
name: build ${{ matrix.target }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
runner: macos-14
pkg: darwin-arm64
binary: agent-monitor
- target: x86_64-apple-darwin
runner: macos-15-intel
pkg: darwin-x64
binary: agent-monitor
- target: x86_64-unknown-linux-gnu
runner: ubuntu-22.04
pkg: linux-x64-gnu
binary: agent-monitor
- target: aarch64-unknown-linux-gnu
runner: ubuntu-22.04
pkg: linux-arm64-gnu
binary: agent-monitor
cross: true
- target: x86_64-pc-windows-msvc
runner: windows-2022
pkg: win32-x64
binary: agent-monitor.exe
- target: aarch64-pc-windows-msvc
runner: windows-2022
pkg: win32-arm64
binary: agent-monitor.exe
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: ${{ matrix.cross }}
run: cargo install cross --locked
- name: Build (cargo)
if: ${{ !matrix.cross }}
run: cargo build --release --target ${{ matrix.target }}
- name: Build (cross)
if: ${{ matrix.cross }}
run: cross build --release --target ${{ matrix.target }}
- name: Stage binary
shell: bash
run: |
mkdir -p npm/platforms/${{ matrix.pkg }}/bin
cp "target/${{ matrix.target }}/release/${{ matrix.binary }}" \
"npm/platforms/${{ matrix.pkg }}/bin/${{ matrix.binary }}"
chmod +x "npm/platforms/${{ matrix.pkg }}/bin/${{ matrix.binary }}" || true
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.pkg }}
path: npm/platforms/${{ matrix.pkg }}
publish:
name: publish to npm
needs: build
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
- name: Check npm token
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [ -z "$NODE_AUTH_TOKEN" ]; then
echo "NPM_TOKEN repository secret is required to publish"
exit 1
fi
- uses: actions/download-artifact@v4
with:
path: npm/platforms
- name: Restore executable bits
run: |
chmod +x npm/platforms/darwin-*/bin/agent-monitor
chmod +x npm/platforms/linux-*/bin/agent-monitor
- name: Publish platform packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
for dir in npm/platforms/*/; do
name=$(node -p "require('./${dir}/package.json').name")
version=$(node -p "require('./${dir}/package.json').version")
if npm view "${name}@${version}" version >/dev/null 2>&1; then
echo "Skipping ${name}@${version}; already published"
continue
fi
echo "Publishing $dir"
(cd "$dir" && npm publish --access public)
done
- name: Publish main package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
name=$(node -p "require('./npm/agent-monitor/package.json').name")
version=$(node -p "require('./npm/agent-monitor/package.json').version")
if npm view "${name}@${version}" version >/dev/null 2>&1; then
echo "Skipping ${name}@${version}; already published"
exit 0
fi
(cd npm/agent-monitor && npm publish --access public)