Skip to content

Commit

Permalink
feat: Add Support for a separate Github release token to the auto-upd…
Browse files Browse the repository at this point in the history
…ate token (#8173)

* [Add] Support for a separate Github release token to the auto-update token

Reference: #5688 - Discussion about keeping two separate tokens; one for publishing to Github releases and the other used by the app to make requests for auto-update updates.

Now you can set a release token that has write permissions to publish your release.

The release token will be used instead of a GH_TOKEN || GITHUB_TOKEN ONLY during publishing.

The Github token defined via the Github options or environment variable will still be used as normal.

mac: ``` export GITHUB_RELEASE_TOKEN=<my token> ```

I used the Contents permission for a New fine-grained personal access token with "Read and write". "Read-only" for the usual app-update token.

So even if the app-update token is inside your app-update.yml its only read-only, yay! (Mac: you can find the app-update.yml by right-click > Show Package Contents > Contents > Resources)
  • Loading branch information
AndrewEQ committed Apr 20, 2024
1 parent fa6fc16 commit 3ae3589
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-pumpkins-suffer.md
@@ -0,0 +1,5 @@
---
"electron-publish": minor
---

feat: Support for a separate Github publish token to the auto-update token
6 changes: 6 additions & 0 deletions docs/configuration/publish.md
Expand Up @@ -9,6 +9,12 @@ If `GH_TOKEN` or `GITHUB_TOKEN` is defined — defaults to `[{provider: "github"

If `KEYGEN_TOKEN` is defined and `GH_TOKEN` or `GITHUB_TOKEN` is not — defaults to `[{provider: "keygen"}]`.

If `GITHUB_RELEASE_TOKEN` is defined, it will be used instead of (`GH_TOKEN` or `GITHUB_TOKEN`) to publish your release.
- e.g. mac: ``` export GITHUB_RELEASE_TOKEN=<my token> ```
- the `GITHUB_TOKEN` will still be used when your app checks for updates, etc.
- you could make your `GITHUB_TOKEN` "Read-only" when creating a fine-grained personal access token, and "Read and write" for the `GITHUB_RELEASE_TOKEN`.
- "Contents" fine-grained permission was sufficient. (at time of writing - Apr 2024)

!!! info "Snap store"
`snap` target by default publishes to snap store (the app store for Linux). To force publishing to another providers, explicitly specify publish configuration for `snap`.

Expand Down
4 changes: 2 additions & 2 deletions packages/electron-publish/src/gitHubPublisher.ts
Expand Up @@ -46,8 +46,8 @@ export class GitHubPublisher extends HttpPublisher {
super(context, true)

let token = info.token
if (isEmptyOrSpaces(token)) {
token = process.env.GH_TOKEN || process.env.GITHUB_TOKEN
if (isEmptyOrSpaces(token) || process.env.GITHUB_RELEASE_TOKEN) {
token = process.env.GITHUB_RELEASE_TOKEN ? process.env.GITHUB_RELEASE_TOKEN : (process.env.GH_TOKEN || process.env.GITHUB_TOKEN)

Check warning on line 50 in packages/electron-publish/src/gitHubPublisher.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Replace `(process.env.GH_TOKEN·||·process.env.GITHUB_TOKEN)` with `process.env.GH_TOKEN·||·process.env.GITHUB_TOKEN`

Check warning on line 50 in packages/electron-publish/src/gitHubPublisher.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Replace `(process.env.GH_TOKEN·||·process.env.GITHUB_TOKEN)` with `process.env.GH_TOKEN·||·process.env.GITHUB_TOKEN`
if (isEmptyOrSpaces(token)) {
throw new InvalidConfigurationError(`GitHub Personal Access Token is not set, neither programmatically, nor using env "GH_TOKEN"`)
}
Expand Down

0 comments on commit 3ae3589

Please sign in to comment.