Skip to content

Commit

Permalink
Create branch tag action
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangmirs committed Sep 10, 2020
0 parents commit 150138f
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
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 }}"
5 changes: 5 additions & 0 deletions Dockerfile
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"]
58 changes: 58 additions & 0 deletions README.md
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 }}"
```
12 changes: 12 additions & 0 deletions action.yml
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 }}
9 changes: 9 additions & 0 deletions entrypoint.sh
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"

0 comments on commit 150138f

Please sign in to comment.