-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
97 lines (96 loc) · 4.17 KB
/
action.yml
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
name: 'GitOps Automatic Versioning'
author: 'EvilKittenLord'
description: 'Automatically determine semantic version based on branch merge history.'
branding:
icon: git-branch
color: white
inputs:
force-re-evaluate:
description: "Forces a re-evaluation of the entire git history."
required: false
default: 'false'
force-patch-increment:
description: "Forces a PATCH increment if no other increment detected. NOTE: This is intended for development purposes only."
required: false
default: 'false'
mono-repo-product-name:
description: "Enables mono-repo mode. The product name to match against. EG: 'bob', match the tags like 'bob_1.2.3'."
required: false
default: ''
mono-repo-product-path:
description: "The path to the product. IE: 'path/to/bob'. Required if 'mono-repo-mode' is enabled."
required: false
default: ''
outputs:
new-version:
description: "New Version"
value: ${{ steps.new-version.outputs.new-version }}
previous-version:
description: "Previous Version"
value: ${{ steps.previous-version.outputs.previous-version }}
debug-cmd:
description: "Input Command"
value: ${{ steps.previous-version.outputs.debug-cmd }}
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Ensure full commit history
run: |
cd $GITHUB_WORKSPACE
git pull --unshallow
shell: bash
- name: Detect Previous Version
id: previous-version
run: |
cd $GITHUB_WORKSPACE
echo "previous-version=$(${{ github.action_path }}/scripts/detectPreviousVersion.sh)" | tee $GITHUB_OUTPUT
shell: bash
- name: Detect New Version
id: new-version
run: |
cd $GITHUB_WORKSPACE
opt=''
[[ "${{ github.event.inputs.force-re-evaluate }}" == 'true' ]] && opt='$opt -f'
[[ "${{ github.event.inputs.force-patch-increment }}" == 'true' ]] && opt='$opt -p'
[[ "${{ github.event.inputs.mono-repo-product-name }}" != "" ]] && opt='$opt -n ${{ github.event.inputs.mono-repo-product-name }}'
[[ "${{ github.event.inputs.mono-repo-product-path }}" != "" ]] && opt='$opt -d ${{ github.event.inputs.mono-repo-product-path }}'
new_version="$(${{ github.action_path }}/scripts/detectNewVersion.sh $opt)" || true
debug_cmd="echo ${{ github.action_path }}/scripts/detectNewVersion.sh $opt" || true
echo "new-version=$new_version" | tee $GITHUB_OUTPUT
if [[ "$new_version" =~ "520" ]]; then
echo -e "ERROR: 520 - You must source this script when specifying an environment variable! Eg: '. ./foo.sh -e bar_ver'"
exit 1 || true
fi
if [[ "$new_version" =~ "570" ]]; then
echo -e "ERROR: 570 - Invalid argument!"
exit 1 || true
fi
if [[ "$new_version" =~ "590" ]]; then
echo -e "FATAL: 501 - This is not a git repository!"
exit 1 || true
fi
if [[ "$new_version" =~ "591" ]]; then
echo -e "ERROR: 591 - Unsupported origin host."
exit 1 || true
fi
if [[ "$new_version" =~ "599" ]]; then
echo -e "ERROR: 599 - No feature, enhancement, fix, bugfix, hotfix, or ops branches detected!"
exit 1 || true
fi
shell: bash
- name: Debug Cmd
id: debug-cmd
run: |
cd $GITHUB_WORKSPACE
opt=''
[[ "${{ github.event.inputs.force-re-evaluate }}" == 'true' ]] && opt='$opt -f'
[[ "${{ github.event.inputs.force-patch-increment }}" == 'true' ]] && opt='$opt -p'
[[ "${{ github.event.inputs.mono-repo-product-name }}" != "" ]] && opt='$opt -n ${{ github.event.inputs.mono-repo-product-name }}'
[[ "${{ github.event.inputs.mono-repo-product-path }}" != "" ]] && opt='$opt -d ${{ github.event.inputs.mono-repo-product-path }}'
debug_cmd="echo ${{ github.action_path }}/scripts/detectNewVersion.sh $opt" || true
echo "debug-cmd=$debug_cmd" | tee $GITHUB_OUTPUT
shell: bash
# See github contexts for more like github.action_path.
# REF: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context