-
Notifications
You must be signed in to change notification settings - Fork 365
68 lines (59 loc) · 2.02 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
name: Test
# This workflow tests the tag action and can be used on PRs to detect (some) breaking changes.
on:
pull_request:
types:
- opened
- edited
- reopened
- synchronize
push:
branches:
- master
workflow_dispatch:
jobs:
test-action:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: '0'
# Use the action to generate a tag for itself
- name: Test action
id: test
uses: ./
env:
DRY_RUN: true
WITH_V: true
PRERELEASE_SUFFIX: test
VERBOSE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Check if the action created the expected output
- name: Check if the tag would have been created
run: |
OUTPUT_TAG = ${{ steps.test.outputs.tag }}
OUTPUT_NEWTAG = ${{ steps.test.outputs.new_tag }}
OUTPUT_PART = ${{ steps.test.outputs.part }}
echo "Outputs from running the action:"
echo "Tag: $OUTPUT_TAG"
echo "New tag: $OUTPUT_NEWTAG"
echo "Part: $OUTPUT_PART"
# Work out what the new tag should be
INCREMENT=$(echo $TAG | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')
CORRECT_TAG="$INCREMENT-test.0"
# Bash if statement that checks that the OUTPUT_NEWTAG value is the same as the
# OUTPUT_TAG action but one number higher and with a suffix of -test.*
if [[ $OUTPUT_NEWTAG == $CORRECT_TAG ]]; then
echo "The tag was created correctly"
else
echo "The tag was not created correctly, expected $CORRECT_TAG got $OUTPUT_NEWTAG"
exit 1
fi
if $OUTPUT_NEWTAG ; then
echo "The tag was created as expected"
exit 0
else
echo "The action did not create a new tag"
exit 1
fi