Merge branch 'primary' into feat/improve-demo-add-env-vars

This commit is contained in:
Franz Diebold 2020-11-27 21:18:32 +01:00 committed by GitHub
commit 599593b29b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 577 additions and 460 deletions

View file

@ -7,7 +7,7 @@ jobs:
name: Linux Demo
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/github-env-vars-action@v1.2.1
- uses: FranzDiebold/github-env-vars-action@v1.3.0
- name: Print environment variables exposed by this action
run: |
echo "GITHUB_REPOSITORY_SLUG=$GITHUB_REPOSITORY_SLUG"
@ -16,8 +16,12 @@ jobs:
echo "GITHUB_REPOSITORY_NAME=$GITHUB_REPOSITORY_NAME"
echo "GITHUB_REPOSITORY_NAME_SLUG=$GITHUB_REPOSITORY_NAME_SLUG"
echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG"
echo "GITHUB_BRANCH_NAME=$GITHUB_BRANCH_NAME"
echo "GITHUB_BRANCH_NAME_SLUG=$GITHUB_BRANCH_NAME_SLUG"
echo "GITHUB_REF_NAME=$GITHUB_REF_NAME"
echo "GITHUB_REF_NAME_SLUG=$GITHUB_REF_NAME_SLUG"
echo "GITHUB_HEAD_REF_SLUG=$GITHUB_HEAD_REF_SLUG"
echo "GITHUB_BASE_REF_SLUG=$GITHUB_BASE_REF_SLUG"
echo "GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT"
- name: Print environment variables exposed by GitHub
run: |
@ -37,7 +41,7 @@ jobs:
name: Windows Demo
runs-on: windows-latest
steps:
- uses: FranzDiebold/github-env-vars-action@v1.2.1
- uses: FranzDiebold/github-env-vars-action@v1.3.0
- name: Print environment variables exposed by this action
run: |
echo "GITHUB_REPOSITORY_SLUG=$Env:GITHUB_REPOSITORY_SLUG"
@ -46,8 +50,12 @@ jobs:
echo "GITHUB_REPOSITORY_NAME=$Env:GITHUB_REPOSITORY_NAME"
echo "GITHUB_REPOSITORY_NAME_SLUG=$Env:GITHUB_REPOSITORY_NAME_SLUG"
echo "GITHUB_REF_SLUG=$Env:GITHUB_REF_SLUG"
echo "GITHUB_BRANCH_NAME=$Env:GITHUB_BRANCH_NAME"
echo "GITHUB_BRANCH_NAME_SLUG=$Env:GITHUB_BRANCH_NAME_SLUG"
echo "GITHUB_REF_NAME=$Env:GITHUB_REF_NAME"
echo "GITHUB_REF_NAME_SLUG=$Env:GITHUB_REF_NAME_SLUG"
echo "GITHUB_HEAD_REF_SLUG=$Env:GITHUB_HEAD_REF_SLUG"
echo "GITHUB_BASE_REF_SLUG=$Env:GITHUB_BASE_REF_SLUG"
echo "GITHUB_SHA_SHORT=$Env:GITHUB_SHA_SHORT"
- name: Print environment variables exposed by GitHub
run: |
@ -67,7 +75,7 @@ jobs:
name: macOS Demo
runs-on: macos-latest
steps:
- uses: FranzDiebold/github-env-vars-action@v1.2.1
- uses: FranzDiebold/github-env-vars-action@v1.3.0
- name: Print environment variables exposed by this action
run: |
echo "GITHUB_REPOSITORY_SLUG=$GITHUB_REPOSITORY_SLUG"
@ -76,8 +84,12 @@ jobs:
echo "GITHUB_REPOSITORY_NAME=$GITHUB_REPOSITORY_NAME"
echo "GITHUB_REPOSITORY_NAME_SLUG=$GITHUB_REPOSITORY_NAME_SLUG"
echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG"
echo "GITHUB_BRANCH_NAME=$GITHUB_BRANCH_NAME"
echo "GITHUB_BRANCH_NAME_SLUG=$GITHUB_BRANCH_NAME_SLUG"
echo "GITHUB_REF_NAME=$GITHUB_REF_NAME"
echo "GITHUB_REF_NAME_SLUG=$GITHUB_REF_NAME_SLUG"
echo "GITHUB_HEAD_REF_SLUG=$GITHUB_HEAD_REF_SLUG"
echo "GITHUB_BASE_REF_SLUG=$GITHUB_BASE_REF_SLUG"
echo "GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT"
- name: Print environment variables exposed by GitHub
run: |

View file

