Skip to content

Commit 539413b

Browse files
committed
refactor: use a GitHub actions and a more permissive regex
1 parent 6a2ad8b commit 539413b

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

.github/workflows/merge-release-tag.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ name: Merge Release Tag
33
on:
44
push:
55
tags:
6-
- 'mongosh@[0-9]+.[0-9]+.[0-9]+'
6+
- 'mongosh@[0-9]+.[0-9]+.*'
77
workflow_dispatch:
88

9+
permissions:
10+
contents: none # We use the github app to checkout and push tags
11+
912
jobs:
1013
merge-release-tag:
1114
runs-on: ubuntu-latest
@@ -24,31 +27,31 @@ jobs:
2427
token: ${{ steps.app-token.outputs.token }}
2528

2629
- name: Extract version from tag
27-
id: version
28-
run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF} | sed -n 's/refs\/tags\/mongosh@\([0-9]\+\.[0-9]\+\.[0-9]\+\)/\1/p')" >> $GITHUB_ENV
30+
uses: actions-ecosystem/action-regex-match@d50fd2e7a37d0e617aea3d7ada663bd56862b9cc
31+
id: version-match
32+
with:
33+
text: ${{ github.ref }}
34+
regex: 'refs/tags/mongosh@([0-9]+\.[0-9]+\.*)'
2935

3036
- name: Validate release version
3137
shell: bash
38+
id: validate
3239
run: |
33-
if [ -z "${RELEASE_VERSION}" ]; then
34-
echo "RELEASE_TAG is not set or is empty"
40+
if [[ -z "${{ steps.version-match.outputs.group1 }}" ]]; then
41+
echo "Error: Could not extract version from tag"
3542
exit 1
3643
fi
3744
38-
if git rev-parse "release/v$RELEASE_VERSION" >/dev/null 2>&1; then
45+
if git rev-parse "release/v${{ steps.version-match.outputs.group1 }}" >/dev/null 2>&1; then
3946
echo "Error: Branch release/v$RELEASE_TAG already exists"
4047
echo "If this version has already been released consider using a different one."
4148
exit 1
4249
fi
50+
echo "::set-output name=version::${{ steps.version-match.outputs.group1 }}"
4351
44-
- name: Create and push branch from tag
45-
run: |
46-
git checkout -b release/v$RELEASE_VERSION ${{ github.ref }}
47-
git push origin release/v$RELEASE_VERSION
48-
49-
- name: Merge branch into main
52+
- name: Merge release tag into main
5053
run: |
54+
git checkout -b release/v${{ steps.validate.outputs.version }} ${{ github.ref }}
5155
git checkout main
52-
git merge release/v$RELEASE_VERSION
56+
git merge release/v${{ steps.validate.outputs.version }}
5357
git push origin main
54-
git push -d origin release/v$RELEASE_VERSION

0 commit comments

Comments
 (0)