changesets / action

682 stars 242 forks source link

Unable to publish #395

Closed richw-kai closed 4 weeks ago

richw-kai commented 1 month ago

Hi, Using this github action I have an issue publishing to NPM but no obvious error logs.

The github action logs:

🦋  All files have been updated and committed. You're ready to publish!
/usr/bin/git status --porcelain
/usr/bin/git push origin HEAD:changeset-release/main --force
/home/runner/work/_actions/changesets/action/v1/dist/index.js:1
(()=>{var __webpack_modules__={87351:function(e,t,r){"use strict";
...

And then just prints a minified js file which I am assuming is ther contents of this file /home/runner/work/_actions/changesets/action/v1/dist/index.js

My github action step is setup as:

- name: Create Release Pull Request or Publish to npm
  id: changesets
  uses: changesets/action@v1
  with:
    publish: npm run ci
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

I'm at a bit of a loss where to try and debug this without an error message to work with... I enabled debug logging in github actions but that doesn't show any errors within the action itself.

almahdi404 commented 4 weeks ago

It should be

with:
  publish: npm ci && npm run build && changeset publish
richw-kai commented 4 weeks ago

It should be

with:
  publish: npm ci && npm run build && changeset publish

thanks for the reply, ci is the script I had defined in my package.json. I already install dependencies and handle caches through github a few steps prior. my ci command runs the following:

"ci": "npm run check-format && npm run build && npx changeset publish",

There must have been a minor update to the action itself though as when I ran the same action again the next day, the actual error message was surfaced and I was able to identify the problem was to do with permissions with my github action not being able to create pull requests.

Not sure why the error wasn't originally being surfaced in the github logs but it came through eventually so going to resolve this.

richw-kai commented 4 weeks ago

For reference, the cause here was github permissions being explicitly set in the action yaml, if you put fine grain permissions into your github action, then it explicitly uses that set instead of your repository settings configured in github.

I needed to set the following for my github workflow:

permissions:
  id-token: write
  contents: write

This allows PR's to be created by the workflow as well as allowing the required permissions I need for using ghcr for other parts of the build process.