-
Notifications
You must be signed in to change notification settings - Fork 2
120 lines (100 loc) · 3.52 KB
/
changeset-version-management.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
name: 🪡 Changeset (Version Management)
on:
push:
branches:
- develop
- test
jobs:
changeset_handler:
name: Changeset handler
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/create-github-app-token@v1
id: fleek-platform-bot-token
with:
app-id: ${{ secrets.FLEEK_PLATFORM_BOT_APP_ID }}
private-key: ${{ secrets.FLEEK_PLATFORM_BOT_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.fleek-platform-bot-token.outputs.token }}
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 7
run_install: false
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Changeset status
id: changeset-status
shell: bash
run: |
# Default skip state
skip="false"
# Default main branch
defaultBranchName=$(git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5)
# Changeset artifacts
changesetArtifactsPath=".changeset"
if ! npx changeset status &>/dev/null; then
echo "⚠️ Warning: No changesets found, should skip!"
skip="true"
fi
# If there are changes, it exit 1
if git diff --quiet HEAD "$defaultBranchName" -- "$changesetArtifactsPath"; then
echo "⚠️ Warning: The .changeset directory doesn't have new changesets, should skip!"
skip="true"
fi
echo "skip=$skip" >> "$GITHUB_OUTPUT"
- name: Get pnpm store directory
if: ${{ steps.changeset-status.outputs.skip != 'true' }}
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
if: ${{ steps.changeset-status.outputs.skip != 'true' }}
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
if: ${{ steps.changeset-status.outputs.skip != 'true' }}
run: |
pnpm install \
--strict-peer-dependencies
- name: Set version
if: ${{ steps.changeset-status.outputs.skip != 'true' }}
run: |
pnpm changeset:version
git status --short
- name: Commit changes
if: ${{ steps.changeset-status.outputs.skip != 'true' }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
if ! git add -A; then
echo "👹 Oops! Failed stage changes"
exit 1
fi
echo "✅ Staged all changes!"
pkgVersion=$(node -p "require('./package.json').version")
if ! git commit \
--allow-empty \
--no-verify \
-m "[skip ci] 🦖 updated package version to $pkgVersion"; then
echo "👹 Oops! Failed to commit package version."
exit 1
fi
echo "✅ Committed package version!"
if ! git push; then
echo "👹 Oops! Failed to push changes."
exit 1
fi
echo "✅ Pushed changes to repository!"