Skip to content

Commit

Permalink
NEW Create action
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 9, 2022
1 parent 74f5614 commit b2ff281
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 42 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/auto-tag.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: Auto-tag
on:
push:
tags:
Expand All @@ -8,7 +9,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Auto-tag
uses: emteknetnz/gha-auto-tag@main
with:
ref: ${{ github.ref }}
sha: ${{ github.sha }}
uses: silverstripe/gha-auto-tag@main
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Using the 'v' prefix to avoid confusion with the '2' branch naming convention th

## Usage

.github/workflows/auto-tag.yml
This action has no configuration or inputs - just add the following workflow verbatim.

**.github/workflows/auto-tag.yml**
```yml
on:
push:
Expand All @@ -27,8 +29,4 @@ jobs:
steps:
- name: Auto-tag
uses: silverstripe/gha-auto-tag@main
with:
ref: ${{ github.ref }}
sha: ${{ github.sha }}

```
39 changes: 6 additions & 33 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,22 @@
name: Auto-tag
description: Automatically delete and re-release tags so that other github action modules can use something similar to carets e.g. v0.1 or v3
inputs:
ref:
type: string
required: true
description: github.ref when workflow is triggered by x.y.z semver tag e.g. refs/tags/0.1.23
sha:
type: string
required: true
description: SHA of the tag

runs:
using: composite
steps:
- name: Validate inputs
shell: bash
env:
REF: ${{ inputs.ref }}
SHA: ${{ inputs.sha }}
run: |
# refs/tags/0.1.23 => 0.1.23
TAG=$(echo $REF | cut -c 11-)
if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Valid tag $TAG"
else
echo "Invalid tag $TAG"
exit 1
fi
if [[ "$SHA" =~ ^[0-9a-f]{40}$ ]]; then
echo "Valid sha $SHA"
else
echo "Invalid sha $SHA"
exit 1
fi

- name: Generate tag name
id: generate_tag_name
shell: bash
env:
REF: ${{ inputs.ref }}
GITHUB_REF: ${{ github.ref }}
run: |
# refs/tags/0.1.23 => 0.1.23
TAG=$(echo $REF | cut -c 11-)
[[ $TAG =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]
TAG=$(echo $GITHUB_REF | cut -c 11-)
if ! [[ $TAG =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "Invalid semver tag $TAG"
exit 1
fi
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
Expand All @@ -56,7 +30,6 @@ runs:
- name: Add tag to repo
uses: silverstripe/gha-tag-release@main
with:
sha: ${{ github.sha }}
tag: ${{ steps.generate_tag_name.outputs.tag }}
delete_existing: true
release: false

0 comments on commit b2ff281

Please sign in to comment.