-
Notifications
You must be signed in to change notification settings - Fork 384
204 lines (171 loc) · 7.78 KB
/
test.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: Test
# This workflow tests the tag action and can be used on PRs to detect (some) breaking changes.
on:
workflow_dispatch:
pull_request:
types:
- opened
- edited
- reopened
- synchronize
permissions:
pull-requests: write
checks: write
contents: read
jobs:
test-action:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: '0'
# Use the action to generate a tag for itself
- name: Test action main1 (with_v true)
id: test_main1
uses: ./
env:
DRY_RUN: true
WITH_V: true
VERBOSE: true
DEFAULT_BUMP: minor # default
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test action main2 (with_v false)
id: test_main2
uses: ./
env:
DRY_RUN: true
WITH_V: false
VERBOSE: true
DEFAULT_BUMP: major
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test action main3 (with_v false)
id: test_main3
uses: ./
env:
DRY_RUN: true
WITH_V: false
VERBOSE: true
DEFAULT_BUMP: none
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test action main4 (with_v true)
id: test_main4
uses: ./
env:
DRY_RUN: true
WITH_V: true
VERBOSE: true
DEFAULT_BUMP: none
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test action main5 (with_v true)
id: test_main5
uses: ./
env:
DRY_RUN: true
WITH_V: true
VERBOSE: true
DEFAULT_BUMP: patch
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Use the action to generate a tag for itself
- name: Test action pre1-release (with_v true)
id: test_pre1
uses: ./
env:
DRY_RUN: true
WITH_V: true
PRERELEASE: true
PRERELEASE_SUFFIX: test
VERBOSE: true
DEFAULT_BUMP: minor # default
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test action pre2-release (with_v false)
id: test_pre2
uses: ./
env:
DRY_RUN: true
WITH_V: false
PRERELEASE: true
PRERELEASE_SUFFIX: test
VERBOSE: true
DEFAULT_BUMP: major
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Check if the action created the expected output
- name: Check if the tag would have been created
shell: bash
run: |
set -x
MAIN1_OUTPUT_TAG=${{ steps.test_main1.outputs.old_tag }}
MAIN1_OUTPUT_NEWTAG=${{ steps.test_main1.outputs.new_tag }}
MAIN1_OUTPUT_PART=${{ steps.test_main1.outputs.part }}
PRE1_OUTPUT_TAG=${{ steps.test_pre1.outputs.old_tag }}
PRE1_OUTPUT_NEWTAG=${{ steps.test_pre1.outputs.new_tag }}
PRE1_OUTPUT_PART=${{ steps.test_pre1.outputs.part }}
MAIN2_OUTPUT_TAG=${{ steps.test_main2.outputs.old_tag }}
MAIN2_OUTPUT_NEWTAG=${{ steps.test_main2.outputs.new_tag }}
MAIN2_OUTPUT_PART=${{ steps.test_main2.outputs.part }}
PRE2_OUTPUT_TAG=${{ steps.test_pre2.outputs.old_tag }}
PRE2_OUTPUT_NEWTAG=${{ steps.test_pre2.outputs.new_tag }}
PRE2_OUTPUT_PART=${{ steps.test_pre2.outputs.part }}
MAIN3_OUTPUT_TAG=${{ steps.test_main3.outputs.old_tag }}
MAIN3_OUTPUT_NEWTAG=${{ steps.test_main3.outputs.new_tag }}
MAIN3_OUTPUT_PART=${{ steps.test_main3.outputs.part }}
MAIN4_OUTPUT_TAG=${{ steps.test_main4.outputs.old_tag }}
MAIN4_OUTPUT_NEWTAG=${{ steps.test_main4.outputs.new_tag }}
MAIN4_OUTPUT_PART=${{ steps.test_main4.outputs.part }}
MAIN5_OUTPUT_TAG=${{ steps.test_main5.outputs.old_tag }}
MAIN5_OUTPUT_NEWTAG=${{ steps.test_main5.outputs.new_tag }}
MAIN5_OUTPUT_PART=${{ steps.test_main5.outputs.part }}
echo -e "> MAIN tests with_v, default bump:\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN1 with_v Tag: $MAIN1_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN1 with_v New tag: $MAIN1_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN1 with_v Part: $MAIN1_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> Pre-release tests with_v, default bump:\n" >> $GITHUB_STEP_SUMMARY
echo "PRE1 with_v Tag: $PRE1_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "PRE1 with_v New tag: $PRE1_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "PRE1 with_v Part: $PRE1_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> MAIN tests without_v, bump major:\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN2 without_v Tag: $MAIN2_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN2 without_v New tag: $MAIN2_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN2 without_v Part: $MAIN2_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> Pre-release tests without_v, bump major:\n" >> $GITHUB_STEP_SUMMARY
echo "PRE2 without_v Tag: $PRE2_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "PRE2 without_v New tag: $PRE2_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "PRE2 without_v Part: $PRE2_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> MAIN tests without_v, bump none: (should be the same old tag no change regardless of what original tag contains or not v)\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN3 without_v Tag: $MAIN3_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN3 without_v New tag: $MAIN3_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN3 without_v Part: $MAIN3_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> MAIN tests with_v, bump none: (should be the same old tag no change regardless of what original tag contains or not v)\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN4 with_v Tag: $MAIN4_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN4 with_v New tag: $MAIN4_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN4 with_v Part: $MAIN4_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> MAIN tests with_v, bump patch:\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN5 with_v Tag: $MAIN5_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN5 with_v New tag: $MAIN5_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN5 with_v Part: $MAIN5_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
# check that the original tag got bumped either major, minor, patch
verlte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
verlt() {
[ "$1" = "$2" ] && return 1 || verlte $1 $2
}
# needs to be a greater tag in default minor
main1="$(verlt $MAIN1_OUTPUT_TAG $MAIN1_OUTPUT_NEWTAG && true || false)"
pre1="$(verlt $PRE1_OUTPUT_TAG $PRE1_OUTPUT_NEWTAG && true || false)"
# needs to be a greater tag in bump major
main2="$(verlt $MAIN2_OUTPUT_TAG $MAIN2_OUTPUT_NEWTAG && true || false)"
pre2="$(verlt $PRE2_OUTPUT_TAG $PRE2_OUTPUT_NEWTAG && true || false)"
# needs to be the latest tag of the repo when bump is none
main3="$([ "$MAIN3_OUTPUT_TAG" = "$MAIN3_OUTPUT_NEWTAG" ] && true || false)"
main4="$([ "$MAIN4_OUTPUT_TAG" = "$MAIN4_OUTPUT_NEWTAG" ] && true || false)"
# needs to be a greater tag in bump patch
main5="$(verlt $MAIN5_OUTPUT_TAG $MAIN5_OUTPUT_NEWTAG && true || false)"
if $main1 && $pre1 && $main2 && $pre2 && $main3 && $main4 && $main5
then
echo -e "\n>>>>The tags were created correctly" >> $GITHUB_STEP_SUMMARY
else
echo -e "\n>>>>Tags NOT created correctly" >> $GITHUB_STEP_SUMMARY
exit 1
fi