Skip to content

ci: update npm install commands to clean dependencies first #5

ci: update npm install commands to clean dependencies first

ci: update npm install commands to clean dependencies first #5

Workflow file for this run

name: Publish to npm
on:
push:
tags:
- 'v*'
branches:
- main
workflow_dispatch:
inputs:
publish_type:
description: 'Type of publish: official or test'
required: true
default: 'test'
type: choice
options:
- official
- test
test_package_name:
description: 'Optional custom package name for test publish (e.g. @alicloud/agentrun-sdk-test)'
required: false
jobs:
prepare:
name: Build
runs-on: ubuntu-latest
outputs:
built: ${{ steps.build.outputs.built }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Clean and install dependencies
run: |
rm -rf node_modules package-lock.json
npm install
- name: Build
id: build
run: |
npm run build
echo "built=true" >> $GITHUB_OUTPUT
publish-official:
name: Publish Official Package
needs: prepare
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_type == 'official')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
always-auth: true
- name: Clean and install dependencies
run: |
rm -rf node_modules package-lock.json
npm install
- name: Build
run: npm run build
- name: Publish to npm (official)
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "Publishing official package to npm"
npm publish --access public
publish-test:
name: Publish Test Package
needs: prepare
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
if: (github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_type == 'test')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
always-auth: true
- name: Clean and install dependencies
run: |
rm -rf node_modules package-lock.json
npm install
- name: Build
run: npm run build
- name: Publish test package (tag=test)
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
TEST_PKG_NAME: ${{ github.event.inputs.test_package_name }}
run: |
set -e
echo "Publishing test package (tag=test)"
if [ -n "$TEST_PKG_NAME" ]; then
node -e "const fs=require('fs');const p=JSON.parse(fs.readFileSync('package.json'));p.name=process.env.TEST_PKG_NAME;fs.writeFileSync('package.json.tmp',JSON.stringify(p,null,2));fs.copyFileSync('package.json','package.json.bak');fs.copyFileSync('package.json.tmp','package.json');"
npm publish --tag test --access public
mv package.json.bak package.json
rm -f package.json.tmp
else
npm publish --tag test --access public
fi