Skip to content

Commit 1bf9f82

Browse files
Merge pull request #372 from Staffbase/make-release-version-template-monorepoable
2 parents 2ce52e4 + 8214544 commit 1bf9f82

File tree

2 files changed

+55
-29
lines changed

2 files changed

+55
-29
lines changed

.github/workflows/template_release_version.yml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ name: Release Version Detector
33
on:
44
workflow_call:
55
inputs:
6+
tag-prefix:
7+
required: false
8+
type: string
9+
default: 'v'
10+
tag-suffix:
11+
required: false
12+
type: string
13+
default: ''
614
format:
715
required: false
816
type: string
@@ -15,7 +23,6 @@ on:
1523

1624
jobs:
1725
new_version:
18-
1926
name: Get new release version
2027
runs-on: ubuntu-24.04
2128

@@ -29,6 +36,8 @@ jobs:
2936
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3037
id: set_version
3138
run: |
39+
TAG_PREFIX=${{ inputs['tag-prefix'] }}
40+
TAG_SUFFIX=${{ inputs['tag-suffix'] }}
3241
DATE=$(date +"%Y%m%d")
3342
YEAR=$(date +"%Y")
3443
WEEK=$(date +"%-V")
@@ -41,10 +50,19 @@ jobs:
4150
fi
4251
4352
if [[ $(gh release view -R ${{ github.repository }} 2>&1) =~ "release not found" ]]; then
44-
COUNTER=1
53+
COUNTER=0
4554
else
46-
# fetch last tag from github
47-
OLD_VERSION=`gh api repos/${{ github.repository }}/releases/latest | jq .tag_name -r`
55+
# fetch last tag name from github releases which are not drafts or pre-releases and starts with the given prefix
56+
OLD_TAG_NAME=$(gh release list -R ${{ github.repository }} --limit 100 --exclude-drafts --exclude-pre-releases --json tagName --jq "[.[] | select(.tagName | startswith(\"${TAG_PREFIX}\") and endswith(\"${TAG_SUFFIX}\"))] | .[0].tagName")
57+
58+
echo "Last tag name: ${OLD_TAG_NAME}"
59+
60+
# remove prefix and suffix
61+
OLD_VERSION=${OLD_TAG_NAME#${TAG_PREFIX}}
62+
OLD_VERSION=${OLD_VERSION%${TAG_SUFFIX}}
63+
64+
echo "Last version: ${OLD_VERSION}"
65+
4866
PARTS=(${OLD_VERSION//./ })
4967
COUNTER=${PARTS[2]}
5068
MINOR_FROM_LAST_TAG=${PARTS[1]}
@@ -60,15 +78,21 @@ jobs:
6078
fi
6179
6280
# check if valid tag
63-
pattern="v[0-9]+.[0-9]+.[0-9]+$"
81+
pattern="[0-9]+.[0-9]+.[0-9]+$"
6482
if ! [[ $OLD_VERSION =~ $pattern ]]; then
6583
COUNTER=0
6684
fi
67-
68-
# increase Version
69-
COUNTER=$((COUNTER+1))
7085
fi
7186
72-
echo "next_version=${YEAR}.${MINOR}.${COUNTER}" >> $GITHUB_OUTPUT
73-
echo "next_tag=v${YEAR}.${MINOR}.${COUNTER}" >> $GITHUB_OUTPUT
87+
# increase Version
88+
COUNTER=$((COUNTER+1))
89+
90+
NEW_VERSION="${YEAR}.${MINOR}.${COUNTER}"
91+
NEW_TAG="${TAG_PREFIX}${NEW_VERSION}${TAG_SUFFIX}"
92+
93+
echo "Next version: ${NEW_VERSION}"
94+
echo "Next tag: ${NEW_TAG}"
95+
96+
echo "next_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
97+
echo "next_tag=${NEW_TAG}" >> $GITHUB_OUTPUT
7498
shell: bash

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ You can find all possible template workflows in the directory `.github/workflows
99
```yml
1010
name: <your name>
1111

12-
on:
13-
...
12+
on: ...
1413

1514
jobs:
1615
<action name>:
1716
uses: Staffbase/gha-workflows/.github/workflows/template_*.yml@v9.0.0
18-
with:
19-
...
17+
with: ...
2018
```
2119
2220
## Example Configurations 🔧
@@ -193,7 +191,7 @@ jobs:
193191
# optional: name of the branch where it should check, default: main
194192
branch: 'master'
195193
# optional: file path suffixes (comma seperated) to filter the test files
196-
path-suffixes: ".spec.ts,.spec.tsx,.test.ts,.test.tsx"
194+
path-suffixes: '.spec.ts,.spec.tsx,.test.ts,.test.tsx'
197195
# prefix of the test run which should be filtered out
198196
prefix: 'test-'
199197
secrets:
@@ -212,21 +210,21 @@ jobs:
212210
213211
```yml
214212
name: GitOps
215-
on: [ push ]
213+
on: [push]
216214

217215
jobs:
218216
gitops:
219217
uses: Staffbase/gha-workflows/.github/workflows/template_gitops.yml@v9.0.0
220218
with:
221219
# optional: host of the docker registry, default: "registry.staffbase.com"
222-
docker-registry: "<your-registry>"
220+
docker-registry: '<your-registry>'
223221
# optional: list of build-time variables
224222
docker-build-args: |
225223
"any important args"
226224
# optional: set the target stage to build
227-
docker-build-target: "any target"
225+
docker-build-target: 'any target'
228226
# optional: set the provenance level of the docker build, default: "false"
229-
docker-build-provenance: "<your-provenance-level>"
227+
docker-build-provenance: '<your-provenance-level>'
230228
# optional: should the last stage image be retagged for the release image, default: false
231229
docker-disable-retagging: true
232230
# optional: path to the Dockerfile, default: ./Dockerfile
@@ -238,11 +236,11 @@ jobs:
238236
# optional: organization of the gitops repository, default: github.repository_owner
239237
gitops-organization: <your-organization>
240238
# optional: repository where to update the files, default: mops
241-
gitops-repository: "<your-repository>"
239+
gitops-repository: '<your-repository>'
242240
# optional: user which does the commit, default: "staffbase-actions"
243-
gitops-user: "<your-user>"
241+
gitops-user: '<your-user>'
244242
# optional: email of the user which does the commit, default: "staffbase-actions[bot]@users.noreply.github.com"
245-
gitops-email: "<your-email>"
243+
gitops-email: '<your-email>'
246244
# optional: files which should be updated for dev
247245
gitops-dev: |-
248246
your files
@@ -432,6 +430,10 @@ jobs:
432430
new_version:
433431
uses: Staffbase/gha-workflows/.github/workflows/template_release_version.yml@v9.0.0
434432
with:
433+
# optional: prefix of the tag in order to find the last release; this is useful for multi artifact/service repositories, default: 'v'
434+
tag-prefix: 'app-v'
435+
# optional: suffix of the tag in order to find the last release; this is useful for multi artifact/service repositories, default: '' (empty string)
436+
tag-suffix: '-native'
435437
# optional: format of the version, default: weekly
436438
format: 'quarterly'
437439
```
@@ -476,7 +478,7 @@ name: Stale PRs
476478
477479
on:
478480
schedule:
479-
- cron: "0 0 * * 1-5"
481+
- cron: '0 0 * * 1-5'
480482
481483
jobs:
482484
stale:
@@ -511,9 +513,9 @@ on:
511513
branches:
512514
- 'main'
513515
paths:
514-
- "docs/**"
515-
- "mkdocs.yml"
516-
- ".github/workflows/techdocs.yaml"
516+
- 'docs/**'
517+
- 'mkdocs.yml'
518+
- '.github/workflows/techdocs.yaml'
517519
518520
jobs:
519521
techdocs:
@@ -540,9 +542,9 @@ on:
540542
branches:
541543
- 'main'
542544
paths:
543-
- "docs/**"
544-
- "mkdocs.yml"
545-
- ".github/workflows/techdocs.yaml"
545+
- 'docs/**'
546+
- 'mkdocs.yml'
547+
- '.github/workflows/techdocs.yaml'
546548
547549
jobs:
548550
techdocs:

0 commit comments

Comments
 (0)