Skip to content

Commit 5823523

Browse files
committed
chore: add release workflow
1 parent 98fc2f1 commit 5823523

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

.github/workflows/release.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
id-token: write
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: "20"
22+
cache: "npm"
23+
registry-url: "https://registry.npmjs.org"
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Validate package
29+
run: npm run validate
30+
31+
- name: Publish to npm
32+
run: npm publish --provenance --access public
33+
env:
34+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
35+
36+
- name: Generate release notes
37+
id: release_notes
38+
run: |
39+
# Extract version from tag
40+
VERSION=${GITHUB_REF#refs/tags/v}
41+
echo "version=$VERSION" >> $GITHUB_OUTPUT
42+
43+
# Generate changelog since last tag
44+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
45+
if [ -n "$PREV_TAG" ]; then
46+
echo "## Changes" > release_notes.md
47+
git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD >> release_notes.md
48+
else
49+
echo "## Initial Release" > release_notes.md
50+
echo "First release of @aha-co/config" >> release_notes.md
51+
fi
52+
53+
- name: Create GitHub Release
54+
uses: actions/create-release@v1
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
with:
58+
tag_name: ${{ github.ref }}
59+
release_name: Release ${{ steps.release_notes.outputs.version }}
60+
body_path: release_notes.md
61+
draft: false
62+
prerelease: ${{ contains(github.ref, '-') }}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"format": "prettier . --write",
2121
"lint": "eslint .",
2222
"typecheck": "tsc",
23-
"validate": "run-p -l format lint typecheck"
23+
"validate": "run-p -l format lint typecheck",
24+
"prepack": "npm run validate"
2425
},
2526
"keywords": [
2627
"config",

scripts/release.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# Release script for @aha-co/config
4+
# Usage: ./scripts/release.sh [patch|minor|major]
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m' # No Color
13+
14+
# Default to patch if no argument provided
15+
RELEASE_TYPE=${1:-patch}
16+
17+
# Validate release type
18+
if [[ ! "$RELEASE_TYPE" =~ ^(patch|minor|major)$ ]]; then
19+
echo -e "${RED}Error: Release type must be 'patch', 'minor', or 'major'${NC}"
20+
echo "Usage: ./scripts/release.sh [patch|minor|major]"
21+
exit 1
22+
fi
23+
24+
echo -e "${YELLOW}Starting $RELEASE_TYPE release...${NC}"
25+
26+
# Check if working directory is clean
27+
if [[ -n $(git status --porcelain) ]]; then
28+
echo -e "${RED}Error: Working directory is not clean. Please commit or stash your changes.${NC}"
29+
exit 1
30+
fi
31+
32+
# Check if we're on main branch
33+
CURRENT_BRANCH=$(git branch --show-current)
34+
if [[ "$CURRENT_BRANCH" != "main" ]]; then
35+
echo -e "${YELLOW}Warning: You're not on the main branch (current: $CURRENT_BRANCH)${NC}"
36+
read -p "Continue anyway? (y/N): " -n 1 -r
37+
echo
38+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
39+
exit 1
40+
fi
41+
fi
42+
43+
# Pull latest changes
44+
echo -e "${YELLOW}Pulling latest changes...${NC}"
45+
git pull origin $CURRENT_BRANCH
46+
47+
# Run validation
48+
echo -e "${YELLOW}Running validation...${NC}"
49+
npm run validate
50+
51+
if [ $? -ne 0 ]; then
52+
echo -e "${RED}Validation failed. Please fix the issues before releasing.${NC}"
53+
exit 1
54+
fi
55+
56+
# Get current version
57+
CURRENT_VERSION=$(node -p "require('./package.json').version")
58+
echo -e "${YELLOW}Current version: $CURRENT_VERSION${NC}"
59+
60+
# Bump version and create tag
61+
echo -e "${YELLOW}Bumping version...${NC}"
62+
npm version $RELEASE_TYPE -m "Release v%s"
63+
64+
# Get new version
65+
NEW_VERSION=$(node -p "require('./package.json').version")
66+
echo -e "${GREEN}New version: $NEW_VERSION${NC}"
67+
68+
# Push commits and tags
69+
echo -e "${YELLOW}Pushing to GitHub...${NC}"
70+
git push origin $CURRENT_BRANCH --follow-tags
71+
72+
echo -e "${GREEN}✅ Release $NEW_VERSION completed!${NC}"
73+
echo -e "${YELLOW}Next steps:${NC}"
74+
echo "1. GitHub Actions will automatically create a release"
75+
echo "2. To publish to npm manually, run: npm publish"
76+
echo "3. Check the release at: https://github.com/theahaco/aha-co-config/releases"

0 commit comments

Comments
 (0)