-
Notifications
You must be signed in to change notification settings - Fork 4
114 lines (97 loc) · 3.81 KB
/
create-release.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
name: Release with Changeset
on:
workflow_dispatch:
branches:
- main
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ github.token }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm ci
- name: Commit Changeset Version Bump
id: changesets
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
npx changeset version
# Print the git status to see the changes
git status
if [ -n "$(git status --porcelain)" ]; then
NEW_VERSION=$(node -p "require('./package.json').version")
git add .
git commit -m "Version packages"
echo "commit=true" >> $GITHUB_ENV
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
echo "::set-output name=commit::true"
else
echo "No changes to commit"
echo "commit=false" >> $GITHUB_ENV
echo "::set-output name=commit::false"
fi
- name: Debug Commit Output
run: echo "Commit output: ${{ steps.changesets.outputs.commit }}"
- name: Pull Latest Changes
run: git pull origin main --rebase
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Push Version Bump to Main
if: steps.changesets.outputs.commit == 'true'
run: git push origin main
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Check Version Change
id: version_check
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
LATEST_RELEASE=$(gh release list --limit 1 | cut -f1)
LATEST_VERSION=${LATEST_RELEASE#v}
echo "Current version: ${CURRENT_VERSION}"
echo "Latest release: ${LATEST_VERSION}"
if [ "$(printf '%s\n' "$LATEST_VERSION" "$CURRENT_VERSION" | sort -V | tail -n1)" = "$CURRENT_VERSION" ] && [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
echo "Version increment detected"
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "No version increment detected or versions are equal"
echo "should_release=false" >> $GITHUB_OUTPUT
exit 0
fi
- name: Generate Release Summary
if: steps.version_check.outputs.should_release == 'true'
id: release_summary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get all commits between the last release and current
LATEST_RELEASE=$(gh release list --limit 1 | cut -f1)
COMMITS=$(git log ${LATEST_RELEASE}..HEAD --pretty=format:"%s")
# Generate a summary from the commit messages
SUMMARY="Summary of changes:\n${COMMITS}"
# Store the summary for the release
echo "summary<<EOF" >> $GITHUB_OUTPUT
echo "$SUMMARY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
if: steps.version_check.outputs.should_release == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
gh release create "v${CURRENT_VERSION}" \
--title "v${CURRENT_VERSION}: ${{ steps.release_summary.outputs.summary }}" \
--notes "${{ steps.release_summary.outputs.summary }}" \
--generate-notes