generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 59
173 lines (148 loc) · 5.95 KB
/
manual-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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Manual Plugin Release
on:
workflow_dispatch:
inputs:
increment:
description: "Version increment type"
required: true
type: choice
options:
- patch
- minor
- major
default: "patch"
jobs:
check_release:
runs-on: ubuntu-latest
outputs:
is_releasing: ${{ steps.check.outputs.is_releasing }}
steps:
- id: check
name: Check for running release workflows
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get running workflows named either "Release Obsidian Plugin" or "Manual Plugin Release"
running=$(gh api /repos/${{ github.repository }}/actions/runs \
--jq '.workflow_runs[] | select(.status=="in_progress" and (.name=="Release Obsidian Plugin" or .name=="Manual Plugin Release")) | .id' \
| wc -l)
# If any release workflows are running (besides this one), fail early
if [ "$running" -gt "1" ]; then
echo "is_releasing=true" >> $GITHUB_OUTPUT
echo "::error::A release is already in progress. Please wait for it to complete."
exit 1
else
echo "is_releasing=false" >> $GITHUB_OUTPUT
fi
release:
needs: check_release
if: needs.check_release.outputs.is_releasing != 'true'
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
# Use a full checkout to ensure all history is available
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Install dependencies
run: pnpm install
- 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 versions
id: version
run: |
cd packages/plugin
echo "Current directory: $(pwd)"
echo "Current package.json version: $(node -p "require('./package.json').version")"
echo "Current manifest.json version: $(node -p "require('../../manifest.json').version")"
echo "Increment type: ${{ github.event.inputs.increment }}"
# Bump version in package.json
NEW_VERSION=$(npm version ${{ github.event.inputs.increment }} --no-git-tag-version)
VERSION_NUMBER=${NEW_VERSION#v}
echo "New version (with v): $NEW_VERSION"
echo "New version (stripped): $VERSION_NUMBER"
# Export the new version for subsequent steps
echo "version=${VERSION_NUMBER}" >> "$GITHUB_OUTPUT"
# Update root manifest.json to match the new version
cd ../..
jq --arg version "$VERSION_NUMBER" '.version = $version' manifest.json > manifest.json.tmp
mv manifest.json.tmp manifest.json
echo "Updated package.json version: $(node -p "require('./packages/plugin/package.json').version")"
echo "Updated manifest.json version: $(node -p "require('./manifest.json').version")"
# Stage and commit changes
git add packages/plugin/package.json manifest.json
echo "Files to be committed:"
git status --porcelain
git commit -m "chore(release): bump version to $VERSION_NUMBER"
echo "Commit created with version $VERSION_NUMBER"
- name: Push changes
run: git push origin HEAD
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build plugin
run: pnpm --filter "./packages/plugin" build
- name: Generate Release Notes
id: release_notes
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
# Build the release-notes package
pnpm --filter "@file-organizer/release-notes" build
# Generate the release notes
cd packages/plugin
previous_version=$(node -p "require('./manifest.json').version")
NOTES_JSON=$(node -r ts-node/register ../release-notes/dist/index.js $previous_version )
echo "NOTES_JSON<<EOF" >> $GITHUB_ENV
echo "$NOTES_JSON" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Prepare release artifacts
run: |
mkdir -p release-artifacts
cp packages/plugin/dist/main.js release-artifacts/
cp packages/plugin/dist/styles.css release-artifacts/
cp manifest.json release-artifacts/
# Create checksum file
cd release-artifacts
sha256sum * > checksums.txt
cd ..
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version=$(node -p "require('./manifest.json').version")
# Parse release notes JSON
RELEASE_NAME=$(echo "$NOTES_JSON" | jq -r '.name')
RELEASE_DESC=$(echo "$NOTES_JSON" | jq -r '.description')
TECHNICAL_CHANGES=$(echo "$NOTES_JSON" | jq -r '.technicalChanges | join("\n- ")')
# Create release notes markdown
{
echo "# $RELEASE_NAME"
echo ""
echo "$RELEASE_DESC"
echo ""
echo "## Technical Changes"
echo "- $TECHNICAL_CHANGES"
echo ""
echo "## SHA-256 Checksums"
cat release-artifacts/checksums.txt
} > release-notes.md
# Create the GitHub release
gh release create "$version" \
--title="$RELEASE_NAME" \
--notes-file=release-notes.md \
--draft=false \
release-artifacts/main.js \
release-artifacts/styles.css \
release-artifacts/manifest.json \
release-artifacts/checksums.txt