Skip to content

Commit 14c39a2

Browse files
authored
Merge pull request #286 from Quorafind/feat/file-index
Feat/file index
2 parents e000262 + a97aa50 commit 14c39a2

195 files changed

Lines changed: 45686 additions & 32281 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/beta-release.yml

Lines changed: 190 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,202 @@
11
# .github/workflows/beta-release.yml
22

3-
name: 'Automatic Beta Release on PR Commit'
3+
name: "Automatic Beta Release on PR Commit"
44

55
on:
6-
pull_request:
7-
# Trigger on PR creation or when new commits are pushed
8-
types: [opened, synchronize]
9-
# IMPORTANT: Change 'main' to your default branch if it's different (e.g., 'master')
10-
branches:
11-
- main
6+
pull_request:
7+
# Trigger on PR creation or when new commits are pushed
8+
types: [opened, synchronize]
9+
# IMPORTANT: Change 'main' to your default branch if it's different (e.g., 'master')
10+
branches:
11+
- master
12+
push:
13+
# Only trigger on push to specific branches (more secure)
14+
branches:
15+
- master
16+
- "feat/**"
17+
- "release/**"
1218

1319
env:
14-
PLUGIN_NAME: obsidian-task-genius
20+
PLUGIN_NAME: obsidian-task-genius
1521

1622
# Grant permissions for the action to create a release
1723
permissions:
18-
contents: write
19-
pull-requests: read
24+
contents: write
25+
pull-requests: read
2026

2127
jobs:
22-
build-and-release-beta:
23-
# This job only runs if the latest commit message on the PR contains '[release-beta]'
24-
if: contains(github.event.head_commit.message, '[release-beta]')
25-
runs-on: ubuntu-latest
26-
steps:
27-
- name: 'Checkout code'
28-
uses: actions/checkout@v4
29-
30-
- name: 'Use Node.js 22'
31-
uses: actions/setup-node@v4
32-
with:
33-
node-version: 22
34-
35-
- name: 'Install pnpm'
36-
uses: pnpm/action-setup@v4
37-
with:
38-
version: 9
39-
40-
- name: 'Install dependencies'
41-
run: pnpm install
42-
43-
# --- New Step to read version ---
44-
- name: 'Get version from package.json'
45-
id: get_version
46-
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
47-
48-
- name: 'Build and package plugin'
49-
id: build
50-
run: |
51-
pnpm run build
52-
# Create a directory and copy files for zipping
53-
mkdir ${{ env.PLUGIN_NAME }}
54-
cp main.js manifest.json styles.css ${{ env.PLUGIN_NAME }}/
55-
# Create the zip file for the release, using the version from package.json
56-
zip -r ${{ env.PLUGIN_NAME }}-${{ env.VERSION }}.zip ./${{ env.PLUGIN_NAME }}
57-
58-
- name: 'Create Beta Pre-Release'
59-
uses: softprops/action-gh-release@v2
60-
with:
61-
# Use the body of the PR for the release notes
62-
body: |
63-
Automated beta release for PR #${{ github.event.pull_request.number }}.
64-
Commit: `${{ github.sha }}`
65-
66-
${{ github.event.pull_request.body }}
67-
68-
# Mark this as a pre-release, so it doesn't count as a latest official release
69-
prerelease: true
70-
71-
# Use the version from package.json for the tag and release name
72-
tag_name: "v${{ env.VERSION }}"
73-
name: "Beta Release v${{ env.VERSION }}"
74-
75-
# Upload all required assets in one step, using the versioned zip file name
76-
files: |
77-
${{ env.PLUGIN_NAME }}-${{ env.VERSION }}.zip
78-
main.js
79-
manifest.json
80-
styles.css
28+
build-and-release-beta:
29+
if: |
30+
contains(github.event.head_commit.message, '[release-beta]') && (
31+
(github.event_name == 'push' && github.actor == github.repository_owner) ||
32+
(github.event_name == 'pull_request' && github.event.pull_request.author_association == 'OWNER')
33+
)
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: "Checkout code"
37+
uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 0
8140

