Skip to content

Commit 3bb6d26

Browse files
committed
GH-2: add workflow to release to npm
1 parent 1829da7 commit 3bb6d26

4 files changed

Lines changed: 237 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: "Version bump type"
8+
required: true
9+
default: "patch"
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
- custom
16+
custom_version:
17+
description: "Custom version (only used if type is 'custom')"
18+
required: false
19+
type: string
20+
21+
jobs:
22+
release:
23+
runs-on: ubuntu-latest
24+
25+
permissions:
26+
contents: write
27+
id-token: write
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
token: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: "22"
40+
registry-url: "https://registry.npmjs.org"
41+
42+
- name: Install dependencies
43+
run: npm ci
44+
45+
- name: Run tests
46+
run: npm test
47+
48+
- name: Run lint check
49+
run: npm run lint:check
50+
51+
- name: Determine version
52+
id: version
53+
run: |
54+
CURRENT_VERSION=$(node -p "require('./package.json').version")
55+
56+
if [ "${{ github.event.inputs.version_type }}" == "custom" ]; then
57+
NEW_VERSION="${{ github.event.inputs.custom_version }}"
58+
else
59+
NEW_VERSION=$(node -p "
60+
const v = '${CURRENT_VERSION}'.split('.');
61+
const type = '${{ github.event.inputs.version_type }}';
62+
if (type === 'major') {
63+
v[0] = parseInt(v[0]) + 1;
64+
v[1] = 0;
65+
v[2] = 0;
66+
} else if (type === 'minor') {
67+
v[1] = parseInt(v[1]) + 1;
68+
v[2] = 0;
69+
} else {
70+
v[2] = parseInt(v[2]) + 1;
71+
}
72+
v.join('.');
73+
")
74+
fi
75+
76+
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
77+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
78+
echo "Current version: $CURRENT_VERSION"
79+
echo "New version: $NEW_VERSION"
80+
81+
- name: Validate version
82+
run: |
83+
if [ -z "${{ steps.version.outputs.new_version }}" ]; then
84+
echo "Error: New version is empty"
85+
exit 1
86+
fi
87+
88+
if [ "${{ steps.version.outputs.current_version }}" == "${{ steps.version.outputs.new_version }}" ]; then
89+
echo "Error: New version is the same as current version"
90+
exit 1
91+
fi
92+
93+
- name: Update package.json version
94+
run: |
95+
node -e "
96+
const fs = require('fs');
97+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
98+
pkg.version = '${{ steps.version.outputs.new_version }}';
99+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 4) + '\n');
100+
console.log('Updated package.json to version', pkg.version);
101+
"
102+
103+
- name: Generate changelog
104+
run: |
105+
NEW_VERSION="${{ steps.version.outputs.new_version }}"
106+
DATE=$(date +%Y-%m-%d)
107+
108+
if [ -f CHANGELOG.md ]; then
109+
# Update existing changelog
110+
TEMP_FILE=$(mktemp)
111+
112+
# Extract header (first 6 lines)
113+
head -n 6 CHANGELOG.md > "$TEMP_FILE"
114+
115+
# Add new version entry
116+
echo "" >> "$TEMP_FILE"
117+
echo "## [$NEW_VERSION] - $DATE" >> "$TEMP_FILE"
118+
echo "" >> "$TEMP_FILE"
119+
echo "### Added" >> "$TEMP_FILE"
120+
echo "- Release version $NEW_VERSION" >> "$TEMP_FILE"
121+
echo "" >> "$TEMP_FILE"
122+
123+
# Append rest of changelog (skip header)
124+
tail -n +7 CHANGELOG.md >> "$TEMP_FILE"
125+
126+
# Add version link
127+
echo "" >> "$TEMP_FILE"
128+
echo "[$NEW_VERSION]: https://github.com/renderorange/types-class/releases/tag/v$NEW_VERSION" >> "$TEMP_FILE"
129+
130+
mv "$TEMP_FILE" CHANGELOG.md
131+
else
132+
# Create new changelog
133+
cat > CHANGELOG.md << 'EOF'
134+
# Changelog
135+
136+
All notable changes to this project will be documented in this file.
137+
138+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
139+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
140+
141+
## [1.0.0] - 2025-03-04
142+
143+
### Added
144+
- Initial release with runtime type checking base class
145+
- Basic types: isaPositiveInt, isaEmailAddress, isaString
146+
- Standard types: isaNumber, isaBoolean, isaDate, isaURL, isaArray, isaObject
147+
- Compound types: isaAnyOf, isaAllOf, isaNoneOf
148+
- Utilities: validate(), maybe()
149+
150+
[1.0.0]: https://github.com/renderorange/types-class/releases/tag/v1.0.0
151+
EOF
152+
sed -i "s/## \[1.0.0\]/## [$NEW_VERSION] - $DATE\n\n### Added\n- Release version $NEW_VERSION\n\n## [1.0.0]/" CHANGELOG.md
153+
sed -i "s|/v1.0.0|/v$NEW_VERSION|" CHANGELOG.md
154+
fi
155+
156+
echo "Changelog updated"
157+
158+
- name: Configure git
159+
run: |
160+
git config user.name "github-actions[bot]"
161+
git config user.email "github-actions[bot]@users.noreply.github.com"
162+
163+
- name: Commit changes
164+
run: |
165+
git add package.json CHANGELOG.md
166+
git commit -m "chore(release): v${{ steps.version.outputs.new_version }}"
167+
168+
- name: Push to main
169+
run: git push origin main
170+
171+
- name: Create and push tag
172+
run: |
173+
git tag -a "v${{ steps.version.outputs.new_version }}" -m "Release v${{ steps.version.outputs.new_version }}"
174+
git push origin "v${{ steps.version.outputs.new_version }}"
175+
176+
- name: Create GitHub Release
177+
uses: softprops/action-gh-release@v1
178+
with:
179+
tag_name: "v${{ steps.version.outputs.new_version }}"
180+
name: "v${{ steps.version.outputs.new_version }}"
181+
generate_release_notes: true
182+
env:
183+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
184+
185+
- name: Publish to npm
186+
run: npm publish --provenance --access public
187+
env:
188+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0] - 2025-03-04
9+
10+
### Added
11+
- Initial release with runtime type checking base class
12+
- Basic types: isaPositiveInt, isaEmailAddress, isaString
13+
- Standard types: isaNumber, isaBoolean, isaDate, isaURL, isaArray, isaObject
14+
- Compound types: isaAnyOf, isaAllOf, isaNoneOf
15+
- Utilities: validate(), maybe()
16+
17+
[1.0.0]: https://github.com/renderorange/types-class/releases/tag/v1.0.0

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# types-class
1+
# @renderorange/types-class
22

