-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v6' into next-thumbnail
- Loading branch information
Showing
362 changed files
with
129,549 additions
and
56,928 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* @typedef {import('@octokit/rest').Octokit} Octokit | ||
* @typedef {import('@actions/github')['context']} Context | ||
*/ | ||
|
||
module.exports = async function updateNoticeYear( | ||
/** @type {{ octokit: Octokit, context: Context }} */ | ||
{ octokit, context } | ||
) { | ||
const now = new Date() | ||
// Change to UTC+8 | ||
now.setHours(now.getHours() + 8) | ||
const newYear = now.getFullYear() | ||
console.log('Prepare to update notice year to', newYear) | ||
|
||
const noticeContent = `Apache ECharts | ||
Copyright 2017-${newYear} The Apache Software Foundation | ||
This product includes software developed at | ||
The Apache Software Foundation (https://www.apache.org/).` | ||
|
||
const repoCtx = context.repo | ||
|
||
const repoInfo = (await octokit.rest.repos.get(repoCtx)).data | ||
const defaultBranchName = repoInfo.default_branch | ||
const remoteNoticeFile = (await octokit.rest.repos.getContent({ | ||
...repoCtx, | ||
path: 'NOTICE', | ||
ref: defaultBranchName | ||
})).data | ||
const remoteNoticeContent = base64ToUtf8(remoteNoticeFile.content) | ||
if (remoteNoticeContent === noticeContent) { | ||
console.log('NOTICE year is already updated.') | ||
return | ||
} | ||
|
||
console.log('Ready to update the NOTICE file:\n' + noticeContent) | ||
|
||
const defaultBranch = (await octokit.rest.repos.getBranch({ | ||
...repoCtx, | ||
branch: defaultBranchName | ||
})).data | ||
|
||
const newBranchName = `bot/update-notice-year/${newYear}` | ||
await octokit.rest.git.createRef({ | ||
...repoCtx, | ||
ref: `refs/heads/${newBranchName}`, | ||
sha: defaultBranch.commit.sha | ||
}) | ||
console.log('Created a new branch:', newBranchName) | ||
|
||
await octokit.rest.repos.createOrUpdateFileContents({ | ||
...repoCtx, | ||
path: 'NOTICE', | ||
message: `chore: update NOTICE year to ${newYear}`, | ||
content: utf8ToBase64(noticeContent), | ||
sha: remoteNoticeFile.sha, | ||
branch: newBranchName | ||
}) | ||
|
||
console.log('Updated the NOTICE file on the new branch') | ||
|
||
const pr = (await octokit.rest.pulls.create({ | ||
...repoCtx, | ||
head: newBranchName, | ||
base: defaultBranchName, | ||
maintainer_can_modify: true, | ||
title: `chore: update NOTICE year to ${newYear}`, | ||
body: `## Brief Information | ||
This pull request is in the type of: | ||
- [ ] bug fixing | ||
- [ ] new feature | ||
- [x] others | ||
### What does this PR do? | ||
Update notice year to ${newYear}. 💖 | ||
Happy new year! 祝大家新年快乐!🎇` | ||
})).data | ||
|
||
console.log(`Opened PR #${pr.number} for updating the NOTICE file`) | ||
} | ||
|
||
function utf8ToBase64(data) { | ||
return Buffer.from(data, 'utf-8').toString('base64') | ||
} | ||
|
||
function base64ToUtf8(data) { | ||
return Buffer.from(data, 'base64').toString('utf-8') | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Deploy PR Preview | ||
|
||
on: | ||
workflow_run: | ||
workflows: ['Node CI'] | ||
types: [completed] | ||
|
||
jobs: | ||
on-success: | ||
if: ${{ github.repository_owner == 'apache' }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Determine if workflow build job is successful | ||
id: check-build-success | ||
uses: actions/github-script@v7 | ||
with: | ||
result-encoding: string | ||
script: | | ||
const jobsRes = await github.rest.actions.listJobsForWorkflowRun({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: context.payload.workflow_run.id | ||
}); | ||
return jobsRes.data.jobs.some((job) => job.name.includes('build') && job.conclusion === 'success'); | ||
outputs: | ||
SHOULD_DEPLOY: ${{ steps.check-build-success.outputs.result }} | ||
|
||
deploy: | ||
needs: [on-success] | ||
if: ${{ needs.on-success.outputs.SHOULD_DEPLOY == 'true' }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Install action dependencies | ||
run: | | ||
mkdir .actions | ||
cd .actions | ||
git clone --depth=1 https://github.com/dawidd6/action-download-artifact.git | ||
git clone --depth=1 https://github.com/plainheart/maintain-one-comment.git | ||
- name: Fetch PR dist files | ||
uses: ./.actions/action-download-artifact | ||
with: | ||
workflow: ${{ github.event.workflow.id }} | ||
run_id: ${{ github.event.workflow_run.id }} | ||
name: pr_preview | ||
path: pr-dist | ||
if_no_artifact_found: fail | ||
|
||
- name: Output PR metadata | ||
id: pr-metadata | ||
working-directory: pr-dist | ||
run: | | ||
echo "NUMBER=$(cat pr_number)" >> $GITHUB_OUTPUT | ||
echo "COMMIT_SHA=$(cat pr_commit_sha)" >> $GITHUB_OUTPUT | ||
echo "COMMIT_SHA_SHORT=$(cat pr_commit_sha | cut -c 1-7)" >> $GITHUB_OUTPUT | ||
- name: Deploy dist files | ||
env: | ||
PR_NUMBER: ${{ steps.pr-metadata.outputs.NUMBER }} | ||
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} | ||
working-directory: pr-dist | ||
run: | | ||
export SURGE_DOMAIN=https://echarts-pr-$PR_NUMBER.surge.sh | ||
npx surge --project ./package --domain $SURGE_DOMAIN --token $SURGE_TOKEN | ||
- name: Create comment for PR preview | ||
uses: ./.actions/maintain-one-comment | ||
env: | ||
PR_NUMBER: ${{ steps.pr-metadata.outputs.NUMBER }} | ||
COMMIT_SHA_SHORT: ${{ steps.pr-metadata.outputs.COMMIT_SHA_SHORT }} | ||
with: | ||
body: | | ||
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-${{ env.PR_NUMBER }}@${{ env.COMMIT_SHA_SHORT }} | ||
body-include: '<!-- ECHARTS_PR_PREVIEW -->' | ||
number: ${{ env.PR_NUMBER }} |
Oops, something went wrong.