From 76a267e2c51023088ef0821b86c7935da3385319 Mon Sep 17 00:00:00 2001 From: binmax <501711499@qq.com> Date: Fri, 10 Jan 2025 17:08:17 +0800 Subject: [PATCH] add publish action file --- .github/workflows/publish.yml | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..d09fae9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,45 @@ +name: Publish npm package + +on: + push: + branches: + - main + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '14' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: pnpm i + + - name: Run tests + run: pnpm test + + - name: Check if version changed + id: version_check + run: | + git fetch origin main + PREVIOUS_VERSION=$(git show origin/main:package.json | jq -r .version) + CURRENT_VERSION=$(jq -r .version package.json) + echo "previous_version=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT + echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + if [ "$PREVIOUS_VERSION" == "$CURRENT_VERSION" ]; then + echo "Version has not changed. Exiting." + exit 0 + fi + + - name: Publish to npm + if: ${{ steps.version_check.outputs.current_version != steps.version_check.outputs.previous_version }} + run: pnpm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}