-
Notifications
You must be signed in to change notification settings - Fork 36
91 lines (78 loc) · 2.84 KB
/
Copy pathcreate-release.yml
File metadata and controls
91 lines (78 loc) · 2.84 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
name: Release with Changeset
on:
workflow_dispatch:
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: Pull Latest Changes
run: |
git pull origin main
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: Create GitHub Release
if: steps.version_check.outputs.should_release == 'true'
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
gh release create "v${CURRENT_VERSION}" \
--title "v${CURRENT_VERSION}" \
--generate-notes