33
Runtime type checking base class for JavaScript.
44

55
## Installation
66

77
```bash
8-
npm install types-class
8+
npm install @renderorange/types-class
99
```
1010

1111
## Usage
1212

1313
Extend `TypesClass` and define methods that use the built-in type checks:
1414

1515
```javascript
16-
const TypesClass = require("types-class");
16+
const TypesClass = require("@renderorange/types-class");
1717

1818
class User extends TypesClass {
1919
constructor(name, email, age) {

package.json

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
11
{
2-
"name": "types-class",
2+
"name": "@renderorange/types-class",
33
"version": "1.0.0",
44
"description": "Base class for runtime type checking in JavaScript",
5-
"author": "Blaine Motsinger",
5+
"author": "Blaine Motsinger <blaine@renderorange.com>",
6+
"license": "MIT",
67
"main": "src/types_class.js",
8+
"files": [
9+
"src/",
10+
"LICENSE",
11+
"README.md",
12+
"CHANGELOG.md"
13+
],
14+
"keywords": [
15+
"type-checking",
16+
"validation",
17+
"javascript",
18+
"class",
19+
"runtime-types",
20+
"type-validation",
21+
"type-checker"
22+
],
23+
"repository": {
24+
"type": "git",
25+
"url": "git+https://github.com/renderorange/types-class.git"
26+
},
27+
"bugs": {
28+
"url": "https://github.com/renderorange/types-class/issues"
29+
},
30+
"homepage": "https://github.com/renderorange/types-class#readme",
31+
"publishConfig": {
32+
"access": "public"
33+
},
734
"scripts": {
835
"test": "jest",
936
"test:watch": "jest --watch",
1037
"test:coverage": "jest --coverage",
1138
"lint": "node node_modules/eslint/bin/eslint.js . --fix",
1239
"lint:check": "node node_modules/eslint/bin/eslint.js ."
13-
1440
},
1541
"devDependencies": {
1642
"eslint": "^9.0.0",

0 commit comments

Comments
 (0)