Skip to content

add ali-oss deploy

add ali-oss deploy #9

Workflow file for this run

name: Automatic Deployment
on:
push:
tags:
- 'v*' # 当推送带有 v 前缀的标签时触发
jobs:
deploy-prod:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: yarn
- name: Export BUILD_MODE
run: export BUILD_MODE=release
- name: Get version
run: |
FULL_VERSION=$(node -p -e "require('./lerna.json').version")
MAJOR_VERSION=$(echo $FULL_VERSION | cut -d. -f1)
echo "VERSION=$MAJOR_VERSION" >> $GITHUB_ENV
echo "version=$MAJOR_VERSION" >> $GITHUB_OUTPUT
env:
BUILD_MODE: release
- name: Build bundle
run: yarn build:bundle
- name: Deploy to prod
run: node ./scripts/deploy/deploy-oss.js prod v${VERSION}
env:
OSS_ENDPOINT: ${{ secrets.OSS_ENDPOINT }}
OSS_REGION: ${{ secrets.OSS_REGION }}
OSS_ACCESS_KEY: ${{ secrets.OSS_ACCESS_KEY }}
OSS_BUCKET: ${{ secrets.OSS_BUCKET }}
OSS_SECRET_KEY: ${{ secrets.OSS_SECRET_KEY }}
publish-npm:
needs: deploy-prod
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org/'
- name: Install dependencies
run: yarn
- name: Publish to NPM
run: node ./scripts/deploy/publish-npm.js
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
post-notify-success:
needs: publish-npm
runs-on: ubuntu-latest
if: success()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prepare notification
run: |
COMMIT_MESSAGE=$(git show-branch --no-name HEAD)
echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV
echo "COMMIT_URL=https://github.com/${{ github.repository }}/commit/${{ github.sha }}" >> $GITHUB_ENV
- name: Notify deployment success
uses: slackapi/slack-github-action@v1.25.0
with:
channel-id: 'rum'
payload: |
{
"text": ":rocket: ${{ github.repository }} <${{ env.COMMIT_URL }}|${{ env.COMMIT_MESSAGE }}> *automatically* deployed to :earth_americas:."
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
post-notify-failure:
needs: publish-npm
runs-on: ubuntu-latest
if: failure()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prepare notification
run: |
COMMIT_MESSAGE=$(git show-branch --no-name HEAD)
echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV
echo "BUILD_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_ENV
- name: Notify deployment failure
uses: slackapi/slack-github-action@v1.25.0
with:
channel-id: 'rum'
payload: |
{
"text": ":host-red: ${{ github.repository }} *automatic* deployment of <${{ env.BUILD_URL }}|${{ env.COMMIT_MESSAGE }}> failed."
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}