0

我们已经为 ci/cd 管道设置了 Github 操作,几天前它按预期工作。我们使用 GitHub pr 评论(/deploy staging)将代码部署到 AWS S3 存储桶,一切都按预期工作,但是现在当我们评论 pr(拉取请求)时,部署不会触发,而是在 10 小时后的午夜触发. 这是我的文件。

  1. 工作流/deploy.yml

    名称:“部署”在:[“部署”]

作业:部署:名称:'部署到 ${{ github.event.deployment.environment }}' 运行:ubuntu-latest 步骤:

  - name: Deployment pending
    uses: deliverybot/deployment-status@master
    with:
      state: pending
      token: '${{ github.token }}'

  - name: Copy Repo Files
    uses: actions/checkout@v1

  - name: Set Variables
    id: variables
    run: |
      if [ "$ENVIRONMENT" == "production" ]; then
        echo ::set-output name=DEPLOY_BUCKET::$PROD_BUCKET
        export PUBLIC_URL=https://app.virtualcombine.com/
      else
        echo ::set-output name=DEPLOY_BUCKET::$STAGING_BUCKET
        export PUBLIC_URL=https://staging-app.virtualcombine.com/
      fi
      export VERSION="$(node -pe "require('./package.json').version")"
      export COMMIT="$(sed -e 's/^\(.\{9\}\).*/\1/' <<< $(git rev-parse --short HEAD))"
      echo ::set-output name=SOURCE_PATH::$VERSION/$COMMIT/$ENVIRONMENT
    env:
      ENVIRONMENT: ${{ github.event.deployment.environment }}
      PROD_BUCKET: ${{ secrets.PROD_S3_UI_BUCKET }}
      STAGING_BUCKET: ${{ secrets.STAGING_S3_UI_BUCKET }}

  - name: Configure AWS credentials
    uses: aws-actions/configure-aws-credentials@v1
    with:
      aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
      aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      aws-region: us-east-2

  - name: 'Deploy to ${{ github.event.deployment.environment }}'
    run: |
      aws s3 sync s3://${SOURCE_BUCKET_NAME}/${SOURCE_BUCKET_PATH} s3://${DEST_BUCKET_NAME} --delete
    env:
      SOURCE_BUCKET_NAME: ${{ secrets.AWS_S3_RELEASE_BUCKET }}
      SOURCE_BUCKET_PATH: ${{ steps.variables.outputs.SOURCE_PATH }}
      DEST_BUCKET_NAME: ${{ steps.variables.outputs.DEPLOY_BUCKET }}

  - name: 'Deployment success'
    if: success()
    uses: 'deliverybot/deployment-status@master'
    with:
      state: 'success'
      token: '${{ github.token }}'

  - name: 'Deployment failure'
    if: failure()
    uses: 'deliverybot/deployment-status@master'
    with:
      state: 'failure'
      token: '${{ github.token }}'
  1. 工作流/mail.yml

    名称:Virtual Combine App UI

on:推送:分支:-'release/ '-'hotfix/ '

作业:lint_test:名称:受影响的 Lint 和测试运行:ubuntu-latest 步骤:-名称:复制 Repo 文件使用:actions/checkout@v1

  - name: Yarn Install
    uses: bahmutov/npm-install@v1
    with:
      useLockFile: true

  - name: Setup Env Files
    run: |
      touch src/config/env-urls.js
      echo "$ENV_URL_FILE" > src/config/env-urls.js
    env:
      ENV_URL_FILE: ${{ secrets.ALPHA_URL_FILE }}

  - name: Lint Affected
    run: yarn lint

  - name: Test Affected
    run: yarn test

build_staging:名称:构建分期需要:- lint_test

