feat: add GITHUB_HEAD_REF_SLUG

This commit is contained in:
romain lespinasse
2019-11-06 01:27:30 +01:00
committed by Romain Lespinasse
parent e27f283bad
commit 855ce255dd
2 changed files with 15 additions and 4 deletions

View File

@@ -10,9 +10,10 @@ This action slug and expose some github variables.
## Environement Variables
### `GITHUB_REF_SLUG`
Slug from `GITHUB_REF` env variables
| GitHub environment variable | Slug variable |
| - | - |
| GITHUB_REF | GITHUB_REF_SLUG |
| GITHUB_HEAD_REF | GITHUB_HEAD_REF_SLUG |
## Example usage
@@ -21,4 +22,6 @@ Slug from `GITHUB_REF` env variables
- name: Print slug variables
run: |
echo ${{ env.GITHUB_REF_SLUG }}
echo ${{ env.GITHUB_HEAD_REF_SLUG }}
echo ${{ env.GITHUB_BASE_REF_SLUG }}
```

View File

@@ -1,3 +1,11 @@
#!/bin/sh -l
echo ::set-env name=GITHUB_REF_SLUG::$(echo $GITHUB_REF | tr A-Z a-z | sed -r 's#refs/.*/##;s/[~\^]+//g;s/[^a-zA-Z0-9]+/-/g;s/^-+\|-+$//g' | cut -c1-63)
slug_ref() {
echo $1 \
| tr A-Z a-z \
| sed -r 's#refs/.*/##;s/[~\^]+//g;s/[^a-zA-Z0-9]+/-/g;s/^-+\|-+$//g' \
| cut -c1-63
}
echo ::set-env name=GITHUB_REF_SLUG::$(slug_ref $GITHUB_REF)
echo ::set-env name=GITHUB_HEAD_REF_SLUG::$(slug_ref $GITHUB_HEAD_REF)