@ -2,7 +2,7 @@
[![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)
[![Demo: available](https://img.shields.io/badge/Demo-available-orange)](.github/workflows/demo.yml)
[![Version: v1.2.1](https://img.shields.io/badge/Version-v1.2.1-brightgreen)](https://github.com/FranzDiebold/github-env-vars-action/releases/tag/v1.2.1)
[![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)
[![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)
[![license: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](./LICENSE)
@ -18,15 +18,19 @@ A [GitHub Action](https://github.com/features/actions) to expose useful environm
| `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` |
| `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` |
| `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` |
| `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` |
| `GITHUB_SHA_SHORT` | The shortened commit SHA (8 characters) that triggered the workflow. | `ffac537e` |
> The [slugified](https://en.wikipedia.org/wiki/Clean_URL#Slug) values are designed to be used in a URL.
### Default Environment Variables exposed by GitHub
For a full list of default environment variables exposed by GitHub see [https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables).
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).
| Environment Variable Name | Description | Example value |
|---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
@ -34,12 +38,14 @@ For a full list of default environment variables exposed by GitHub see [https://
| `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` |
| `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` |
## :rocket: Example usage
```yaml
steps:
- uses: FranzDiebold/github-env-vars-action@v1.2.1
- uses: FranzDiebold/github-env-vars-action@v1.3.0
- name: Print environment variables
run: |
echo "GITHUB_REPOSITORY_SLUG=$GITHUB_REPOSITORY_SLUG"
@ -48,8 +54,12 @@ steps:
echo "GITHUB_REPOSITORY_NAME=$GITHUB_REPOSITORY_NAME"
echo "GITHUB_REPOSITORY_NAME_SLUG=$GITHUB_REPOSITORY_NAME_SLUG"
echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG"
echo "GITHUB_BRANCH_NAME=$GITHUB_BRANCH_NAME"
echo "GITHUB_BRANCH_NAME_SLUG=$GITHUB_BRANCH_NAME_SLUG"
echo "GITHUB_REF_NAME=$GITHUB_REF_NAME"
echo "GITHUB_REF_NAME_SLUG=$GITHUB_REF_NAME_SLUG"
echo "GITHUB_HEAD_REF_SLUG=$GITHUB_HEAD_REF_SLUG"
echo "GITHUB_BASE_REF_SLUG=$GITHUB_BASE_REF_SLUG"
echo "GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT"
```

View file

@ -122,6 +122,40 @@ try {
'"GITHUB_REF_NAME_SLUG".');
}
headRef = process.env.GITHUB_HEAD_REF;
branchName = headRef || refName;
if (branchName) {
core.exportVariable('GITHUB_BRANCH_NAME', branchName);
core.info(`Set GITHUB_BRANCH_NAME=${process.env.GITHUB_BRANCH_NAME}`);
core.exportVariable('GITHUB_BRANCH_NAME_SLUG', slugify(branchName));
core.info('Set GITHUB_BRANCH_NAME_SLUG=' +
`${process.env.GITHUB_BRANCH_NAME_SLUG}`);
} else {
core.warning('Environment variables "GITHUB_REF" and ' +
'"GITHUB_HEAD_REF" not set. ' +
'Cannot set "GITHUB_BRANCH_NAME" and ' +
'"GITHUB_BRANCH_NAME_SLUG".');
}
if (headRef) {
core.exportVariable('GITHUB_HEAD_REF_SLUG', slugify(headRef));
core.info(`Set GITHUB_HEAD_REF_SLUG=${process.env.GITHUB_HEAD_REF_SLUG}`);
} else {
core.warning('Environment variable "GITHUB_HEAD_REF" not set. ' +
'Cannot set "GITHUB_HEAD_REF_SLUG".');
}
baseRef = process.env.GITHUB_BASE_REF;
if (baseRef) {
core.exportVariable('GITHUB_BASE_REF_SLUG', slugify(baseRef));
core.info(`Set GITHUB_BASE_REF_SLUG=${process.env.GITHUB_BASE_REF_SLUG}`);
} else {
core.warning('Environment variable "GITHUB_BASE_REF" not set. ' +
'Cannot set "GITHUB_BASE_REF_SLUG".');
}
// i.e. ffac537e6cbbf934b08745a378932722df287a53
shaShort = getShaShort(process.env.GITHUB_SHA);
if (shaShort) {

963
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "github-env-vars-action",
"version": "1.2.1",
"version": "1.3.0",
"description": "A GitHub Action to expose useful environment variables.",
"main": "index.js",
"scripts": {
@ -26,8 +26,8 @@
"@actions/core": "^1.2.6"
},
"devDependencies": {
"eslint": "^7.10.0",
"eslint": "^7.14.0",
"eslint-config-google": "^0.14.0",
"jest": "^26.4.2"
"jest": "^26.6.3"
}
}