Skip to content

Commit

Permalink
ci: add preview and publish workflows (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: frank-zsy <[email protected]>
  • Loading branch information
frank-zsy authored May 16, 2024
1 parent 586639f commit a74bda5
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/publish.yml
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 }}
77 changes: 77 additions & 0 deletions .github/workflows/pull_preview.yml
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 }}/

0 comments on commit a74bda5

Please sign in to comment.