mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-18 10:59:10 +08:00
chore(project): use github workflow for website preview (#3387)
* chore(project): use github workflow for website preview * chore: update PULL_REQUEST_NUMBER * fix: typo * chore: add pull_request for test * fix: json format * fix: add robot test * fix: update request * chore: update var * chore: update var & remove test * chore: improve workflow * chore: upgrade workflow
This commit is contained in:
parent
29545d1ea2
commit
a2be1973ea
64
.github/azure-pipelines.yml
vendored
64
.github/azure-pipelines.yml
vendored
@ -1,64 +0,0 @@
|
||||
name: Element Plus
|
||||
|
||||
trigger: none
|
||||
|
||||
pr:
|
||||
autoCancel: true
|
||||
branches:
|
||||
exclude:
|
||||
- gh-pages
|
||||
|
||||
pool:
|
||||
vmImage: 'ubuntu-latest'
|
||||
|
||||
variables:
|
||||
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
|
||||
|
||||
stages:
|
||||
- stage: Preview
|
||||
jobs:
|
||||
- job: Build_Preview
|
||||
steps:
|
||||
- checkout: self
|
||||
displayName: 'Checkout'
|
||||
clean: true
|
||||
fetchDepth: 1
|
||||
- task: NodeTool@0
|
||||
displayName: 'Install Node.js'
|
||||
inputs:
|
||||
versionSpec: '12.20.0'
|
||||
- task: Cache@2
|
||||
inputs:
|
||||
key: 'yarn | "$(Agent.OS)" | yarn.lock'
|
||||
restoreKeys: |
|
||||
yarn | "$(Agent.OS)"
|
||||
yarn
|
||||
path: $(YARN_CACHE_FOLDER)
|
||||
displayName: Cache Yarn packages
|
||||
- script: yarn bootstrap
|
||||
displayName: 'Project bootstrap'
|
||||
- script: yarn website-build
|
||||
displayName: 'Build website'
|
||||
- script: |
|
||||
export DEPLOY_DOMAIN=https://preview-${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}-element-plus.surge.sh
|
||||
echo "Deploy to $DEPLOY_DOMAIN"
|
||||
npx surge --project ./website-dist --domain $DEPLOY_DOMAIN
|
||||
displayName: 'Deploy Site'
|
||||
env:
|
||||
SURGE_LOGIN: $(SURGE_LOGIN)
|
||||
SURGE_TOKEN: $(SURGE_TOKEN)
|
||||
- script: |
|
||||
export DEPLOY_DOMAIN=https://preview-${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}-element-plus.surge.sh
|
||||
curl -X POST ${BOT_URL} -H 'Content-Type:application/json' --data-raw '{"botAction":"Preview", "pr":'${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}', "url":"'${DEPLOY_DOMAIN}'"}'
|
||||
displayName: 'Update PR comment'
|
||||
env:
|
||||
BOT_URL: $(BOT_URL)
|
||||
- job: Build_Preview_Failed
|
||||
dependsOn: Build_Preview
|
||||
condition: failed()
|
||||
steps:
|
||||
- script: |
|
||||
curl -X POST ${BOT_URL} -H 'Content-Type:application/json' --data-raw '{"status":"error", "botAction":"Preview", "pr":'${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}'}'
|
||||
displayName: 'Update PR comment'
|
||||
env:
|
||||
BOT_URL: $(BOT_URL)
|
50
.github/workflows/preview-build.yml
vendored
Normal file
50
.github/workflows/preview-build.yml
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
name: Website Preview
|
||||
|
||||
on: pull_request
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
PULL_REQUEST_NUMBER: ${{ github.event.number }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v2
|
||||
|
||||
- name: Cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: node_modules
|
||||
key: node_modules-${{ hashFiles('**/yarn.lock') }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn bootstrap
|
||||
|
||||
- name: Build website
|
||||
run: yarn website-build
|
||||
|
||||
# share website dist
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: website
|
||||
path: website-dist/
|
||||
retention-days: 1
|
||||
|
||||
# write pr.txt for share
|
||||
- name: Save pr number
|
||||
if: ${{ always() }}
|
||||
run: echo ${PULL_REQUEST_NUMBER} > ./pr.txt
|
||||
|
||||
# share pr number
|
||||
- name: Upload pr number
|
||||
if: ${{ always() }}
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: pr
|
||||
path: ./pr.txt
|
||||
retention-days: 1
|
80
.github/workflows/preview-deploy.yml
vendored
Normal file
80
.github/workflows/preview-deploy.yml
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
# This workflow runs on target, so there is no need to worry about secrets
|
||||
name: Website Preview Deploy
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ['Website Preview']
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
# Build successfully, start deployment
|
||||
on-success:
|
||||
name: Build successfully
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||
steps:
|
||||
- name: Download pr number
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
workflow: ${{ github.event.workflow_run.workflow_id }}
|
||||
name: pr
|
||||
|
||||
- name: Output pr number
|
||||
id: pr
|
||||
run: echo "::set-output name=id::$(<pr.txt)"
|
||||
|
||||
- name: Download artifact
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
workflow: ${{ github.event.workflow_run.workflow_id }}
|
||||
workflow_conclusion: success
|
||||
name: website
|
||||
|
||||
- name: Deploy Site
|
||||
run: |
|
||||
export DEPLOY_DOMAIN=https://preview-${PULL_REQUEST_NUMBER}-element-plus.surge.sh
|
||||
echo "Deploy to $DEPLOY_DOMAIN"
|
||||
npx surge --project ./ --domain $DEPLOY_DOMAIN --token $SURGE_TOKEN
|
||||
env:
|
||||
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
|
||||
PULL_REQUEST_NUMBER: ${{ steps.pr.outputs.id }}
|
||||
|
||||
- name: Deploy has succeeded
|
||||
if: ${{ success() }}
|
||||
run: |
|
||||
export DEPLOY_DOMAIN=https://preview-${PULL_REQUEST_NUMBER}-element-plus.surge.sh
|
||||
curl -X POST ${BOT_URL} -H 'Content-Type:application/json' --data-raw '{"botAction":"Preview", "pr":'${PULL_REQUEST_NUMBER}', "url":"'${DEPLOY_DOMAIN}'"}'
|
||||
env:
|
||||
BOT_URL: ${{ secrets.BOT_URL }}
|
||||
PULL_REQUEST_NUMBER: ${{ steps.pr.outputs.id }}
|
||||
|
||||
- name: Deploy has failed
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
curl -X POST ${BOT_URL} -H 'Content-Type:application/json' --data-raw '{"status":"error", "botAction":"Preview", "pr":'${PULL_REQUEST_NUMBER}'}'
|
||||
env:
|
||||
BOT_URL: ${{ secrets.BOT_URL }}
|
||||
PULL_REQUEST_NUMBER: ${{ steps.pr.outputs.id }}
|
||||
|
||||
# Build failed, update comment
|
||||
on-failure:
|
||||
name: Build failed
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
||||
steps:
|
||||
- name: Download pr number
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
workflow: ${{ github.event.workflow_run.workflow_id }}
|
||||
name: pr
|
||||
|
||||
- name: Output pr number
|
||||
id: pr
|
||||
run: echo "::set-output name=id::$(<pr.txt)"
|
||||
|
||||
- name: Update comment
|
||||
run: |
|
||||
curl -X POST ${BOT_URL} -H 'Content-Type:application/json' --data-raw '{"status":"error", "botAction":"Preview", "pr":'${PULL_REQUEST_NUMBER}'}'
|
||||
env:
|
||||
BOT_URL: ${{ secrets.BOT_URL }}
|
||||
PULL_REQUEST_NUMBER: ${{ steps.pr.outputs.id }}
|
Loading…
Reference in New Issue
Block a user