代码之家  ›  专栏  ›  技术社区  ›  bpereira

Github工作流-在工作流中间添加手动步骤

  •  0
  • bpereira  · 技术社区  · 1 年前

    这就是我的Worfklow现在的样子:

    它并行运行单元测试和集成测试,如果两者都通过,则运行“暂存”和“生产”部署。

    我想知道是否有办法只在部署步骤中添加手动步骤。我不想每次都部署到“暂存”。

    有什么办法实现它吗?

    test.yml

    name: Test, Build
    
    on:
      workflow_call:
    
    jobs:
      all-tests:
        name: All Tests
        runs-on: [self-hosted]
        services:
          postgres:
            image: postgres:11.5-alpine
            env:
              POSTGRES_USER: ''
              POSTGRES_PASSWORD: ''
              POSTGRES_DB: ''
            ports:
              - 5445:5432
            options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
        steps:
          - name: Checkout Repo
            uses: actions/checkout@master
          - name: Run migrations
            env:
              ENVIRONMENT: 'test'
              DATABASE_URL: ''
            run: ./gradlew flywayMigrate
          - name: Integration Test
            env:
              ENVIRONMENT: 'test'
            run: ./gradlew test
    

    deploy.yml

    name: Deploy
    
    on:
      push:
        branches:
          - main
    
    jobs:
      test:
        uses: ./.github/workflows/test.yml
      deploy-staging:
        name: Deploy Staging
        runs-on: [self-hosted]
        needs: [test]
        steps:
          - name: Checkout Repo
            uses: actions/checkout@master
          - name: Migrations
            env:
              ENVIRONMENT: 'staging'
              DATABASE_URL: ${{ secrets.DATABASE_URL_STAGING_MIGRATION }}
            run: ./gradlew flywayMigrate
          - name: Authenticate
            with:
              credentials_json: '${{ secrets.GCP_SA_KEY_STAGING }}'
            uses: 'google-github-actions/auth@v0'
          - name: Print Config Files
            env:
              ENVIRONMENT: 'staging'
            run: ./gradlew appengineShowConfiguration
          - name: Stage Deploy
            env:
              ENVIRONMENT: 'staging'
              DATABASE_URL: ${{ secrets.DATABASE_URL_STAGING }}
            run: ./gradlew appengineDeploy
      deploy-prod:
        name: Deploy Prod
        runs-on: [self-hosted]
        needs: [test]
        steps:
          - name: Checkout Repo
            uses: actions/checkout@master
          - name: Migrations
            env:
              ENVIRONMENT: 'production'
              DATABASE_URL: ${{ secrets.DATABASE_URL_MIGRATION }}
            run: ./gradlew flywayMigrate
          - name: Authenticate
            with:
              credentials_json: '${{ secrets.GCP_SA_KEY }}'
            uses: 'google-github-actions/auth@v0'
          - name: Print Config Files
            env:
              ENVIRONMENT: 'production'
            run: ./gradlew appengineShowConfiguration
          - name: Deploy
            env:
              ENVIRONMENT: 'production'
              DATABASE_URL: ${{ secrets.DATABASE_URL }}
            run: ./gradlew appengineDeploy
    

    Github workflow with test and deploy steps

    1 回复  |  直到 1 年前
        1
  •  1
  •   Roberto Yoc    1 年前

    对于手动部署,您需要 workflow dispatch 事件

    on: workflow_dispatch
    
    jobs:
      deploy-staging:
        name: Deploy Staging
        runs-on: ubuntu-latest
        steps:
          - name: Deploy
            run: <your_staging_deploy_command>
    

    那么你需要 manually run a workflow 使用Github接口。