electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.42k stars 507 forks source link

publisher-github: Setting the `authToken` in the `forge.config.js` configuration doesn't work #2820

Open guizmaii opened 2 years ago

guizmaii commented 2 years ago

Pre-flight checklist

Electron Forge version

6.0.0-beta.63

Electron version

v18.1.0

Operating system

All

Last known working Electron Forge version

No response

Expected behavior

See "Actual behavior" description

Actual behavior

In my forge.config.js config, following this doc https://js.electronforge.io/publisher/github/interfaces/publishergithubconfig#authtoken, I have:

  publishers: [
    {
      name: '@electron-forge/publisher-github',
      config: {
        repository: {
          owner: 'myaccount',
          name: 'myrepo',
        },
        authToken: process.env.GITHUB_TOKEN,
        draft: process.env.PUBLISHER_GITHUB_DRAFT,
        prerelease: process.env.PUBLISHER_GITHUB_PRERELEASE,
      },
    },
  ],

When I yarn publish in my CI, I have the error:

> Run yarn publish
yarn publish v1.22.1
[1/4] Bumping version...
info Current version: 0.0.1
[2/4] Logging in...
error No token found and can't prompt for login when running with --non-interactive.
info Visit https://yarnpkg.com/en/docs/cli/publish for documentation about this command.
Error: Process completed with exit code 1.

To fix, this issue I had to remove the authToken from the forge.config.js config:

  publishers: [
    {
      name: '@electron-forge/publisher-github',
      config: {
        repository: {
          owner: 'myaccount',
          name: 'myrepo',
        },
        draft: process.env.PUBLISHER_GITHUB_DRAFT,
        prerelease: process.env.PUBLISHER_GITHUB_PRERELEASE,
      },
    },
  ],

and change the command run in CI with:

yarn electron-forge publish --auth-token=${GITHUB_TOKEN}

which finally works as expected:

...
Making for the following targets: deb
- Making for target: deb - On platform: linux - For arch: x64
✔ Making for target: deb - On platform: linux - For arch: x64
- Resolving publish target: @electron-forge/publisher-github
✔ Resolving publish target: @electron-forge/publisher-github
- Searching for target release: 0.0.1
✔ Searching for target release: 0.0.1
- Uploading Artifacts 0/1 to v0.0.1
✔ Uploading Artifacts 1/1 to v0.0.1
Done in 74.63s.

Steps to reproduce

See "Actual behavior" description

Additional information

No response

Mubramaj commented 12 months ago

I think what is happening here is that the Github action is confused and the yarn publish is trying actually to do the publishing of an npm package, that needs a specific token ( not the GITHUB_TOKEN of electron forge )

What I did in my repo is that I replaced the package.json script publish by publish-app :

  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make",
    "publish-app": "electron-forge publish",
    "lint": "eslint --ext .ts,.tsx ."
  },

Of course also updated my github action to run yarn publish-app instead of yarn publish