-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 150138f
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Main | ||
|
||
on: [push] | ||
|
||
jobs: | ||
print_branch_tag: | ||
runs-on: ubuntu-latest | ||
name: A job to print branch tag | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: ./ | ||
name: Extract branch tag | ||
id: extract | ||
|
||
# Use the output/env from the `extract` step | ||
- name: Print the values | ||
run: | | ||
echo "The branch tag is ${{ steps.extract.outputs.branch_tag }}" | ||
echo "or ${{ env.BRANCH_TAG }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM alpine:3 | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Branch tag action | ||
|
||
This action returns the valid docker image tag name by extracting the branch from branch name or tag ref and replacing `/` by `-` using [Shell Parameter Expansion](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html) | ||
|
||
``` | ||
#refs/heads/feature/add-new-action -> feature-add-new-action | ||
``` | ||
|
||
## Inputs | ||
|
||
### `ref` | ||
|
||
**Required** The name of the branch or tag ref. | ||
Default is the current branch that runs this action. | ||
|
||
## Outputs | ||
|
||
### `branch_tag` | ||
|
||
The valid branch tag | ||
|
||
## Environment variables | ||
|
||
### `BRANCH_TAG` | ||
|
||
The valid branch tag | ||
|
||
## Example usage | ||
|
||
``` | ||
uses: nimblehq/branch-tag-action@v1 | ||
# or | ||
uses: nimblehq/branch-tag-action@v1 | ||
with: | ||
ref: 'feature/add-new-action' | ||
``` | ||
|
||
### Full workflow | ||
|
||
``` | ||
on: [push] | ||
jobs: | ||
print_branch_tag: | ||
runs-on: ubuntu-latest | ||
name: A job to print branch tag | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: nimblehq/branch-tag-action@v1 | ||
id: extract | ||
# Use the output/env from the `extract` step | ||
- name: Print the values | ||
run: | | ||
echo "The branch tag is ${{ steps.extract.outputs.branch_tag }}" | ||
echo "or ${{ env.BRANCH_TAG }}" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Branch Tag Action | ||
description: Get branch tag and set to ENV | ||
inputs: | ||
ref: | ||
description: 'The branch or tag ref' | ||
required: true | ||
default: ${{ github.ref }} | ||
runs: | ||
using: docker | ||
image: Dockerfile | ||
args: | ||
- ${{ inputs.ref }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh -l | ||
|
||
BRANCH_NAME="${1#refs/heads/}" | ||
|
||
# shellcheck disable=SC2039 | ||
BRANCH_TAG="${BRANCH_NAME/\//-}" | ||
|
||
echo "::set-env name=BRANCH_TAG::$BRANCH_TAG" | ||
echo "::set-output name=branch_tag::$BRANCH_TAG" |