From 9c1d5311821db8257c15c84da6f76aae5af56c64 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Tue, 23 Feb 2021 10:59:56 -0800 Subject: [PATCH 1/2] improve GitHub actions docs + remove unnecessary warning --- .../docs/build-platforms/github-actions.mdx | 20 ++++++++++++++++--- plugins/npm/src/index.ts | 5 ++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/pages/docs/build-platforms/github-actions.mdx b/docs/pages/docs/build-platforms/github-actions.mdx index 004ce670d..ee6da259b 100644 --- a/docs/pages/docs/build-platforms/github-actions.mdx +++ b/docs/pages/docs/build-platforms/github-actions.mdx @@ -51,7 +51,20 @@ jobs: ### NPM: Github Package Registry -If you are publishing to the Github Package Registry you will need to change the `NPM_TOKEN` token secret to match the following: +If you are publishing to the Github Package Registry you will need to change a few things. + +1. Modify the node action to use the Github Package Registry and your user scope. + +```yml +- name: Use Node.js 12.x + uses: actions/setup-node@v1 + with: + node-version: 12.x + registry-url: "https://npm.pkg.github.com" + scope: "@your-username-scope" +``` + +2. Use the `GITHUB_TOKEN` as the `NODE_AUTH_TOKEN` to publish to the Github Package Registry. ```yml - name: Create Release @@ -64,7 +77,6 @@ If you are publishing to the Github Package Registry you will need to change the npx auto shipit ``` -This will use your `GITHUB_TOKEN` to publish to the Github Package Registry. The `NODE_AUTH_TOKEN` variable is required the `.npmrc` that `actions/setup-node@v1` sets up. If you aren't using `actions/setup-node@v1` replace the variable name `NODE_AUTH_TOKEN` with `NPM_TOKEN` and the `.npmrc` `auto` will handle authentication instead. @@ -78,12 +90,14 @@ If you are having problems make sure you have done the following: ### Running With Branch Protection GitHub actions require a little more setup to use `auto` with branch protection. +We can't use the `GITHUB_TOKEN` to commit to the branch because it does not have high enough permissions. +You will need to create a token with admin access to your repo and modify your build config like the following: ```yml steps: - uses: actions/checkout@v2 with: - # Ensure that git uses your token with write access to the repo + # Ensure that git uses your token with admin access to the repo token: ${{ secrets.GH_TOKEN }} - name: Prepare repository diff --git a/plugins/npm/src/index.ts b/plugins/npm/src/index.ts index f42aa66e3..f9cbb0a86 100644 --- a/plugins/npm/src/index.ts +++ b/plugins/npm/src/index.ts @@ -707,7 +707,10 @@ export default class NPMPlugin implements IPlugin { return; } - auto.checkEnv(this.name, "NPM_TOKEN"); + // gh-action + node action uses NODE_AUTH_TOKEN and we should warn about NPM_TOKEN + if (!process.env.NODE_AUTH_TOKEN) { + auto.checkEnv(this.name, "NPM_TOKEN"); + } }); auto.hooks.getAuthor.tapPromise(this.name, async () => { From 3da6de55ba23dba03fb7306b9f22199e6605ff07 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Wed, 24 Feb 2021 08:50:12 -0800 Subject: [PATCH 2/2] code review --- docs/pages/docs/build-platforms/github-actions.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pages/docs/build-platforms/github-actions.mdx b/docs/pages/docs/build-platforms/github-actions.mdx index ee6da259b..ea9a22c5d 100644 --- a/docs/pages/docs/build-platforms/github-actions.mdx +++ b/docs/pages/docs/build-platforms/github-actions.mdx @@ -77,7 +77,7 @@ If you are publishing to the Github Package Registry you will need to change a f npx auto shipit ``` -The `NODE_AUTH_TOKEN` variable is required the `.npmrc` that `actions/setup-node@v1` sets up. +The `NODE_AUTH_TOKEN` variable is required for the `.npmrc` that `actions/setup-node@v1` sets up. If you aren't using `actions/setup-node@v1` replace the variable name `NODE_AUTH_TOKEN` with `NPM_TOKEN` and the `.npmrc` `auto` will handle authentication instead. ## Troubleshooting @@ -98,7 +98,7 @@ steps: - uses: actions/checkout@v2 with: # Ensure that git uses your token with admin access to the repo - token: ${{ secrets.GH_TOKEN }} + token: ${{ secrets.ADMIN_TOKEN }} - name: Prepare repository # Fetch full git history and tags