Skip to content

Commit 3c0ee2a

Browse files
Merge pull request #1 from GlueOps/feature/generate-default-glueops-tags
feat: generate tags action
2 parents 15f25a7 + 72d0c23 commit 3c0ee2a

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
# github-actions-create-container-tags
1+
# Custom Action to Create the Default GlueOps Image Tags
2+
3+
The GlueOps platform relies upon specific tags for CI/CD automation. This Action automates the creation of those tags.
4+
5+
## Tags Created
6+
7+
* `Target Reference:` Either Branch Name or Tag, depending upon the trigger context.
8+
* `Short SHA`
9+
* `SHA`
10+
11+
## Usage
12+
13+
Can be implemented as a stand alone action, or coupled with the action [GlueOps/github-actions-build-push-containers](https://github.com/GlueOps/github-actions-build-push-containers).
14+
15+
### Output Values
16+
17+
* `tags_csv`: comma-separated string of generated tags.
18+
* `clean_target_ref`: the target reference (e.g. branch name or tag) with invalid characters for a container tag removed.
19+
* `target_ref_type`: the type of target reference, one of ["branch", "pull_request", "tag", "unknown"].
20+
21+
### Example Configuration
22+
23+
```yaml
24+
- name: Create GlueOps Tags
25+
if: inputs.tags == ''
26+
uses: Glueops/[email protected]
27+
id: create-tags
28+
```

action.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: 'Create GlueOps Image Tags'
2+
description: 'Creates tags for docker images used by the GlueOps platform'
3+
4+
outputs:
5+
tags_csv:
6+
description: 'Comma-separated list of GlueOps image tags'
7+
value: ${{ steps.create-tags.outputs.tags }}
8+
clean_target_ref:
9+
description: 'Target reference with invalid tag characters removed'
10+
value: ${{ steps.create-tags.outputs.target-ref}}
11+
target_ref_type:
12+
description: 'Type of Target ref, as ["branch", "pull_request", "tag", "unknown"]'
13+
value: ${{ steps.create-tags.outputs.target-ref-type }}
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Create Tags
19+
id: create-tags
20+
shell: bash
21+
run: |
22+
echo "::group::determine ref"
23+
if [[ $GITHUB_REF == refs/heads/* ]]; then
24+
REF_TYPE=branch
25+
TARGET_REF=${GITHUB_REF#refs/heads/}
26+
elif [[ $GITHUB_REF == refs/tags/* ]]; then
27+
REF_TYPE=tag
28+
TARGET_REF=${GITHUB_REF#refs/tags/}
29+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
30+
REF_TYPE=pull_request
31+
TARGET_REF=$GITHUB_SHA
32+
else
33+
REF_TYPE=unknown
34+
fi
35+
echo "target-ref-type=$TARGET_REF" >> $GITHUB_OUTPUT
36+
37+
echo "::endgroup::"
38+
# Create default tags
39+
SHA="${{ github.sha }}"
40+
SHORT_SHA="${SHA:0:7}"
41+
42+
# Remove invalid tag characters from TARGET_REF
43+
TARGET_REF="${TARGET_REF#refs/tags/}"
44+
TARGET_REF="${TARGET_REF#refs/heads/}"
45+
TARGET_REF=${TARGET_REF////-} # Replace slashes with hyphens
46+
TARGET_REF=${TARGET_REF//[^a-zA-Z0-9_.-]/_} # Replace invalid characters with underscores
47+
TARGET_REF=${TARGET_REF// /_} # Replace whitespaces with underscores
48+
TARGET_REF=${TARGET_REF,,} # Convert to lowercase
49+
echo "target-ref=$TARGET_REF" >> $GITHUB_OUTPUT
50+
51+
52+
# Array of tags to generate
53+
TAGS_ARRAY=(
54+
"${TARGET_REF}"
55+
"${SHORT_SHA}"
56+
"${SHA}"
57+
)
58+
59+
IFS=','
60+
TAGS=${TAGS_ARRAY[*]}
61+
echo "Computed tags: $TAGS"
62+
echo "tags=$TAGS" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)