diff --git a/.github/actions/publish_nodejs/action.yml b/.github/actions/publish_nodejs/action.yml new file mode 100644 index 000000000..bd9570856 --- /dev/null +++ b/.github/actions/publish_nodejs/action.yml @@ -0,0 +1,96 @@ +name: publish nodejs package +description: publish nodejs package +inputs: + token: + description: The NPM access token to use when publishing + required: true + access: + description: > + Determines whether the published package should be publicly visible, + or restricted to members of your NPM organization. + required: false + dry-run: + description: Run npm with the --dry-run flag to avoid actually publishing anything. + required: false + on_finished: + description: Run a bash on finished. + required: false + on_publish_failed: + description: Run a bash on publish failed. + required: false +outputs: + failed: + description: "Random number" + value: ${{ steps.nodejs.outputs.id == 'undefined' || steps.output_failure.outputs.failed == 'true' }} + +runs: + using: 'composite' + steps: + - + uses: JS-DevTools/npm-publish@v3 + id: nodejs + with: + package: assets/MAA-nodejs-package/maa-node + token: ${{ inputs.token }} + access: ${{ inputs.access }} + dry-run: ${{ inputs.dry-run }} + - + uses: JS-DevTools/npm-publish@v3 + with: + package: assets/MAA-nodejs-package/maa-node-win32-x64 + token: ${{ inputs.token }} + access: ${{ inputs.access }} + dry-run: ${{ inputs.dry-run }} + - + uses: JS-DevTools/npm-publish@v3 + with: + package: assets/MAA-nodejs-package/maa-node-win32-arm64 + token: ${{ inputs.token }} + access: ${{ inputs.access }} + dry-run: ${{ inputs.dry-run }} + - + uses: JS-DevTools/npm-publish@v3 + with: + package: assets/MAA-nodejs-package/maa-node-linux-x64 + token: ${{ inputs.token }} + access: ${{ inputs.access }} + dry-run: ${{ inputs.dry-run }} + - + uses: JS-DevTools/npm-publish@v3 + with: + package: assets/MAA-nodejs-package/maa-node-linux-arm64 + token: ${{ inputs.token }} + access: ${{ inputs.access }} + dry-run: ${{ inputs.dry-run }} + - + uses: JS-DevTools/npm-publish@v3 + with: + package: assets/MAA-nodejs-package/maa-node-darwin-x64 + token: ${{ inputs.token }} + access: ${{ inputs.access }} + dry-run: ${{ inputs.dry-run }} + - + uses: JS-DevTools/npm-publish@v3 + with: + package: assets/MAA-nodejs-package/maa-node-darwin-arm64 + token: ${{ inputs.token }} + access: ${{ inputs.access }} + dry-run: ${{ inputs.dry-run }} + - + name: Remove NodeJS Release + if: always() + shell: bash + run: | + eval $ON_FINISHED || echo "::warning::Failed to eval $ON_FINISHED" + env: + ON_FINISHED: ${{ inputs.on_finished }} + - + name: Output Failure + id: output_failure + if: failure() || steps.nodejs.outputs.id == 'undefined' + shell: bash + run: | + eval $ON_PUBLISH_FAILED || echo "::warning::Failed to eval $ON_PUBLISH_FAILED" + echo "failed=true" >> $GITHUB_OUTPUT + env: + ON_PUBLISH_FAILED: ${{ inputs.on_publish_failed }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b1449c76..4f1d46671 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -491,52 +491,14 @@ jobs: || eval $OUTPUT_PUBLISH_FAILED rm -r assets/MAA-pip-pkgs - - uses: JS-DevTools/npm-publish@v3 + - uses: MaaXYZ/MaaFramework/.github/actions/publish_nodejs@main id: nodejs with: - package: assets/MAA-nodejs-package/maa-node - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-win32-x64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-win32-arm64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-linux-x64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-linux-arm64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-darwin-x64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-darwin-arm64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - name: Remove NodeJS Release - run: | - rm -r assets/MAA-nodejs-package + access: public + token: ${{ secrets.NPM_TOKEN }} + on_finished: rm -r assets/MAA-nodejs-package + on_publish_failed: ${{ env.OUTPUT_PUBLISH_FAILED }} + continue-on-error: true - run: | cd assets @@ -551,7 +513,7 @@ jobs: prerelease: ${{ needs.meta.outputs.is_pre_release == 'true' }} - name: Create issue if failed to release - if: failure() || steps.nuget.outputs.failed || steps.pip.outputs.failed || steps.nodejs.outputs.id == 'undefined' + if: failure() || steps.nuget.outputs.failed || steps.pip.outputs.failed || steps.nodejs.outputs.failed uses: actions-cool/issues-helper@v3 with: actions: "create-issue" @@ -562,4 +524,4 @@ jobs: ${{ steps.pip.outputs.failed && '- pip @MistEO' || '' }} ${{ steps.nodejs.outputs.id == 'undefined' && '- nodejs @neko-para' || '' }} - cc @MistEO \ No newline at end of file + cc @MistEO diff --git a/.github/workflows/publish_nodejs.yml b/.github/workflows/publish_nodejs.yml index 63b602a34..8f06262bc 100644 --- a/.github/workflows/publish_nodejs.yml +++ b/.github/workflows/publish_nodejs.yml @@ -15,45 +15,7 @@ jobs: name: MAA-nodejs-package path: assets/MAA-nodejs-package - - uses: JS-DevTools/npm-publish@v3 - id: nodejs + - uses: MaaXYZ/MaaFramework/.github/actions/publish_nodejs@main with: - package: assets/MAA-nodejs-package/maa-node - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-win32-x64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-win32-arm64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-linux-x64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-linux-arm64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-darwin-x64 - access: public - token: ${{ secrets.NPM_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - package: assets/MAA-nodejs-package/maa-node-darwin-arm64 - access: public - token: ${{ secrets.NPM_TOKEN }} + access: public + token: ${{ secrets.NPM_TOKEN }}