generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 38
202 lines (170 loc) · 9.53 KB
/
beta-release.yml
File metadata and controls
202 lines (170 loc) · 9.53 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# .github/workflows/beta-release.yml
name: "Automatic Beta Release on PR Commit"
on:
pull_request:
# Trigger on PR creation or when new commits are pushed
types: [opened, synchronize]
# IMPORTANT: Change 'main' to your default branch if it's different (e.g., 'master')
branches:
- master
push:
# Only trigger on push to specific branches (more secure)
branches:
- master
- "feat/**"
- "release/**"
env:
PLUGIN_NAME: obsidian-task-genius
# Grant permissions for the action to create a release
permissions:
contents: write
pull-requests: read
jobs:
build-and-release-beta:
if: |
contains(github.event.head_commit.message, '[release-beta]') && (
(github.event_name == 'push' && github.actor == github.repository_owner) ||
(github.event_name == 'pull_request' && github.event.pull_request.author_association == 'OWNER')
)
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 0
# Check if any recent commits contain [release-beta] tag
- name: "Check for release-beta tag in commits"
id: check_release_tag
run: |
SHOULD_RELEASE="false"
# Security check: only allow releases from the main repository
REPO_OWNER="${{ github.repository_owner }}"
REPO_NAME="${{ github.repository }}"
echo "Repository: $REPO_NAME, Owner: $REPO_OWNER"
# Add your expected repository info here for extra security
# EXPECTED_REPO="your-username/your-repo-name"
# if [ "$REPO_NAME" != "$EXPECTED_REPO" ]; then
# echo "Release not allowed from repository: $REPO_NAME"
# echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT
# exit 0
# fi
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "Checking PR commits for [release-beta] tag..."
# Check the latest commit in the PR
LATEST_COMMIT_MSG=$(git log -1 --pretty=format:"%s")
echo "Latest commit message: $LATEST_COMMIT_MSG"
if echo "$LATEST_COMMIT_MSG" | grep -q "\[release-beta\]"; then
echo "Found [release-beta] tag in latest commit"
SHOULD_RELEASE="true"
fi
# Check user permissions (more restrictive)
USER_ASSOCIATION="${{ github.event.pull_request.author_association }}"
PR_AUTHOR="${{ github.event.pull_request.user.login }}"
echo "PR author: $PR_AUTHOR, Association: $USER_ASSOCIATION"
# Only allow OWNER and COLLABORATOR to trigger releases
if [ "$USER_ASSOCIATION" != "OWNER" ] && [ "$USER_ASSOCIATION" != "COLLABORATOR" ]; then
echo "User association '$USER_ASSOCIATION' is not authorized for releases"
SHOULD_RELEASE="false"
fi
# Additional check: only allow specific users (optional - uncomment and customize)
# ALLOWED_USERS="Quorafind,other-username"
# if ! echo "$ALLOWED_USERS" | grep -q "$PR_AUTHOR"; then
# echo "User '$PR_AUTHOR' is not in allowed users list"
# SHOULD_RELEASE="false"
# fi
elif [ "${{ github.event_name }}" = "push" ]; then
echo "Checking push commit for [release-beta] tag..."
COMMIT_MSG="${{ github.event.head_commit.message }}"
PUSH_AUTHOR="${{ github.event.head_commit.author.username }}"
echo "Commit message: $COMMIT_MSG"
echo "Push author: $PUSH_AUTHOR"
if echo "$COMMIT_MSG" | grep -q "\[release-beta\]"; then
echo "Found [release-beta] tag in push commit"
# Check if pusher is authorized (optional - uncomment and customize)
# ALLOWED_PUSH_USERS="Quorafind,other-username"
# if ! echo "$ALLOWED_PUSH_USERS" | grep -q "$PUSH_AUTHOR"; then
# echo "User '$PUSH_AUTHOR' is not authorized to trigger releases via push"
# SHOULD_RELEASE="false"
# else
# SHOULD_RELEASE="true"
# fi
SHOULD_RELEASE="true"
fi
fi
echo "SHOULD_RELEASE=$SHOULD_RELEASE" >> $GITHUB_OUTPUT
echo "Should release: $SHOULD_RELEASE"
- name: "Use Node.js 22"
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
uses: actions/setup-node@v4
with:
node-version: 22
- name: "Install pnpm"
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
uses: pnpm/action-setup@v4
with:
version: 9
- name: "Install dependencies"
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
run: |
# Install jq for JSON parsing
sudo apt-get update && sudo apt-get install -y jq
pnpm install
- name: "Get version from package.json"
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
id: get_version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
- name: "Get commit messages since last release"
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
id: get_commits
run: |
# Get all releases (including pre-releases) and find the most recent one
echo "Fetching all releases from GitHub API..."
LAST_RELEASE=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases?per_page=100" | jq -r '.[0].tag_name // empty' 2>/dev/null || echo "")
# If no release found via API, try to get the most recent tag with proper semantic version sorting
if [ -z "$LAST_RELEASE" ]; then
echo "No release found via API, looking for latest tag..."
# Get all tags and sort them properly using semantic versioning
LAST_RELEASE=$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1 2>/dev/null || echo "")
fi
if [ -z "$LAST_RELEASE" ]; then
echo "No previous release or tag found, getting all commits from the beginning"
COMMIT_MESSAGES=$(git log --pretty=format:"- %s (%an) [%h](https://github.com/${{ github.repository }}/commit/%H)" --no-merges)
LAST_RELEASE="(initial)"
else
echo "Getting commits since last release: $LAST_RELEASE"
RELEASE_COMMIT=$(git rev-list -n 1 $LAST_RELEASE 2>/dev/null || git rev-list -n 1 HEAD~10)
COMMIT_MESSAGES=$(git log ${RELEASE_COMMIT}..HEAD --pretty=format:"- %s (%an) [%h](https://github.com/${{ github.repository }}/commit/%H)" --no-merges)
fi
if [ -z "$COMMIT_MESSAGES" ]; then
COMMIT_MESSAGES="- No new commits since last release"
fi
echo "COMMIT_MESSAGES<<EOF" >> $GITHUB_ENV
echo "$COMMIT_MESSAGES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "LAST_RELEASE=$LAST_RELEASE" >> $GITHUB_ENV
- name: "Build and package plugin"
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
id: build
run: |
pnpm run build
mkdir ${{ env.PLUGIN_NAME }}
cp main.js manifest.json styles.css ${{ env.PLUGIN_NAME }}/
zip -r ${{ env.PLUGIN_NAME }}-${{ env.VERSION }}.zip ./${{ env.PLUGIN_NAME }}
- name: "Create Beta Pre-Release"
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
uses: softprops/action-gh-release@v2
with:
body: |
${{ github.event_name == 'pull_request' && format('🚀 Automated beta release for PR #{0}', github.event.pull_request.number) || '🚀 Automated beta release' }}
## 📝 Changes since last release${{ env.LAST_RELEASE && format(' ({0})', env.LAST_RELEASE) || '' }}:
${{ env.COMMIT_MESSAGES }}
---
${{ github.event_name == 'pull_request' && github.event.pull_request.body || '' }}
prerelease: true
tag_name: "v${{ env.VERSION }}"
name: "Beta Release v${{ env.VERSION }}"
files: |
${{ env.PLUGIN_NAME }}-${{ env.VERSION }}.zip
main.js
manifest.json
styles.css