-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (105 loc) · 3.94 KB
/
release-drafter.yml
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
# .github/workflows/release-drafter.yml
name: Release Drafter
on:
push:
branches: [ master ] # Changed from main to master
pull_request:
types: [opened, reopened, synchronize]
branches: [ master ] # Changed from main to master
workflow_dispatch:
permissions:
contents: write
pull-requests: write
issues: write
jobs:
draft:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: release-drafter/release-drafter@v5
id: release_drafter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
config-name: release-drafter.yml
disable-autolabeler: false
commitish: master # Changed from main to master
- name: Extract version without v prefix
id: version
run: |
VERSION="${{ steps.release_drafter.outputs.resolved_version }}"
VERSION="${VERSION#v}" # Remove v prefix if present
echo "version=$VERSION" >> $GITHUB_OUTPUT
update_version:
needs: draft
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master' # Changed from main to master
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Update Package Version
run: |
NEW_VERSION="${{ needs.draft.outputs.version }}"
if [ -n "$NEW_VERSION" ]; then
# Read current version
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$CURRENT_VERSION" != "$NEW_VERSION" ]; then
echo "Updating version from $CURRENT_VERSION to $NEW_VERSION"
# Update package.json without creating git tag
npm version $NEW_VERSION --no-git-tag-version --allow-same-version
npm install
rm -rf dist/
# Stage changes
git add package.json
if [ -f "package-lock.json" ]; then
rm -rf package-lock.json
fi
# Commit and push changes
git commit -m "chore: update package version to $NEW_VERSION [skip ci]"
git push
else
echo "Version is already up to date ($CURRENT_VERSION)"
fi
else
echo "No version update needed"
fi
- name: Update Changelog
if: needs.draft.outputs.version != ''
run: |
if [ -f CHANGELOG.md ]; then
NEW_VERSION="${{ needs.draft.outputs.version }}"
DATE=$(date +"%Y-%m-%d")
# Create temporary file for new content
echo "# $NEW_VERSION ($DATE)" > temp_changelog.md
echo "" >> temp_changelog.md
# Add release notes
curl -s \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/releases" \
| jq -r '.[0].body' >> temp_changelog.md
echo "" >> temp_changelog.md
# Combine with existing changelog
if [ -f CHANGELOG.md ]; then
cat CHANGELOG.md >> temp_changelog.md
fi
mv temp_changelog.md CHANGELOG.md
# Commit changelog
git add CHANGELOG.md
git commit -m "docs: update changelog for $NEW_VERSION [skip ci]"
git push
fi