-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add preview and publish workflows (#18)
Signed-off-by: frank-zsy <[email protected]>
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 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,36 @@ | ||
name: publish | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup node 18 env | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18' | ||
cache: "npm" | ||
|
||
- name: build | ||
run: | | ||
git config --global url."https://github.com/".insteadOf git://github.com/ | ||
npm install | ||
npm run build | ||
- name: Publish to OSS | ||
uses: tvrcgo/oss-action@master | ||
with: | ||
key-id: ${{ secrets.OSS_ACCESS_KEY_ID }} | ||
key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }} | ||
region: ${{ secrets.OSS_REGION }} | ||
bucket: ${{ secrets.OSS_BUCKET }} | ||
assets: | | ||
./build/**:${{ secrets.OSS_TARGET_PATH }} |
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,77 @@ | ||
name: pr_test | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
preview: | ||
if: github.event.issue.pull_request | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
||
- name: Check comment command | ||
uses: actions-ecosystem/action-regex-match@v2 | ||
id: regex-match | ||
with: | ||
text: ${{ github.event.comment.body }} | ||
regex: '^/preview$' | ||
|
||
- uses: actions/github-script@v3 | ||
id: get-pr | ||
if: ${{ steps.regex-match.outputs.match != '' }} | ||
with: | ||
script: | | ||
const request = { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number | ||
} | ||
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`) | ||
try { | ||
const result = await github.pulls.get(request) | ||
return result.data | ||
} catch (err) { | ||
core.setFailed(`Request failed with error ${err}`) | ||
} | ||
- name: Check out pull request head | ||
if: ${{ steps.regex-match.outputs.match != '' }} | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }} | ||
ref: ${{ fromJSON(steps.get-pr.outputs.result).head.sha }} | ||
|
||
- name: Setup node 18 env | ||
if: ${{ steps.regex-match.outputs.match != '' }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18' | ||
cache: "npm" | ||
|
||
- name: Build the website | ||
if: ${{ steps.regex-match.outputs.match != '' }} | ||
run: | | ||
git config --global url."https://github.com/".insteadOf git://github.com/ | ||
npm install | ||
npm run build | ||
- name: Upload to OSS | ||
if: ${{ steps.regex-match.outputs.match != '' }} | ||
uses: tvrcgo/oss-action@master | ||
with: | ||
key-id: ${{ secrets.OSS_ACCESS_KEY_ID }} | ||
key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }} | ||
region: ${{ secrets.OSS_REGION }} | ||
bucket: ${{ secrets.OSS_BUCKET }} | ||
assets: | | ||
./build/**:${{ secrets.OSS_TARGET_PATH }}pull_${{ github.event.issue.number }}/ | ||
- name: Create comment | ||
if: ${{ steps.regex-match.outputs.match != '' }} | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
issue-number: ${{ github.event.issue.number }} | ||
body: 🪧The website for this PR is deployed at https://open-digger.cn${{ secrets.OSS_TARGET_PATH }}pull_${{ github.event.issue.number }}/ |