-
Notifications
You must be signed in to change notification settings - Fork 15
160 lines (136 loc) · 4.72 KB
/
test-and-release.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
---
name: Test and Release
on:
push:
branches:
- '**'
tags-ignore:
- '**'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/[email protected]
with:
check_together: 'yes'
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup bats
uses: bats-core/[email protected]
with:
bats-version: 1.11.0
- name: Test
run: bats tests/*.bats
test-api-mode: # requires github API, didn't want to mock it
runs-on: ubuntu-latest
env:
github_token: ${{ github.token }}
steps:
- name: Checkout code # have to checkout to have the source code available
uses: actions/checkout@v4
- name: Remove .git directory # remove the git directory to make the testing valid
run: rm -rf .git/
- name: Test lookup version (with API)
id: version-lookup
env:
use_api: 'true'
run: ./version-lookup.sh
- name: Check lookup result
shell: bash
run: '[[ -n "${{ steps.version-lookup.outputs.CURRENT_VERSION }}" ]]'
- name: Test increment version (with API)
id: version-increment
run: ./version-increment.sh
env:
current_version: ${{ steps.version-lookup.outputs.CURRENT_VERSION }}
scheme: calver
use_api: 'true'
- name: Check increment result
shell: bash
run: '[[ "$(date +%Y.%-m)" == "$(echo "${{ steps.version-increment.outputs.VERSION }}" | cut -d "." -f 1-2)" ]]'
test-action-yml: # integration testing
needs:
- lint
- test
- test-api-mode
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code # have to checkout to have the source code available
uses: actions/checkout@v4
- name: Remove .git directory # remove the git directory to make the testing valid
shell: bash
run: rm -rf .git/
- name: Get next version via API
uses: ./
id: version-via-api
with:
scheme: 'calver'
use_api: true
- name: Checkout code
uses: actions/checkout@v4
- name: Get next version via Git
uses: ./
id: version-via-git
with:
scheme: 'calver'
use_api: false
- name: Check results agree
shell: bash
run: |
[[ "${{ steps.version-via-api.outputs.current-version }}" == "${{ steps.version-via-git.outputs.current-version }}" ]]
[[ "${{ steps.version-via-api.outputs.major-version }}" == "${{ steps.version-via-git.outputs.major-version }}" ]]
[[ "${{ steps.version-via-api.outputs.minor-version }}" == "${{ steps.version-via-git.outputs.minor-version }}" ]]
[[ "${{ steps.version-via-api.outputs.patch-version }}" == "${{ steps.version-via-git.outputs.patch-version }}" ]]
# Don't test the full version or pre-version, since the number of digits is likely to be different (9 via api vs. 7 via git)
- name: Get next version via Git with tag-prefix
uses: ./
id: version-prefix
with:
scheme: 'semver'
use_api: false
tag_prefix: 'foo/bar@'
- name: Check that it starts from 0.0.1 (since prefix doesn't exist)
shell: bash
run: |
[[ "${{ steps.version-prefix.outputs.current-version }}" == "0.0.0" ]]
[[ "${{ steps.version-prefix.outputs.major-version }}" == "0" ]]
[[ "${{ steps.version-prefix.outputs.minor-version }}" == "0" ]]
[[ "${{ steps.version-prefix.outputs.patch-version }}" == "1" ]]
[[ "${{ steps.version-prefix.outputs.version }}" = "0.0.1-"* ]]
[[ "${{ steps.version-prefix.outputs.prefixed-version }}" = "foo/[email protected]"* ]]
release:
needs:
- test-action-yml
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Lookup version
id: version-lookup
run: ./version-lookup.sh
- name: Increment version
id: version-increment
run: ./version-increment.sh
env:
current_version: ${{ steps.version-lookup.outputs.CURRENT_VERSION }}
scheme: calver
- name: Release version
uses: softprops/action-gh-release@v1
if: ${{ github.ref_name == github.event.repository.default_branch }}
with:
draft: false
prerelease: false
tag_name: "${{ steps.version-increment.outputs.VERSION }}"