Skip to content

Commit ad031fa

Browse files
authored
Merge pull request #26 from DiamondLightSource/automatic_semver_tag_action
Creating an action to automatically tag main branch with semver
2 parents 17676e9 + b6ddf79 commit ad031fa

File tree

4 files changed

+78
-13
lines changed

4 files changed

+78
-13
lines changed

.github/workflows/docker-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
5858
run: |
5959
TAG=$(git describe --tags --exact-match || echo "")
60-
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
60+
echo "LATEST_TAG=$TAG" >> $GITHUB_ENV
6161
6262
- name: Create tags for publishing image
6363
id: meta

.github/workflows/semver-tag.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Auto Tag with SemVer
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
jobs:
9+
tag-main:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Fetch all tags
21+
run: git fetch --tags --force
22+
23+
- name: Get latest semver tag
24+
id: get_latest_tag
25+
run: |
26+
# Get all tags and filter for valid semver tags (vX.Y.Z format)
27+
LATEST_TAG=$(git tag -l '[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -n 1)
28+
29+
# If no valid semver tags exist, start with 0.0.0
30+
if [ -z "$LATEST_TAG" ]; then
31+
echo "::error::No semantic versioning tags found in the repository. Please create an initial tag (e.g., 0.0.0) manually."
32+
exit 1
33+
fi
34+
35+
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
36+
37+
# Extract the version numbers
38+
VERSION=${LATEST_TAG}
39+
MAJOR=$(echo $VERSION | cut -d. -f1)
40+
MINOR=$(echo $VERSION | cut -d. -f2)
41+
PATCH=$(echo $VERSION | cut -d. -f3)
42+
43+
# Increment patch version
44+
NEW_PATCH=$((PATCH + 1))
45+
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
46+
47+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
48+
49+
- name: Create new tag
50+
id: create_tag
51+
run: |
52+
NEW_TAG="${{ steps.get_latest_tag.outputs.new_version }}"
53+
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
54+
55+
git config --local user.email "action@github.com"
56+
git config --local user.name "GitHub Action"
57+
git tag -a $NEW_TAG -m "Auto-incremented patch version"
58+
59+
- name: Push tag
60+
run: |
61+
git push origin ${{ steps.create_tag.outputs.new_tag }}
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+

package-lock.json

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "daedalus",
33
"private": true,
4-
"version": "0.0.5",
4+
"version": "0.0.7",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -15,7 +15,7 @@
1515
"preview": "vite preview"
1616
},
1717
"dependencies": {
18-
"@diamondlightsource/cs-web-lib": "^0.9.7",
18+
"@diamondlightsource/cs-web-lib": "^0.9.8",
1919
"@emotion/react": "^11.11.4",
2020
"@emotion/styled": "^11.11.5",
2121
"@mui/icons-material": "^5.15.17",

0 commit comments

Comments
 (0)