-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
e71a886
commit 74f5614
Showing
3 changed files
with
110 additions
and
1 deletion.
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,14 @@ | ||
on: | ||
push: | ||
tags: | ||
- '*.*.*' | ||
jobs: | ||
auto-tag: | ||
name: Auto-tag | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Auto-tag | ||
uses: emteknetnz/gha-auto-tag@main | ||
with: | ||
ref: ${{ github.ref }} | ||
sha: ${{ github.sha }} |
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 |
---|---|---|
@@ -1 +1,34 @@ | ||
# gha-auto-tag | ||
# GitHub Actions - Auto-tag | ||
|
||
Delete and re-release tags so that other modules can use something similar to carets (^) | ||
|
||
Caret (^) requirements are not supported by github-action e.g. @^2 does not work | ||
|
||
The action will tag v2 when 2.5.0 is released and v0.3 when 0.3.5 is released | ||
|
||
The new 'v' tag will point to the same sha e.g. the sha of v2 will equal the sha of 2.5.0 | ||
|
||
This allows modules to include workflows using the @v2 or @v0.3 syntax | ||
|
||
Using the 'v' prefix to avoid confusion with the '2' branch naming convention that Silverstripe uses | ||
|
||
## Usage | ||
|
||
.github/workflows/auto-tag.yml | ||
```yml | ||
on: | ||
push: | ||
tags: | ||
- '*.*.*' | ||
jobs: | ||
auto-tag: | ||
name: Auto-tag | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Auto-tag | ||
uses: silverstripe/gha-auto-tag@main | ||
with: | ||
ref: ${{ github.ref }} | ||
sha: ${{ github.sha }} | ||
|
||
``` |
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,62 @@ | ||
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 }} | ||
run: | | ||
# refs/tags/0.1.23 => 0.1.23 | ||
TAG=$(echo $REF | cut -c 11-) | ||
[[ $TAG =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] | ||
MAJOR="${BASH_REMATCH[1]}" | ||
MINOR="${BASH_REMATCH[2]}" | ||
PATCH="${BASH_REMATCH[3]}" | ||
NEW_TAG="v${MAJOR}" | ||
if [ "$MAJOR" == "0" ]; then | ||
NEW_TAG=("v${MAJOR}.${MINOR}") | ||
fi | ||
echo "Tag is $NEW_TAG" | ||
echo "::set-output name=tag::$NEW_TAG" | ||
- 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 |