-
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.
Merge pull request #8 from databox/tag_check
Support non semversion tags
- Loading branch information
Showing
6 changed files
with
157 additions
and
36 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
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
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,30 +1,94 @@ | ||
name: Build and push image | ||
name: Tag check | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: 'Tag name' | ||
required: true | ||
type: string | ||
tag_check_regex: | ||
description: 'Regex to check tag' | ||
required: false | ||
type: string | ||
default: '^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$' | ||
extract_semver_from_tag: | ||
description: 'Extract semver from tag' | ||
required: false | ||
type: boolean | ||
default: false | ||
tag_extract_regex: | ||
description: 'Regex to extract semver from tag' | ||
required: false | ||
type: string | ||
default: '([^@]+)$' | ||
runner: | ||
description: 'Runner' | ||
required: false | ||
type: string | ||
default: 'ubnutu-22-04-arm64-1-core-4-ram' | ||
workflow_call: | ||
inputs: | ||
tag: | ||
description: 'Tag name' | ||
required: true | ||
type: string | ||
tag_check_regex: | ||
description: 'Regex to check tag' | ||
required: false | ||
type: string | ||
default: '^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$' | ||
extract_semver_from_tag: | ||
description: 'Extract semver from tag' | ||
required: false | ||
type: boolean | ||
default: false | ||
tag_extract_regex: | ||
description: 'Regex to extract semver from tag' | ||
required: false | ||
type: string | ||
default: '([^@]+)$' | ||
runner: | ||
description: 'Runner' | ||
required: false | ||
type: string | ||
default: 'ubnutu-22-04-arm64-1-core-4-ram' | ||
outputs: | ||
match: | ||
value: ${{ jobs.tag-filter.outputs.match }} | ||
|
||
semver: | ||
value: ${{ jobs.tag-filter.outputs.semver }} | ||
jobs: | ||
tag-filter: | ||
name: Check tag ${{ inputs.tag }} | ||
runs-on: ubnutu-22-04-arm64-1-core-4-ram | ||
runs-on: ${{ inputs.runner }} | ||
timeout-minutes: 1 | ||
outputs: | ||
match: ${{ steps.tag-check.outputs.match }} | ||
semver: ${{ steps.semver.outputs.semver }} | ||
steps: | ||
- id: tag-check | ||
- name: Check tag is valid based on regex | ||
id: tag-check | ||
run: | | ||
if [[ "${{ inputs.tag }}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$ ]]; then | ||
if [[ "${{ inputs.tag }}" =~ ${{ inputs.tag_check_regex }} ]]; then | ||
echo "match=true" >> $GITHUB_OUTPUT | ||
echo "valid tag for release" | ||
echo "Tag ${{ inputs.tag }} is valid!" | ||
else | ||
echo "match=false" >> $GITHUB_OUTPUT | ||
echo "${{ inputs.tag }} is invalid tag for release. Tag check regex: ^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$" | ||
echo "*************** ERROR ***************" | ||
echo "Invalid tag!" | ||
echo "Ensure tag maches regex" | ||
echo "${{ inputs.tag_check_regex }}" | ||
echo "*************** ERROR ***************" | ||
exit 1 | ||
fi | ||
fi | ||
- name: Extract semantic version from tag | ||
id: semver | ||
if: ${{ steps.tag-check.outputs.match == 'true' }} | ||
run: | | ||
if [[ "${{ inputs.extract_semver_from_tag }}" == "false" ]]; then | ||
semver=${{ inputs.tag }} | ||
else | ||
semver=$(echo ${{ inputs.tag }} | grep -Eo ${{ inputs.tag_extract_regex }}) | ||
fi | ||
echo "semver=$semver" >> $GITHUB_OUTPUT | ||
echo "semver=$semver" |
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,15 @@ | ||
name: Tests | ||
on: | ||
pull_request: | ||
types: [opened, reopened, labeled, unlabeled, edited, synchronize] | ||
branches: [master] | ||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Tag check | ||
run: | | ||
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ./tests/test_tag-check_workflow.sh ${{ github.head_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 @@ | ||
FROM alpine:edge |
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,25 @@ | ||
#!/bin/bash | ||
|
||
ref=$1 | ||
|
||
#TODO: | ||
# - Add tests for the build workflow | ||
|
||
#authorize the github cli with GitHub token | ||
gh auth login --with-token $GITHUB_TOKEN | ||
|
||
#run semantic versioning test | ||
gh workflow run "tag-check.yml" \ | ||
-f tag="1.0.0" \ | ||
-f runner="ubuntu-latest" \ | ||
-r $ref | ||
|
||
#run non semantic versioning test | ||
gh workflow run "tag-check.yml" \ | ||
-f tag="@databox/[email protected]" \ | ||
-f tag_check_regex="^@.+react-monorepo-benchmark.*@[0-9]+.[0-9]+.[0-9]+(-alpha.[0-9]+)?$" \ | ||
-f extract_semver_from_tag="true" \ | ||
-f tag_extract_regex="'([^@]+)$'" \ | ||
-f runner="ubuntu-latest" \ | ||
-r $ref | ||
|