Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repository Name as a GitHub Action environment variable?

How would you get the repository name (not the user or organization) as an environment variable in GitHub Actions? I found github.repository but that contains the owner as the first part like so: owner/repo.

like image 450
CalculatingKraken Avatar asked Jul 08 '20 20:07

CalculatingKraken


People also ask

How do I define an environment variable in GitHub Actions?

To set a custom environment variable, you must define it in the workflow file. The scope of a custom environment variable is limited to the element in which it is defined. You can define environment variables that are scoped for: The entire workflow, by using env at the top level of the workflow file.

How do I use action variables in GitHub?

To add variables to the repository, you can define the variable in Secrets tab and use them in the yaml file. Note: You can access the variable in the build. xml as highlighted below. And, to make use of your variables as unencrypted, you can directly use them in the yml as highlighted below.

How do I add an environment variable to GitHub?

To add a secret to your repository, go to your repository's Setting > Secrets , click on Add a new secret . In the screenshot below, I added 2 env variables: REACT_APP_APIKey and REACT_APP_APISecret . Notice: All the environment variable you want to access with create-react-app need to be prefixed with REACT_APP .

How do I change my GitHub repository name?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. Under the Repository Name heading, type the new name of your repository. Click Rename.


1 Answers

Try github.event.repository.name

- run: echo ::set-env name=REPO_NAME::${{ github.event.repository.name }}

Documentation aside, i'd really recommend dumping contexts (maybe in some test repo) just to get familiar with them, as there is lot of data which might or might not be useful when writing non-trivial workflows.

- name: Dump github context
  run:   echo "$GITHUB_CONTEXT"
  shell: bash
  env:
   GITHUB_CONTEXT: ${{ toJson(github) }}

Be aware that parts of github context changes depends which event triggered workflow, so it might be a good idea to double check if data you want to use is available for all events used in workflow.

like image 67
Samira Avatar answered Sep 22 '22 05:09

Samira