-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (105 loc) · 4.44 KB
/
release.yml
File metadata and controls
129 lines (105 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Release
on:
push:
branches: [release]
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
# Skip version bump commits
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Use Node.js 20.x
uses: actions/setup-node@v6
with:
node-version: 20.x
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Get version from package.json
id: package-version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: tag-check
run: |
if git rev-parse "v${{ steps.package-version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Generate changelog
id: changelog
if: steps.tag-check.outputs.exists == 'false'
run: |
VERSION="${{ steps.package-version.outputs.version }}"
MAJOR_MINOR=$(echo $VERSION | cut -d. -f1-2)
# Try exact version first (e.g., v0.10.5.md), then minor.x pattern (e.g., v0.10.x.md)
CHANGELOG_FILE_EXACT=".changelog/v${VERSION}.md"
CHANGELOG_FILE_PATTERN=".changelog/v${MAJOR_MINOR}.x.md"
if [ -f "$CHANGELOG_FILE_EXACT" ]; then
# Use exact version changelog
CHANGELOG=$(cat "$CHANGELOG_FILE_EXACT")
elif [ -f "$CHANGELOG_FILE_PATTERN" ]; then
# Use minor version pattern changelog (e.g., v0.10.x.md)
CHANGELOG=$(cat "$CHANGELOG_FILE_PATTERN")
# Replace version placeholder with actual version
CHANGELOG=$(echo "$CHANGELOG" | sed "s/v${MAJOR_MINOR}.x/v${VERSION}/g" | sed "s/${MAJOR_MINOR}.x/${VERSION}/g")
else
# Fallback: Generate changelog from commits (exclude [skip ci] commits)
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)
COMMIT_LOG=$(git log $PREV_TAG..HEAD --pretty=format:"- %s" --no-merges | grep -v "\[skip ci\]" | head -50)
# Create a basic changelog structure
CHANGELOG="# Release v${VERSION}
## Changes
${COMMIT_LOG}
## Installation
\`\`\`bash
git clone https://github.com/atomantic/SparseTree.git
cd SparseTree
npm run install:all
pm2 start ecosystem.config.cjs
\`\`\`"
fi
# Handle multiline output
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
if: steps.tag-check.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.package-version.outputs.version }}
name: v${{ steps.package-version.outputs.version }}
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Archive changelog on main
if: steps.tag-check.outputs.exists == 'false'
run: |
CURRENT_VERSION=${{ steps.package-version.outputs.version }}
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
MAJOR_MINOR="$MAJOR.$MINOR"
PATTERN_FILE=".changelog/v${MAJOR_MINOR}.x.md"
VERSIONED_FILE=".changelog/v${CURRENT_VERSION}.md"
if [ -f "$PATTERN_FILE" ]; then
# Archive directly on main so release never diverges
git fetch origin main
git checkout main
git mv "$PATTERN_FILE" "$VERSIONED_FILE"
sed -i.bak "s/v${MAJOR_MINOR}\.x/v${CURRENT_VERSION}/g; s/${MAJOR_MINOR}\.x/${CURRENT_VERSION}/g; s/YYYY-MM-DD/$(date +%Y-%m-%d)/g" "$VERSIONED_FILE"
rm "${VERSIONED_FILE}.bak"
git add "$VERSIONED_FILE"
git commit -m "docs: archive changelog for v${CURRENT_VERSION} [skip ci]"
git push origin main
# Fast-forward release to match main
git push origin main:release
fi