From 3ec790ff6e3602f4239365dce7f278d903c22c7c Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 7 Jun 2022 14:28:25 +1200 Subject: [PATCH] NEW Create action --- .github/workflows/auto-tag.yml | 6 ++--- README.md | 8 +++---- action.yml | 40 +++++----------------------------- 3 files changed, 11 insertions(+), 43 deletions(-) diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml index 9267c57..33446ca 100644 --- a/.github/workflows/auto-tag.yml +++ b/.github/workflows/auto-tag.yml @@ -1,3 +1,4 @@ +name: Auto-tag on: push: tags: @@ -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 diff --git a/README.md b/README.md index fb04cd5..aa48018 100644 --- a/README.md +++ b/README.md @@ -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: @@ -27,8 +29,4 @@ jobs: steps: - name: Auto-tag uses: silverstripe/gha-auto-tag@main - with: - ref: ${{ github.ref }} - sha: ${{ github.sha }} - ``` diff --git a/action.yml b/action.yml index 0c7e68e..3ca1dd6 100644 --- a/action.yml +++ b/action.yml @@ -1,48 +1,21 @@ 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]}" @@ -56,7 +29,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