-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Tencent:main' into main
- Loading branch information
Showing
110 changed files
with
8,860 additions
and
3,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: PR Closed Or Merge | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- closed | ||
|
||
jobs: | ||
remove_assets: | ||
# 不需要在fork仓库的pr中运行 | ||
if: github.repository == 'Tencent/cherry-markdown' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# 检出仓库代码 | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
# 安装 cos-nodejs-sdk-v5 | ||
- name: Install cos-nodejs-sdk-v5 | ||
run: npm install cos-nodejs-sdk-v5 | ||
|
||
# 删除对应的资源 | ||
- name: Delete Resources On COS | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const COS = require('cos-nodejs-sdk-v5'); | ||
const cos = new COS({ | ||
SecretId: process.env.COS_SECRETID, | ||
SecretKey: process.env.COS_SECRETKEY, | ||
}); | ||
const bucket = 'cherrymd-1301618266'; | ||
const region = 'ap-singapore'; | ||
const prNumber = '${{ github.event.pull_request.number }}'; | ||
const prefix = `pr${prNumber}/`; | ||
// List objects in the bucket with the specified prefix | ||
cos.getBucket({ | ||
Bucket: bucket, | ||
Region: region, | ||
Prefix: prefix, | ||
}, (err, data) => { | ||
if (err) { | ||
console.error('Error listing objects:', err); | ||
return; | ||
} | ||
const objectsToDelete = data.Contents.map(item => ({ Key: item.Key })); | ||
if (objectsToDelete.length === 0) { | ||
console.log('No objects to delete.'); | ||
return; | ||
} | ||
// Delete the listed objects | ||
cos.deleteMultipleObject({ | ||
Bucket: bucket, | ||
Region: region, | ||
Objects: objectsToDelete, | ||
}, (err, data) => { | ||
if (err) { | ||
console.error('Error deleting objects:', err); | ||
} else { | ||
console.log('Successfully deleted objects:', data); | ||
} | ||
}); | ||
}); | ||
env: | ||
COS_SECRETID: ${{ secrets.COS_SECRETID }} | ||
COS_SECRETKEY: ${{ secrets.COS_SECRETKEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
name: PR Reviewer | ||
|
||
on: workflow_call | ||
|
||
jobs: | ||
review: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Print PR details | ||
run: | | ||
echo "The PR ID is ${{ github.event.pull_request.id }}" | ||
echo "The PR number is ${{ github.event.pull_request.number }}" | ||
echo "The PR title is ${{ github.event.pull_request.title }}" | ||
echo "The PR branch is ${{ github.event.pull_request.head.ref }}" | ||
- run: npm install cos-nodejs-sdk-v5 | ||
|
||
- name: Download build dist | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: build-dist | ||
path: dist | ||
|
||
- name: Download build artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: build-examples | ||
path: examples | ||
|
||
- name: Upload to COS | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const COS = require('cos-nodejs-sdk-v5'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const cos = new COS({ | ||
SecretId: '${{ secrets.COS_SECRETID }}', | ||
SecretKey: '${{ secrets.COS_SECRETKEY }}', | ||
}); | ||
const uploadDirectory = (directoryPath, keyPrefix) => { | ||
const uploadPromises = []; | ||
const files = fs.readdirSync(directoryPath); | ||
files.forEach(file => { | ||
const filePath = path.join(directoryPath, file); | ||
const key = `${keyPrefix}/${file}`; | ||
if (fs.lstatSync(filePath).isDirectory()) { | ||
uploadPromises.push(uploadDirectory(filePath, key)); | ||
} else { | ||
uploadPromises.push(uploadFile(filePath, key)); | ||
} | ||
}); | ||
return Promise.all(uploadPromises); | ||
}; | ||
const uploadFile = (filePath, key) => { | ||
return new Promise((resolve, reject) => { | ||
cos.uploadFile({ | ||
Bucket: 'cherrymd-1301618266', | ||
Region: 'ap-singapore', | ||
Key: key, | ||
FilePath: filePath, | ||
SliceSize: 1024 * 1024 * 5, /* 触发分块上传的阈值,超过5MB使用分块上传,非必须 */ | ||
ContentDisposition: 'inline', | ||
CacheControl: 'no-cache', | ||
Headers: { | ||
'Cache-control': 'no-cache', | ||
'Content-Disposition': 'inline', | ||
}, | ||
}, function(err, data) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(data); | ||
} | ||
}); | ||
}); | ||
}; | ||
(async () => { | ||
try { | ||
await uploadDirectory('dist', 'pr${{ github.event.pull_request.number }}/dist'); | ||
await uploadDirectory('examples', 'pr${{ github.event.pull_request.number }}/examples'); | ||
console.log('Upload success'); | ||
} catch (err) { | ||
console.error('Upload failed:', err); | ||
} | ||
})(); | ||
- name: Add Comment | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const response = await github.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
body: ` | ||
### 【预览链接】 | ||
- https://cherrymd.com/pr${{ github.event.pull_request.number }}/examples/index.html | ||
` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: PR Test | ||
|
||
on: | ||
pull_request_target: | ||
branches: [main, dev] | ||
|
||
jobs: | ||
build: | ||
# 不需要在fork仓库的pr中运行 | ||
if: github.repository == 'Tencent/cherry-markdown' | ||
runs-on: ubuntu-latest | ||
env: | ||
BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: '${{ env.HEAD_SHA }}' | ||
|
||
- name: Get changed files and operations | ||
run: | | ||
# 使用 GitHub API 获取变更文件列表及其操作 | ||
DIFF_DOCUMENTS=$(gh api repos/${{ github.repository }}/compare/${{ env.BASE_SHA }}...${{ env.HEAD_SHA }} \ | ||
--jq '.files | .[] | select(.status|IN("added", "modified", "renamed", "copied", "changed")) | .filename') | ||
echo "Changed files and operations: ${DIFF_DOCUMENTS}" | ||
# Eslint 检查js文件 | ||
LINT_FILES=$(echo "${DIFF_DOCUMENTS}" | grep -E '^.*\.js$' | xargs) | ||
echo "LINT_FILES=${LINT_FILES}" >> $GITHUB_ENV | ||
# 忽略 .github/workflows 下的文件 | ||
GIT_DIFF_FILES=$(echo "${DIFF_DOCUMENTS}" | grep -vE '^\.github\/workflows\/.*' | xargs) | ||
echo "GIT_DIFF_FILES=${GIT_DIFF_FILES}" >> $GITHUB_ENV | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- uses: actions/checkout@v2 | ||
if: ${{ env.GIT_DIFF_FILES }} | ||
with: | ||
repository: ${{ github.repository }} | ||
ref: '${{ env.BASE_SHA }}' | ||
path: base-repo | ||
|
||
- name: Replace changed files | ||
if: ${{ env.GIT_DIFF_FILES }} | ||
run: | | ||
for file in ${{ env.GIT_DIFF_FILES }}; do | ||
cp "$file" "base-repo/$file" | ||
done | ||
- name: Use Node.js 16.x | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16.x | ||
cache: 'yarn' | ||
|
||
- name: Install dependencies | ||
uses: borales/actions-yarn@v3.0.0 | ||
with: | ||
cmd: install | ||
|
||
- name: Lint Changed Files | ||
if: ${{ env.LINT_FILES }} | ||
run: | | ||
for file in ${{ env.LINT_FILES }}; do | ||
yarn eslint "$file" | ||
done | ||
- name: Run Build | ||
uses: borales/actions-yarn@v3.0.0 | ||
with: | ||
cmd: build | ||
|
||
- name: Archive build dist | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: build-dist | ||
path: dist | ||
|
||
- name: Archive examples | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: build-examples | ||
path: examples | ||
|
||
review: | ||
needs: build | ||
permissions: write-all | ||
uses: ./.github/workflows/pr-reviewer.yml | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.