20

The official boilerplate code injects the npm token as follows

NODE_AUTH_TOKEN: ${{secrets.npm_token}}

How do I access and set this variable? I cant find it in the GUI.

4 Answers 4

20
  1. Go to your project in Github
  2. Select the Settings tab
  3. Click the Secrets section in the left hand menu
  4. Add a new secret and provide a name (e.g. npm_token) and a value.

How to add a secret

9

In addition to the GUI, you now (January 2020) have a GitHub Actions API(!, still beta though), as announced here.

And it does include a GitHub Actions Secrets API:

Create or update an repository secret:

Creates or updates an organization secret with an encrypted value. Encrypt your secret using LibSodium.

You must authenticate using an access token with the admin:repo scope to use this endpoint.
GitHub Apps must have the secrets organization permission to use this endpoint.

PUT /repos/{owner}/{repo}/actions/secrets/{secret_name}

Get a repository secret

Gets a single secret without revealing its encrypted value.
Anyone with write access to the repository can use this endpoint.
GitHub Apps must have the secrets permission to use this endpoint.

GET /repos/:owner/:repo/actions/secrets/:name

So the GUI is no longer the sole option: you can script and get/set an Actions secret through this new API.

7
  • But the question is "set secrets"
    – maxisme
    Commented Jan 2, 2021 at 17:46
  • 2
    @maxisme I agree. I have edited the answer to include the creation of a secret.
    – VonC
    Commented Jan 2, 2021 at 17:52
  • 1
    Thanks @Vonc I tried to search the documentation but gave up 😩
    – maxisme
    Commented Jan 3, 2021 at 0:07
  • but I think this is only for "organisation" accounts.
    – maxisme
    Commented Jan 3, 2021 at 0:10
  • 1
    @maxisme Good catch, thank you. I have edited the first API endpoint to use the one for repository, instead of organisation.
    – VonC
    Commented Jan 3, 2021 at 0:29
2

This page is hard to find, but it exists in the official docs here: Creating and using secrets (encrypted variables).

Copied from the docs below for convenience:

Secret names cannot include any spaces. To ensure that GitHub redacts your secret in logs, avoid using structured data as the values of secrets, like JSON or encoded Git blobs.

  1. On GitHub, navigate to the main page of the repository.
  2. Under your repository name, click Settings. repository settings button
  3. In the left sidebar, click Secrets.
  4. Type a name for your secret in the "Name" input box.
  5. Type the value for your secret.
  6. Click Add secret.

The link above has a bit more info around using secrets as well.

3
  • Unfortunately, the link doesn't work anymore.
    – Toreno96
    Commented Jul 20, 2023 at 8:20
  • 1
    @Toreno96 thanks for the heads up! i have updated the link. github seems to refactor the actions docs and move things around and break links very often, unfortunately, but they do have a decent search feature for when this happens. Commented Jul 21, 2023 at 18:49
  • Unfortunately, the content of the docs and the settings page itself also slightly changed, so you may consider updating the screenshot and quote too.
    – Toreno96
    Commented Jul 24, 2023 at 9:40
1

I've created a simple CLI that can help you achieve that - https://github.com/unfor19/githubsecrets

This CLI is based on the official API. You can install it with pip or use Docker, read the README.md for more information

Usage-Demo

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.