Skip to content

Commit 0579f47

Browse files
committed
feat: validate tag before anything
Signed-off-by: Adrien Mannocci <[email protected]>
1 parent d436d1e commit 0579f47

File tree

4 files changed

+85
-23
lines changed

4 files changed

+85
-23
lines changed

.github/workflows/pre-post-release.yml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ on:
1717
- pre
1818
- post
1919
required: true
20-
workflow_dispatch:
21-
inputs:
22-
ref:
23-
description: 'Branch or tag ref to run the workflow on'
24-
required: true
25-
default: 'main'
26-
version:
27-
description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps'
28-
required: true
29-
phase:
30-
description: 'Pre or post release phase'
31-
type: choice
32-
options:
33-
- pre
34-
- post
35-
default: 'pre'
3620

3721
env:
3822
RELEASE_VERSION: ${{ inputs.version }}
@@ -45,9 +29,23 @@ concurrency:
4529
group: ${{ github.workflow }}
4630

4731
jobs:
48-
create_pr:
32+
validate-tag:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 0
39+
- name: Validate tag does not exist on current commit
40+
uses: ./.github/workflows/validate-tag
41+
with:
42+
tag: ${{ env.RELEASE_VERSION }}
43+
44+
create-pr:
4945
name: "Bump versions and create PR"
5046
runs-on: ubuntu-latest
47+
needs:
48+
- validate-tag
5149
permissions:
5250
contents: write
5351
steps:

.github/workflows/pre-release.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Pre release
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
ref:
8+
description: 'Branch or tag ref to run the workflow on'
9+
required: true
10+
default: 'main'
11+
version:
12+
description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps'
13+
required: true
14+
15+
concurrency:
16+
group: ${{ github.workflow }}
17+
18+
jobs:
19+
pre-release:
20+
name: "Bump versions and create PR"
21+
uses: ./.github/workflows/pre-post-release.yml
22+
with:
23+
ref: ${{ inputs.ref }}
24+
version: ${{ inputs.version }}
25+
phase: 'pre'
26+
secrets: inherit

.github/workflows/release.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
---
22
name: Release
33

4-
permissions:
5-
contents: read
6-
74
on:
85
workflow_dispatch:
96
inputs:
@@ -19,10 +16,27 @@ on:
1916
default: false
2017
type: boolean
2118

19+
permissions:
20+
contents: read
21+
2222
jobs:
23+
validate-tag:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
- name: Validate tag does not exist on current commit
31+
uses: ./.github/workflows/validate-tag
32+
with:
33+
tag: ${{ env.RELEASE_VERSION }}
34+
2335
release:
2436
name: Release
2537
runs-on: ubuntu-latest
38+
needs:
39+
- validate-tag
2640
steps:
2741
- id: buildkite
2842
name: Run Release
@@ -35,7 +49,7 @@ jobs:
3549
waitFor: true
3650
printBuildLogs: false
3751
buildEnvVars: |
38-
ref=${{ inputs.ref || 'main' }}
52+
ref=${{ inputs.ref }}
3953
dry_run=${{ inputs.dry_run || 'false' }}
4054
4155
- if: ${{ success() }}
@@ -63,9 +77,8 @@ jobs:
6377
name: "Bump versions and create PR"
6478
needs:
6579
- release
66-
permissions:
67-
contents: write
6880
uses: ./.github/workflows/pre-post-release.yml
81+
if: inputs.dry_run == 'false'
6982
with:
7083
ref: ${{ inputs.ref }}
7184
version: ${{ inputs.version }}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
3+
name: validate-tag
4+
description: Validate tag format
5+
6+
inputs:
7+
tag:
8+
description: 'Tag to validate'
9+
required: true
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Validate tag does not exist on current commit
15+
id: validate-tag
16+
shell: 'bash'
17+
run: |
18+
if ! [ $(echo "${{ inputs.tag }}" | grep -P "(\d{1,2})\.(\d{1,2})\.(\d{1,2})") ]; then
19+
echo "Tag should be a SemVer format"
20+
exit 1
21+
fi
22+
if [ $(git tag -l "${{ inputs.tag }}") ]; then
23+
echo "The tag ${{ inputs.tag }} already exists"
24+
exit 1
25+
fi

0 commit comments

Comments
 (0)