-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
112 lines (102 loc) · 3.97 KB
/
Copy pathaction.yml
File metadata and controls
112 lines (102 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright (c) 2025 Erick Bourgeois, finos
# SPDX-License-Identifier: Apache-2.0
name: 'Extract Version Information'
description: 'Extracts version, tag name, and image tags for consistent use across workflows'
author: 'Erick Bourgeois'
branding:
icon: 'tag'
color: 'blue'
inputs:
repository:
description: 'Repository name (e.g., finos/myapp) - used for image repository naming'
required: true
workflow-type:
description: 'Workflow type: main, pr, or release'
required: true
pr-number:
description: 'PR number (only for pr workflow)'
required: false
release-tag:
description: 'Release tag name (only for release workflow)'
required: false
image-tag-suffix:
description: 'Suffix to append to the image tag (e.g., "-distroless")'
required: false
default: ''
outputs:
version:
description: 'Semantic version (e.g., 1.2.3)'
value: ${{ steps.extract.outputs.version }}
tag-name:
description: 'Git tag name (e.g., v1.2.3)'
value: ${{ steps.extract.outputs.tag-name }}
image-tag:
description: 'Docker image tag (e.g., main-2025-12-17, pr-42, v0.2.0)'
value: ${{ steps.extract.outputs.image-tag }}
image-repository:
description: 'Docker repository name (e.g., finos/myapp)'
value: ${{ steps.extract.outputs.image-repository }}
short-sha:
description: 'Short 7-character SHA'
value: ${{ steps.extract.outputs.short-sha }}
runs:
using: 'composite'
steps:
- name: Extract version information
id: extract
shell: bash
env:
GH_SHA: ${{ github.sha }}
GH_RUN_NUMBER: ${{ github.run_number }}
IN_REPOSITORY: ${{ inputs.repository }}
IN_WORKFLOW_TYPE: ${{ inputs.workflow-type }}
IN_PR_NUMBER: ${{ inputs.pr-number }}
IN_RELEASE_TAG: ${{ inputs.release-tag }}
IN_IMAGE_TAG_SUFFIX: ${{ inputs.image-tag-suffix }}
run: |
# Extract short SHA (first 7 characters)
SHORT_SHA="${GH_SHA:0:7}"
echo "short-sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
IMAGE_REPOSITORY="${IN_REPOSITORY}"
IMAGE_TAG_SUFFIX="${IN_IMAGE_TAG_SUFFIX}"
echo "image-repository=${IMAGE_REPOSITORY}" >> $GITHUB_OUTPUT
case "${IN_WORKFLOW_TYPE}" in
release)
# Release workflow: extract from release tag
# Tag format: v0.2.0 (no date)
TAG_NAME="${IN_RELEASE_TAG}"
VERSION="${TAG_NAME#v}"
IMAGE_TAG="${TAG_NAME}${IMAGE_TAG_SUFFIX}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag-name=${TAG_NAME}" >> $GITHUB_OUTPUT
echo "image-tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "Release: version=${VERSION}, tag=${TAG_NAME}, image=${IMAGE_REPOSITORY}:${IMAGE_TAG}"
;;
pr)
# PR workflow: use pr-NUMBER format
# Tag format: pr-42
VERSION="pr-${IN_PR_NUMBER}"
TAG_NAME="pr-${IN_PR_NUMBER}"
IMAGE_TAG="pr-${IN_PR_NUMBER}${IMAGE_TAG_SUFFIX}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag-name=${TAG_NAME}" >> $GITHUB_OUTPUT
echo "image-tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "PR: version=${VERSION}, tag=${TAG_NAME}, image=${IMAGE_REPOSITORY}:${IMAGE_TAG}"
;;
main)
# Main branch: use main-YYYY-MM-DD format
# Tag format: main-2025-12-17
DATE=$(date +%Y-%m-%d)
VERSION="0.0.0-main.${DATE}.${GH_RUN_NUMBER}"
TAG_NAME="main-${DATE}"
IMAGE_TAG="main-${DATE}${IMAGE_TAG_SUFFIX}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag-name=${TAG_NAME}" >> $GITHUB_OUTPUT
echo "image-tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "Main: version=${VERSION}, tag=${TAG_NAME}, image=${IMAGE_REPOSITORY}:${IMAGE_TAG}"
;;
*)
echo "Error: Invalid workflow-type '${IN_WORKFLOW_TYPE}'. Must be: main, pr, or release"
exit 1
;;
esac