feat: Umami 测试 #35
This file contains hidden or 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
| name: Build and Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| INJECT_HEAD: ${{ vars.INJECT_HEAD }} | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| DEPLOY_NAME: ${{ secrets.DEPLOY_NAME }} | |
| DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Get Info | |
| id: vars | |
| run: | | |
| echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
| echo "TIMESTAMP=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Build | |
| run: | | |
| pnpm run build | |
| - name: Compress dist to ZIP | |
| run: | | |
| ZIP_NAME=${{ env.DEPLOY_NAME }}_${{ env.COMMIT }}_${{ env.TIMESTAMP }}.zip | |
| echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV | |
| zip -r $ZIP_NAME dist | |
| - name: Upload artifact to COS | |
| uses: TencentCloud/cos-action@v1 | |
| with: | |
| secret_id: ${{ secrets.COS_SECRET_ID }} | |
| secret_key: ${{ secrets.COS_SECRET_KEY }} | |
| cos_bucket: ${{ secrets.COS_BUCKET }} | |
| cos_region: ${{ secrets.COS_REGION }} | |
| local_path: ${{ env.ZIP_NAME }} | |
| remote_path: ${{ secrets.ARTIFACT_PATH }}${{ env.ZIP_NAME }} | |
| - name: Deploy to server | |
| env: | |
| PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} | |
| run: | | |
| ARTIFACT_URL="https://${{ secrets.COS_BUCKET }}.cos.${{ secrets.COS_REGION }}.myqcloud.com/${{ secrets.ARTIFACT_PATH }}${{ env.ZIP_NAME }}" | |
| ACTION_JSON='{"artifactUrl":"'$ARTIFACT_URL'","extractDir":"'$DEPLOY_PATH'"}' | |
| SIGNED_KEY=$(echo -n "$ACTION_JSON" | openssl dgst -sha256 -sign <(echo "$PRIVATE_KEY") | base64 | tr -d '\n') | |
| curl -X POST ${{ secrets.DEPLOY_SERVER }} \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"deployKey":"'$SIGNED_KEY'","action":'$ACTION_JSON'}' |