41+
# Check if any recent commits contain [release-beta] tag
42+
- name: "Check for release-beta tag in commits"
43+
id: check_release_tag
44+
run: |
45+
SHOULD_RELEASE="false"
46+
47+
# Security check: only allow releases from the main repository
48+
REPO_OWNER="${{ github.repository_owner }}"
49+
REPO_NAME="${{ github.repository }}"
50+
echo "Repository: $REPO_NAME, Owner: $REPO_OWNER"
51+
52+
# Add your expected repository info here for extra security
53+
# EXPECTED_REPO="your-username/your-repo-name"
54+
# if [ "$REPO_NAME" != "$EXPECTED_REPO" ]; then
55+
# echo "Release not allowed from repository: $REPO_NAME"
56+
# echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT
57+
# exit 0
58+
# fi
59+
60+
if [ "${{ github.event_name }}" = "pull_request" ]; then
61+
echo "Checking PR commits for [release-beta] tag..."
62+
# Check the latest commit in the PR
63+
LATEST_COMMIT_MSG=$(git log -1 --pretty=format:"%s")
64+
echo "Latest commit message: $LATEST_COMMIT_MSG"
65+
66+
if echo "$LATEST_COMMIT_MSG" | grep -q "\[release-beta\]"; then
67+
echo "Found [release-beta] tag in latest commit"
68+
SHOULD_RELEASE="true"
69+
fi
70+
71+
# Check user permissions (more restrictive)
72+
USER_ASSOCIATION="${{ github.event.pull_request.author_association }}"
73+
PR_AUTHOR="${{ github.event.pull_request.user.login }}"
74+
echo "PR author: $PR_AUTHOR, Association: $USER_ASSOCIATION"
75+
76+
# Only allow OWNER and COLLABORATOR to trigger releases
77+
if [ "$USER_ASSOCIATION" != "OWNER" ] && [ "$USER_ASSOCIATION" != "COLLABORATOR" ]; then
78+
echo "User association '$USER_ASSOCIATION' is not authorized for releases"
79+
SHOULD_RELEASE="false"
80+
fi
81+
82+
# Additional check: only allow specific users (optional - uncomment and customize)
83+
# ALLOWED_USERS="Quorafind,other-username"
84+
# if ! echo "$ALLOWED_USERS" | grep -q "$PR_AUTHOR"; then
85+
# echo "User '$PR_AUTHOR' is not in allowed users list"
86+
# SHOULD_RELEASE="false"
87+
# fi
88+
89+
elif [ "${{ github.event_name }}" = "push" ]; then
90+
echo "Checking push commit for [release-beta] tag..."
91+
COMMIT_MSG="${{ github.event.head_commit.message }}"
92+
PUSH_AUTHOR="${{ github.event.head_commit.author.username }}"
93+
echo "Commit message: $COMMIT_MSG"
94+
echo "Push author: $PUSH_AUTHOR"
95+
96+
if echo "$COMMIT_MSG" | grep -q "\[release-beta\]"; then
97+
echo "Found [release-beta] tag in push commit"
98+
99+
# Check if pusher is authorized (optional - uncomment and customize)
100+
# ALLOWED_PUSH_USERS="Quorafind,other-username"
101+
# if ! echo "$ALLOWED_PUSH_USERS" | grep -q "$PUSH_AUTHOR"; then
102+
# echo "User '$PUSH_AUTHOR' is not authorized to trigger releases via push"
103+
# SHOULD_RELEASE="false"
104+
# else
105+
# SHOULD_RELEASE="true"
106+
# fi
107+
108+
SHOULD_RELEASE="true"
109+
fi
110+
fi
111+
112+
echo "SHOULD_RELEASE=$SHOULD_RELEASE" >> $GITHUB_OUTPUT
113+
echo "Should release: $SHOULD_RELEASE"
114+
115+
- name: "Use Node.js 22"
116+
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
117+
uses: actions/setup-node@v4
118+
with:
119+
node-version: 22
120+
121+
- name: "Install pnpm"
122+
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
123+
uses: pnpm/action-setup@v4
124+
with:
125+
version: 9
126+
127+
- name: "Install dependencies"
128+
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
129+
run: |
130+
# Install jq for JSON parsing
131+
sudo apt-get update && sudo apt-get install -y jq
132+
pnpm install
133+
134+
- name: "Get version from package.json"
135+
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
136+
id: get_version
137+
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
138+
139+
- name: "Get commit messages since last release"
140+
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
141+
id: get_commits
142+
run: |
143+
# Get all releases (including pre-releases) and find the most recent one
144+
echo "Fetching all releases from GitHub API..."
145+
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 "")
146+
147+
# If no release found via API, try to get the most recent tag with proper semantic version sorting
148+
if [ -z "$LAST_RELEASE" ]; then
149+
echo "No release found via API, looking for latest tag..."
150+
# Get all tags and sort them properly using semantic versioning
151+
LAST_RELEASE=$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1 2>/dev/null || echo "")
152+
fi
153+
154+
if [ -z "$LAST_RELEASE" ]; then
155+
echo "No previous release or tag found, getting all commits from the beginning"
156+
COMMIT_MESSAGES=$(git log --pretty=format:"- %s (%an) [%h](https://github.com/${{ github.repository }}/commit/%H)" --no-merges)
157+
LAST_RELEASE="(initial)"
158+
else
159+
echo "Getting commits since last release: $LAST_RELEASE"
160+
RELEASE_COMMIT=$(git rev-list -n 1 $LAST_RELEASE 2>/dev/null || git rev-list -n 1 HEAD~10)
161+
COMMIT_MESSAGES=$(git log ${RELEASE_COMMIT}..HEAD --pretty=format:"- %s (%an) [%h](https://github.com/${{ github.repository }}/commit/%H)" --no-merges)
162+
fi
163+
164+
if [ -z "$COMMIT_MESSAGES" ]; then
165+
COMMIT_MESSAGES="- No new commits since last release"
166+
fi
167+
echo "COMMIT_MESSAGES<<EOF" >> $GITHUB_ENV
168+
echo "$COMMIT_MESSAGES" >> $GITHUB_ENV
169+
echo "EOF" >> $GITHUB_ENV
170+
echo "LAST_RELEASE=$LAST_RELEASE" >> $GITHUB_ENV
171+
172+
- name: "Build and package plugin"
173+
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
174+
id: build
175+
run: |
176+
pnpm run build
177+
mkdir ${{ env.PLUGIN_NAME }}
178+
cp main.js manifest.json styles.css ${{ env.PLUGIN_NAME }}/
179+
zip -r ${{ env.PLUGIN_NAME }}-${{ env.VERSION }}.zip ./${{ env.PLUGIN_NAME }}
180+
181+
- name: "Create Beta Pre-Release"
182+
if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true'
183+
uses: softprops/action-gh-release@v2
184+
with:
185+
body: |
186+
${{ github.event_name == 'pull_request' && format('🚀 Automated beta release for PR #{0}', github.event.pull_request.number) || '🚀 Automated beta release' }}
187+
188+
## 📝 Changes since last release${{ env.LAST_RELEASE && format(' ({0})', env.LAST_RELEASE) || '' }}:
189+
190+
${{ env.COMMIT_MESSAGES }}
191+
192+
---
193+
194+
${{ github.event_name == 'pull_request' && github.event.pull_request.body || '' }}
195+
prerelease: true
196+
tag_name: "v${{ env.VERSION }}"
197+
name: "Beta Release v${{ env.VERSION }}"
198+
files: |
199+
${{ env.PLUGIN_NAME }}-${{ env.VERSION }}.zip
200+
main.js
201+
manifest.json
202+
styles.css

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ package-lock.json
3939
scripts
4040
translation-templates
4141
._data.json
42+
43+
styles.css

0 commit comments

Comments
 (0)