Skip to content

Commit d00d843

Browse files
committed
Changes from discussion at standup
1 parent ecc89ba commit d00d843

2 files changed

Lines changed: 105 additions & 72 deletions

File tree

.github/workflows/cd_prod.yaml

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -56,75 +56,3 @@ jobs:
5656
git pull
5757
npm install
5858
pm2 startOrReload ecosystem.config.json --env production
59-
release:
60-
needs: deploy
61-
runs-on: ubuntu-latest
62-
permissions:
63-
contents: write
64-
steps:
65-
- name: Checkout (full history + tags)
66-
uses: actions/checkout@v4
67-
with:
68-
fetch-depth: 0
69-
70-
- name: Setup Node.js
71-
uses: actions/setup-node@v4
72-
with:
73-
node-version: "24"
74-
75-
- name: Derive next version and create the release
76-
shell: bash
77-
env:
78-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79-
# Untrusted input — read from env, never inline into the script.
80-
HEAD_COMMIT_MSG: ${{ github.event.head_commit.message }}
81-
run: |
82-
set -e
83-
84-
# Never release the same commit twice (idempotent re-runs).
85-
EXISTING_TAG="$(git tag -l 'v*' --points-at HEAD | head -n1)"
86-
if [ -n "$EXISTING_TAG" ]; then
87-
echo "Commit already released as ${EXISTING_TAG} — nothing to do."
88-
exit 0
89-
fi
90-
91-
# Resolve the bump level from the commit message; default patch.
92-
LEVEL="patch"
93-
if printf '%s' "$HEAD_COMMIT_MSG" | grep -qiE 'BREAKING CHANGE|\[major\]|(^|[^a-z])[a-z]+(\([^)]*\))?!:'; then
94-
LEVEL="major"
95-
elif printf '%s' "$HEAD_COMMIT_MSG" | grep -qiE '\[minor\]|(^|[^a-z])feat(\([^)]*\))?:'; then
96-
LEVEL="minor"
97-
fi
98-
echo "Bump level resolved from commit message: ${LEVEL}"
99-
100-
# Find the highest existing release tag (version-aware sort).
101-
LATEST_TAG="$(git tag -l 'v*' --sort=-v:refname | head -n1)"
102-
103-
if [ -z "$LATEST_TAG" ]; then
104-
# First release: seed from package.json (1.1.0 -> v1.1.0).
105-
NEXT="$(node -p "require('./package.json').version")"
106-
echo "No prior release tag — seeding first release from package.json: ${NEXT}"
107-
else
108-
# Bump the latest tag with npm's semver engine.
109-
BASE="${LATEST_TAG#v}"
110-
TMP="$(mktemp -d)"
111-
printf '{"name":"x","version":"%s"}\n' "$BASE" > "$TMP/package.json"
112-
( cd "$TMP" && npm version "$LEVEL" --no-git-tag-version >/dev/null )
113-
NEXT="$(node -p "require('${TMP}/package.json').version")"
114-
rm -rf "$TMP"
115-
echo "Latest release ${LATEST_TAG} -> next version ${NEXT}"
116-
fi
117-
118-
TAG="v${NEXT}"
119-
120-
if gh release view "$TAG" >/dev/null 2>&1; then
121-
echo "Release $TAG already exists — nothing to do."
122-
exit 0
123-
fi
124-
125-
gh release create "$TAG" \
126-
--target "$GITHUB_SHA" \
127-
--title "$TAG" \
128-
--generate-notes \
129-
--latest
130-
echo "Published release $TAG"
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Release on push to main
2+
3+
# Cuts a GitHub Release (and its tag) every time main advances. RERUM has no
4+
# development branch, so any push to main — a merged PR or a direct commit — is a
5+
# promotion to production and gets a release.
6+
#
7+
# The version is DERIVED, not stored: this reads the highest existing v* release
8+
# tag and bumps it. There is no version-bump commit pushed to any branch, so no
9+
# bot needs write access to a protected branch.
10+
#
11+
# - First release ever (no v* tag yet): seed from package.json. With
12+
# package.json at 1.1.0 this publishes v1.1.0 (matching RERUM_API_VERSION).
13+
# - Every release after that: bump the latest tag. Default is a patch bump
14+
# (v1.1.0 -> v1.1.1). The push/merge commit can opt into a larger bump via
15+
# trigger words in its message:
16+
# "BREAKING CHANGE" / "type!:" / "[major]" -> major (v1.1.0 -> v2.0.0)
17+
# "feat:" / "feat(scope):" / "[minor]" -> minor (v1.1.0 -> v1.2.0)
18+
# anything else (default) -> patch (v1.1.0 -> v1.1.1)
19+
#
20+
# package.json's version is no longer the source of truth after the first
21+
# release — the release tags are. It is kept only to seed that first release.
22+
#
23+
# This is independent of cd_prod.yaml (test + deploy); it does not gate on tests
24+
# or the deploy. Idempotent: if the current commit already carries a v* tag, or
25+
# the computed tag already exists, the run is a no-op. Safe to re-run via
26+
# workflow_dispatch.
27+
28+
on:
29+
push:
30+
branches: main
31+
workflow_dispatch:
32+
33+
permissions:
34+
contents: write
35+
36+
jobs:
37+
release:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout (full history + tags)
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 0
44+
45+
- name: Setup Node.js
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version: "24"
49+
50+
- name: Derive next version and create the release
51+
shell: bash
52+
env:
53+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
# Untrusted input — read from env, never inline into the script.
55+
HEAD_COMMIT_MSG: ${{ github.event.head_commit.message }}
56+
run: |
57+
set -e
58+
59+
# Never release the same commit twice (idempotent re-runs / manual dispatch).
60+
EXISTING_TAG="$(git tag -l 'v*' --points-at HEAD | head -n1)"
61+
if [ -n "$EXISTING_TAG" ]; then
62+
echo "Commit already released as ${EXISTING_TAG} — nothing to do."
63+
exit 0
64+
fi
65+
66+
# Resolve the bump level from the commit message; default patch.
67+
LEVEL="patch"
68+
if printf '%s' "$HEAD_COMMIT_MSG" | grep -qiE 'BREAKING CHANGE|\[major\]|(^|[^a-z])[a-z]+(\([^)]*\))?!:'; then
69+
LEVEL="major"
70+
elif printf '%s' "$HEAD_COMMIT_MSG" | grep -qiE '\[minor\]|(^|[^a-z])feat(\([^)]*\))?:'; then
71+
LEVEL="minor"
72+
fi
73+
echo "Bump level resolved from commit message: ${LEVEL}"
74+
75+
# Find the highest existing release tag (version-aware sort).
76+
LATEST_TAG="$(git tag -l 'v*' --sort=-v:refname | head -n1)"
77+
78+
if [ -z "$LATEST_TAG" ]; then
79+
# First release: seed from package.json (1.1.0 -> v1.1.0).
80+
NEXT="$(node -p "require('./package.json').version")"
81+
echo "No prior release tag — seeding first release from package.json: ${NEXT}"
82+
else
83+
# Derive the next version by bumping the latest tag with npm's semver engine.
84+
BASE="${LATEST_TAG#v}"
85+
TMP="$(mktemp -d)"
86+
printf '{"name":"x","version":"%s"}\n' "$BASE" > "$TMP/package.json"
87+
( cd "$TMP" && npm version "$LEVEL" --no-git-tag-version >/dev/null )
88+
NEXT="$(node -p "require('${TMP}/package.json').version")"
89+
rm -rf "$TMP"
90+
echo "Latest release ${LATEST_TAG} -> next version ${NEXT}"
91+
fi
92+
93+
TAG="v${NEXT}"
94+
95+
if gh release view "$TAG" >/dev/null 2>&1; then
96+
echo "Release $TAG already exists — nothing to do."
97+
exit 0
98+
fi
99+
100+
gh release create "$TAG" \
101+
--target "$GITHUB_SHA" \
102+
--title "$TAG" \
103+
--generate-notes \
104+
--latest
105+
echo "Published release $TAG"

0 commit comments

Comments
 (0)