Skip to content

Commit 961d734

Browse files
committed
fix: added automated versioning
1 parent 82544e0 commit 961d734

File tree

4 files changed

+147
-3
lines changed

4 files changed

+147
-3
lines changed

.github/workflows/build_devnet.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
name: Build and Push Devnet Image
22

33
on:
4-
push:
4+
workflow_run:
5+
workflows: ['Semantic Versioning']
6+
types: [completed]
57
branches: [develop]
68
# also allow manual runs
79
workflow_dispatch:
810

911
jobs:
1012
build:
13+
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
1114
runs-on: ubuntu-latest
1215
permissions:
1316
contents: read
1417

1518
steps:
1619
- name: Checkout source
1720
uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
1823

1924
- uses: docker/setup-qemu-action@v3
2025
- uses: docker/setup-buildx-action@v3

.github/workflows/sem_ver.yaml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Semantic Versioning
2+
3+
on:
4+
push:
5+
branches: [ develop ]
6+
7+
permissions:
8+
contents: write
9+
10+
concurrency:
11+
group: semver-${{ github.ref }}
12+
cancel-in-progress: false
13+
14+
env:
15+
VERSION_FILE: package.json
16+
17+
jobs:
18+
release:
19+
# Extra safety: don't run on the bot's own version bump commits (even though [skip ci] should skip already)
20+
if: github.actor != 'github-actions[bot]'
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0 # fetch all history + tags
28+
29+
- name: Configure git
30+
run: |
31+
git config user.name "github-actions[bot]"
32+
git config user.email "github-actions[bot]@users.noreply.github.com"
33+
34+
- name: Fetch tags
35+
run: git fetch --force --tags
36+
37+
# Bootstrap only when there are no semver tags yet
38+
- name: Bootstrap initial tag (only if none exist)
39+
id: bootstrap
40+
shell: bash
41+
run: |
42+
set -euo pipefail
43+
44+
latest="$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n1 || true)"
45+
if [[ -n "$latest" ]]; then
46+
echo "bootstrapped=false" >> "$GITHUB_OUTPUT"
47+
exit 0
48+
fi
49+
50+
if [[ ! -f "$VERSION_FILE" ]]; then
51+
echo "VERSION_FILE not found: $VERSION_FILE" >&2
52+
exit 1
53+
fi
54+
55+
detected="$(grep -oE "v?[0-9]+\.[0-9]+\.[0-9]+" "$VERSION_FILE" | head -n1 || true)"
56+
if [[ -z "$detected" ]]; then
57+
echo "No semver found in $VERSION_FILE" >&2
58+
exit 1
59+
fi
60+
[[ "$detected" == v* ]] || detected="v$detected"
61+
62+
echo "No semver tags found. Bootstrapping tag: $detected"
63+
git tag -a "$detected" -m "Bootstrap $detected"
64+
git push origin "$detected"
65+
66+
echo "bootstrapped=true" >> "$GITHUB_OUTPUT"
67+
68+
- name: Calculate next version
69+
if: steps.bootstrap.outputs.bootstrapped != 'true'
70+
id: semver
71+
uses: paulhatch/semantic-version@v5.4.0
72+
with:
73+
tag_prefix: "v"
74+
# Conventional Commits defaults (major if !: or BREAKING CHANGE:, minor if feat:)
75+
major_pattern: "/!:|BREAKING CHANGE:/"
76+
minor_pattern: "/feat:/"
77+
search_commit_body: true
78+
version_format: "${major}.${minor}.${patch}"
79+
80+
- name: Guard (do nothing if tag already exists)
81+
if: steps.bootstrap.outputs.bootstrapped != 'true'
82+
id: guard
83+
shell: bash
84+
run: |
85+
set -euo pipefail
86+
tag="${{ steps.semver.outputs.version_tag }}"
87+
if git show-ref --tags --verify --quiet "refs/tags/$tag"; then
88+
echo "Tag already exists: $tag"
89+
echo "should_release=false" >> "$GITHUB_OUTPUT"
90+
exit 0
91+
fi
92+
echo "should_release=true" >> "$GITHUB_OUTPUT"
93+
94+
- name: Update version file
95+
if: steps.guard.outputs.should_release == 'true'
96+
env:
97+
NEW_TAG: ${{ steps.semver.outputs.version_tag }}
98+
run: |
99+
set -euo pipefail
100+
python - <<'PY'
101+
import json, os
102+
from pathlib import Path
103+
104+
path = Path(os.environ["VERSION_FILE"])
105+
new_tag = os.environ["NEW_TAG"]
106+
# Strip leading 'v' for package.json (uses bare semver)
107+
version = new_tag.lstrip("v")
108+
109+
data = json.loads(path.read_text(encoding="utf-8"))
110+
data["version"] = version
111+
path.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
112+
print(f"Updated {path} -> {version}")
113+
PY
114+
115+
- name: Commit + tag + push
116+
if: steps.guard.outputs.should_release == 'true'
117+
run: |
118+
set -euo pipefail
119+
tag="${{ steps.semver.outputs.version_tag }}"
120+
121+
git add "$VERSION_FILE"
122+
if ! git diff --cached --quiet; then
123+
# GitHub supports skipping workflow runs via commit message keywords
124+
git commit -m "chore(release): ${tag} [skip ci]"
125+
fi
126+
127+
git tag -a "$tag" -m "Release $tag"
128+
129+
# Push commit (if any) and annotated tags together
130+
git push origin HEAD:main --follow-tags
131+
132+
- name: Summary
133+
if: steps.bootstrap.outputs.bootstrapped != 'true'
134+
run: |
135+
echo "Previous Version: ${{ steps.semver.outputs.previous_version }}"
136+
echo "New Tag: ${{ steps.semver.outputs.version_tag }}"
137+
echo "Version Type: ${{ steps.semver.outputs.version_type }}"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "deeploy-dapp",
33
"private": true,
44
"type": "module",
5-
"version": "0.1.2",
5+
"version": "1.1.0",
66
"scripts": {
77
"dev": "next dev --turbo --experimental-https",
88
"dev:logs": "NEXT_DEBUG=1 next dev --turbo --experimental-https",

src/shared/NetworkAndStatus.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { ping } from '@lib/api/backend';
33
import { useQuery } from '@tanstack/react-query';
44
import clsx from 'clsx';
55

6+
import pkg from '../../package.json';
7+
68
function NetworkAndStatus() {
79
const { data, error, isLoading } = useQuery({
810
queryKey: ['ping'],
911
queryFn: ping,
1012
retry: false,
1113
});
12-
const appVersion = process.env.NEXT_PUBLIC_APP_VERSION ?? '';
14+
const appVersion = pkg.version; //process.env.NEXT_PUBLIC_APP_VERSION ?? '';
1315

1416
return (
1517
<div className="col gap-2">

0 commit comments

Comments
 (0)