env/README.md

69 lines
7.7 KiB
Markdown
Raw Normal View History

2020-02-10 16:41:27 -05:00
# :octocat: :rocket: GitHub Environment Variables Action
2020-07-13 07:39:14 -04:00
[![GitHub Action: View on Marketplace](https://img.shields.io/badge/GitHub%20Action-View_on_Marketplace-28a745?logo=github)](https://github.com/marketplace/actions/github-environment-variables-action)
2020-07-14 06:06:58 -04:00
[![Demo: available](https://img.shields.io/badge/Demo-available-orange)](.github/workflows/demo.yml)
2020-11-26 14:44:14 -05:00
[![Version: v1.3.0](https://img.shields.io/badge/Version-v1.3.0-brightgreen)](https://github.com/FranzDiebold/github-env-vars-action/releases/tag/v1.3.0)
2020-07-14 06:11:40 -04:00
[![Lint and Test](https://github.com/FranzDiebold/github-env-vars-action/workflows/Lint%20and%20Test/badge.svg)](https://github.com/FranzDiebold/github-env-vars-action/actions?query=workflow%3A%22Lint+and+Test%22)
2020-07-13 06:12:00 -04:00
[![license: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](./LICENSE)
2020-02-11 04:30:39 -05:00
2020-07-13 06:12:00 -04:00
A [GitHub Action](https://github.com/features/actions) to expose useful environment variables.
2020-07-04 11:58:28 -04:00
2020-02-11 04:30:39 -05:00
### Environment Variables exposed by **this Action**
2020-02-10 16:41:27 -05:00
2020-07-16 05:13:18 -04:00
| Environment Variable Name | Description | Example value |
|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------|
| `GITHUB_REPOSITORY_SLUG` | The slug of the owner and repository name (i.e. slug of `FranzDiebold/github-env-vars-action`). | `franzdiebold-github-env-vars-action` |
| `GITHUB_REPOSITORY_OWNER` | The owner of the repository. | `FranzDiebold` |
| `GITHUB_REPOSITORY_OWNER_SLUG` | The slug of the owner of the repository. | `franzdiebold` |
| `GITHUB_REPOSITORY_NAME` | The name of the repository. | `github-env-vars-action` |
| `GITHUB_REPOSITORY_NAME_SLUG` | The slug of the name of the repository. | `github-env-vars-action` |
| `GITHUB_REF_SLUG` | The slug of the branch or tag *ref* that triggered the workflow (i.e. slug of `refs/heads/feat/feature-branch-1`). <br>If neither a branch or tag is available for the event type, the variable will not exist. | `refs-heads-feat-feature-branch-1` |
2020-11-26 14:44:14 -05:00
| `GITHUB_BRANCH_NAME` | The branch *name* that triggered the workflow. For pull requests it is the *head* branch name. | `feat/feature-branch-1` |
| `GITHUB_BRANCH_NAME_SLUG` | The slug of the branch *name* that triggered the workflow. For pull requests it is the slug of the *head* branch name. | `feat-feature-branch-1` |
2020-07-16 05:13:18 -04:00
| `GITHUB_REF_NAME` | The branch or tag *name* that triggered the workflow. <br>If neither a branch or tag is available for the event type, the variable will not exist. | `feat/feature-branch-1` |
| `GITHUB_REF_NAME_SLUG` | The slug of the branch or tag *name* that triggered the workflow. <br>If neither a branch or tag is available for the event type, the variable will not exist. | `feat-feature-branch-1` |
2020-11-26 14:44:14 -05:00
| `GITHUB_HEAD_REF_SLUG` | The slug of the head branch *name*. <br>Only set for event type *pull request* or forked repositories. | `feat-feature-branch-1` |
| `GITHUB_BASE_REF_SLUG` | The slug of the base branch *name*. <br>Only set for event type *pull request* or forked repositories. | `main` |
2020-07-16 05:13:18 -04:00
| `GITHUB_SHA_SHORT` | The shortened commit SHA (8 characters) that triggered the workflow. | `ffac537e` |
2020-02-11 04:30:39 -05:00
2020-07-16 05:13:18 -04:00
> The [slugified](https://en.wikipedia.org/wiki/Clean_URL#Slug) values are designed to be used in a URL.
2020-02-11 04:30:39 -05:00
### Default Environment Variables exposed by GitHub
2020-11-26 14:44:14 -05:00
For a full list of default environment variables exposed by GitHub see [https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables](https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables).
2020-02-11 04:30:39 -05:00
2020-07-16 05:13:18 -04:00
| Environment Variable Name | Description | Example value |
|---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| `GITHUB_ACTOR` | The name of the person or app that initiated the workflow. | `octocat` |
| `GITHUB_REPOSITORY` | The owner and repository name. | `FranzDiebold/github-env-vars-action` |
| `GITHUB_SHA` | The commit SHA that triggered the workflow. | `ffac537e6cbbf934b08745a378932722df287a53` |
| `GITHUB_REF` | The branch or tag ref that triggered the workflow. <br>If neither a branch or tag is available for the event type, the variable will not exist. | `refs/heads/feat/feature-branch-1` |
2020-11-26 14:44:14 -05:00
| `GITHUB_HEAD_REF` | Only set for forked repositories / pull request. The branch of the head repository / the head branch name. | `feat/feature-branch-1` |
| `GITHUB_BASE_REF` | Only set for forked repositories / pull request. The branch of the base repository / the base branch name. | `main` |
2020-02-10 16:41:27 -05:00
2020-07-15 11:41:22 -04:00
## :rocket: Example usage
2020-02-10 16:41:27 -05:00
```yaml
2020-02-11 04:30:39 -05:00
steps:
2020-11-26 14:44:14 -05:00
- uses: FranzDiebold/github-env-vars-action@v1.3.0
2020-02-11 04:30:39 -05:00
- name: Print environment variables
run: |
2020-07-16 05:13:18 -04:00
echo "GITHUB_REPOSITORY_SLUG=$GITHUB_REPOSITORY_SLUG"
2020-02-11 04:30:39 -05:00
echo "GITHUB_REPOSITORY_OWNER=$GITHUB_REPOSITORY_OWNER"
2020-07-16 05:13:18 -04:00
echo "GITHUB_REPOSITORY_OWNER_SLUG=$GITHUB_REPOSITORY_OWNER_SLUG"
2020-02-11 04:30:39 -05:00
echo "GITHUB_REPOSITORY_NAME=$GITHUB_REPOSITORY_NAME"
2020-07-16 05:13:18 -04:00
echo "GITHUB_REPOSITORY_NAME_SLUG=$GITHUB_REPOSITORY_NAME_SLUG"
echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG"
2020-11-26 14:44:14 -05:00
echo "GITHUB_BRANCH_NAME=$GITHUB_BRANCH_NAME"
echo "GITHUB_BRANCH_NAME_SLUG=$GITHUB_BRANCH_NAME_SLUG"
2020-02-11 04:30:39 -05:00
echo "GITHUB_REF_NAME=$GITHUB_REF_NAME"
2020-07-16 05:13:18 -04:00
echo "GITHUB_REF_NAME_SLUG=$GITHUB_REF_NAME_SLUG"
2020-11-26 14:44:14 -05:00
echo "GITHUB_HEAD_REF_SLUG=$GITHUB_HEAD_REF_SLUG"
echo "GITHUB_BASE_REF_SLUG=$GITHUB_BASE_REF_SLUG"
2020-02-11 04:30:39 -05:00
echo "GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT"
2020-02-10 16:41:27 -05:00
```
2020-07-14 03:41:04 -04:00
### Demo
A demo for all Operating systems (Linux, macOS and Windows) is also available in the [demo workflows file of this repository](.github/workflows/demo.yml)!