As part of Chai's standards, we use Continuous Integration and Semi Automated Deployment via GitHub Releases. To enable these to happen, we need to provide our CI server - GitHub Actions with the right environment variables to gain access to our Saucelabs accounts (for cross browser testing), Github account (for automatically posting release notes), and our NPM account (for publishing packages).
We cannot store these in plaintext, because that means anyone who had them could publish whatever they wanted through the chaijs user - for example overwriting the chai
npm package with a virus. As such, we encrypt these tokens in the codebase.
The users in the token-bearers has access to https://github.com/chaijs/token-bearers repository which contains instructions to log into the chaijs
npm account. If you need a token created or regenerated for your repository, you should @mention the token-bearers team, so they may generate some tokens for your repository.
GitHub autoamtically generates GitHub tokens for each Actions build. For npm and saucelabs tokens, we must generate these manually for each package we wish to publish. The process is as follows:
- In a new Incognito Browsing window, visit https://saucelabs.com/beta/team-management, and enter the saucelabs username and password you have. You'll also need to follow any 2FA prompts.
- Scroll to the bottom of the page, where you should see the saucelabs team users - one for each repository
- Add the new repository - by clicking add user.
- Make the
First Name
Chaijs
,Last Name
the name of the repo. The email should bechaijs+{repo}@keithcirkel.co.uk
(where{repo}
is the name of the repo). Make the password the same as the parent account. - With the user generated, click into the user account, click "Edit User Info", and here you should see an "Access Key" section. Click "Show" and copy the token.
- Prepend
SAUCE_ACCESS_KEY=
to the token, you should have something likeSAUCE_ACCESS_KEY=d9167f44-edfc-4eb3-b0d3-310b7e75cb40
on your clipboard. - In the repository folder (on a Mac), run
pbpaste | travis encrypt -r chaijs/{repo}
(where{repo}
is the repo name) - This will output something like the following:
Please add the following to your .travis.yml file: secure: "QEQUy9IvdWbxcMTub3VvH4Ru2sCI3Ze/bWJ2pammucjQ1u1hqfeJf3NAFOlfrbpx52xlIiqgBwm6u2sDRZ69sLYkak/je5GCtE9rLhxoqiS1l6GlRZ9qnBrW7e790ja4aJdjeazULE3F6kgJwcy8E3qLA5eQOt9kdzevSU50AIQ=" Pro Tip: You can add it automatically by running with --add.
- (Pro Pro Tip: Dont use
--add
because it reformats the.travis.yml
and strips comments. No fun.) - Copy the
secure:
bit, and add it to the array ofenv.global
in the.travis.yml
. Make sure to add a comment mentioning that this is the SAUCE_ACCESS_KEY. - You also need to add
SAUCE_USERNAME=chaijs-{repo}
(where{repo}
is the name of the repository). This doesn't need to be encrypted, so you can add it in plaintext to the.travis.yml
. - Submit a PR to the respective repository.
- Visit the Granular Access Tokens page, you may be prompted to sign in as the Chaijs user - Token Bearers have the password and must not share it with anyone. If you're not a member of the Token Bearer's team, ask someone who is.
- (If you cannot access that URL, the way to get there as of writing is opening the menu where the profile image is, navigating to
Access Tokens
, opening theGenerate New Token
menu, and navigating toGranular Access Token
).
- (If you cannot access that URL, the way to get there as of writing is opening the menu where the profile image is, navigating to
- In the field
Token Name
enter the package name, e.g.chai-spies
. - In the field
Description
add "Release token for {}" where{}
should be the package name, e.g.Release token for Chai Spies
- Change the
Expiration
to 365 days - Ignore the
Allowed IP Ranges
section. - In
Packages and Scopes
, enableRead and write
, and selectOnly select packages and scopes
, then in theSelect packages and scopes
dropdown, you'll need to select the name of the package, e.g.chai-spies
- The package won't be available if it has never been published. In that case, you'll need to select
All packages
, use that token to publish, then regenerate a fresh token scoped to the package, and delete the old one. Alternatively you can manually publish the package to register the name.
- Ignore the
Organizations
section - Summary should read:
Provide read and write access to 1 packages and 0 scopes Provide no access to organiizations Expires on {date a year from now}
- Click
Generate Token
- Where it says
Token successfully generated
, the token will be there to copy. It should start withnpm_
and have a bunch of alphanumeric characters after that. - now you need to put it into GitHub's Actions secrets store:
- Visit https://github.com/chaijs/{}/settings/secrets/actions where
{}
is the name of your package, e.g. https://github.com/chaijs/chai-spies/settings/secrets/actions
- (If you cannot access that url, the way to get there as of writing is visiting the repository page for that package, e.g. https://github.com/chaijs/chai-spies, navigating to
Settings
, opening theSecrets and variables
menu, then navigating to theActions
submenu item.
- From here navigate to the
New repository secret
button - In
Name
enterNPM_TOKEN
exactly. - In
Secret
, paste the contents you copied fromToken successfully generated
. - Navigate to the
Add secret
button. - Finished!