semantic-release-action
semantic-release-action copied to clipboard
npm version fails with MODULE_NOT_FOUND (self-hosted runner)
Describe the bug
I'm using semantic-release
to release new package versions. It worked ~17 days ago just fine.
- This only fails when used in the self-hosted runner on Mac Mini M1. 🔴
- Current runner version: ‘2.295.0’
- I've tried to run the same thing with Github hosted runner - it works ✅
- Reading through the error and
@semantic-release/npm
source code, the command that fails isnpm version
More details:
Error: Error: Command failed with exit code 1: npm version 3.4.4 --userconfig /private/var/folders/18/6_t1mlmj5gnb6d3d100f2hc80000gn/T/67efa56206f83e9d5fea8a1c441bf1eb/.npmrc --no-git-tag-version --allow-same-version
Error: Cannot find module '../lib/cli.js'
Require stack:
- /Users/bildur/Development/Company/runner/externals.2.295.0/node16/bin/npm
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/bildur/Development/Company/runner/externals.2.295.0/node16/bin/npm:2:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/bildur/Development/Company/runner/externals.2.295.0/node16/bin/npm'
]
}
Workflow
name: Publish
on:
workflow_call:
secrets:
NPM_TOKEN:
required: true
GH_PUBLISH_TOKEN:
required: true
jobs:
build:
runs-on: office-machine
outputs:
new_release_published: ${{ steps.semantic_release.outputs.new_release_published }}
new_release_version: ${{ steps.semantic_release.outputs.new_release_version }}
steps:
- uses: actions/checkout@v1
- name: Semantic Release
id: semantic_release
uses: cycjimmy/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GH_PUBLISH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
The action does not verify that runners are available outside of Github. If your self-hosted runner can be used in the previous version, it is recommended to return to the previous version.
I do not know the exact cause of this but I could run npm version from my runner as a 'run' step (also self-hosted) but the action still looked in a similar location as above for the npm cli when being invoked from the semantic-release-action.
I was able to run semantic-release on this same runner by installing it in my app, ie, using 'npx semantic-release' in the github action directly. When doing that, the npm plugin was able to update the package.json.
My solution was to NOT use the npm plugin, and to use the exec plugin to run the npm version command in the context of my workflow at the same prepare step (this requires actions/setup-node@v3 to be ran earlier):
["@semantic-release/exec", {
"prepareCmd": "npm version ${nextRelease.version} --no-git-tag-version --allow-same-version"
}],