runs-on: ubuntu-latest
steps:
  - name: Copy Repo Files
    uses: actions/checkout@v1

  - name: Yarn Install
    uses: bahmutov/npm-install@v1
    with:
      useLockFile: true

  - name: Setup Env Files
    run: |
      touch src/config/env-urls.js
      echo "$ENV_URL_FILE" > src/config/env-urls.js
    env:
      ENV_URL_FILE: ${{ secrets.ALPHA_URL_FILE }}

  - name: Set Version
    id: version
    run: |
      if [ "$EVENT" == "push" ]; then
        export COMMIT="$(sed -e 's/^\(.\{9\}\).*/\1/' <<< "$SHA")"
      else
        export COMMIT="$(sed -e 's/^\(.\{9\}\).*/\1/' <<< "$PR_SHA")"
      fi
      export VERSION="$(node -pe "require('./package.json').version")"
      echo ::set-output name=COMMIT::$COMMIT
      echo ::set-output name=VERSION::$VERSION
      echo ::set-output name=DEST_DIR::$VERSION/$COMMIT/staging
    env:
      EVENT: ${{ github.event_name }}
      SHA: ${{ github.sha }}
      PR_SHA: ${{ github.event.pull_request.head.sha }}

  - name: Build
    run: yarn build
    env:
      DEPLOY_COMMIT: ${{ steps.version.outputs.COMMIT }}

  - name: Create Version File
    run: |
      echo "$VERSION/$COMMIT" > dist/apps/web/version.txt
    env:
      VERSION: ${{ steps.version.outputs.VERSION }}
      COMMIT: ${{ steps.version.outputs.COMMIT }}

  - name: Sync to S3
    uses: jakejarvis/s3-sync-action@master
    with:
      args: --quiet --delete
    env:
      AWS_S3_BUCKET: ${{ secrets.AWS_S3_RELEASE_BUCKET }}
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      AWS_REGION: 'us-west-2'
      SOURCE_DIR: 'dist/apps/web'
      DEST_DIR: ${{ steps.version.outputs.DEST_DIR }}

build_production:名称:构建生产需要:- lint_test

runs-on: ubuntu-latest
steps:
  - name: Copy Repo Files
    uses: actions/checkout@v1

  - name: Yarn Install
    uses: bahmutov/npm-install@v1
    with:
      useLockFile: true

  - name: Setup Env Files
    run: |
      touch src/config/env-urls.js
      echo "$ENV_URL_FILE" > src/config/env-urls.js
    env:
      ENV_URL_FILE: ${{ secrets.PROD_URL_FILE }}

  - name: Set Version
    id: version
    run: |
      if [ "$EVENT" == "push" ]; then
        export COMMIT="$(sed -e 's/^\(.\{9\}\).*/\1/' <<< "$SHA")"
      else
        export COMMIT="$(sed -e 's/^\(.\{9\}\).*/\1/' <<< "$PR_SHA")"
      fi
      export VERSION="$(node -pe "require('./package.json').version")"
      echo ::set-output name=VERSION::$VERSION
      echo ::set-output name=COMMIT::$COMMIT
      echo ::set-output name=DEST_DIR::$VERSION/$COMMIT/production
    env:
      EVENT: ${{ github.event_name }}
      SHA: ${{ github.sha }}
      PR_SHA: ${{ github.event.pull_request.head.sha }}

  - name: Build
    run: yarn build
    env:
      DEPLOY_COMMIT: ${{ steps.version.outputs.COMMIT }}

  - name: Create Version File
    run: |
      echo "$VERSION/$COMMIT" > dist/apps/web/version.txt
    env:
      VERSION: ${{ steps.version.outputs.VERSION }}
      COMMIT: ${{ steps.version.outputs.COMMIT }}

  - name: Sync to S3
    uses: jakejarvis/s3-sync-action@master
    with:
      args: --quiet --delete
    env:
      AWS_S3_BUCKET: ${{ secrets.AWS_S3_RELEASE_BUCKET }}
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      AWS_REGION: 'us-west-2'
      SOURCE_DIR: 'dist/apps/web'
      DEST_DIR: ${{ steps.version.outputs.DEST_DIR }}
  1. 部署.yml

    暂存:环境:暂存生产环境:真

生产:环境:生产生产环境:真

4

0 回答 0