GitHub工作流程操作中暂停。

huangapple go评论88阅读模式
英文:

GitHub pause in the middle of workflow action

问题

我已创建了GitHub工作流程。它首先部署到暂存环境,然后在合并时部署到生产环境。我想要的是在暂存环境中暂停部署(以便我可以在暂存环境上进行快速的稳定性测试),然后我有一些手动触发部署到生产环境的方式。

以下是工作流程的YAML文件:

name: main

on:
  push:
    branches:
      - main

jobs:
  test:
    uses: ./.github/workflows/build-test.yml
    secrets: inherit

  staging:
    uses: ./.github/workflows/staging-deploy.yml
    secrets: inherit

  prod:
    name: 'Deploy to Prod'
    uses: ./.github/workflows/deploy.yml
    needs: [test, staging]
    with:
      stage: prod
    secrets: inherit

注意:上述内容是您提供的GitHub工作流程的YAML文件。

英文:

I have created GitHub workflow. It deployed first on staging and than on the production environment on merge. What I want is to pause the deployment at staging, (so that I can do a quick sanity test on staging) and than I have some manual trigger to deploy to production.

Below is the workflow yml file.

name: main

on:
  push:
    branches:
      - main

jobs:
  test:
    uses: ./.github/workflows/build-test.yml
    secrets: inherit

  staging:
    uses: ./.github/workflows/staging-deploy.yml
    secrets: inherit

  prod:
    name: 'Deploy to Prod'
    uses: ./.github/workflows/deploy.yml
    needs: [test, staging]
    with:
      stage: prod
    secrets: inherit

答案1

得分: 0

GitHub Actions允许您通过使用环境来审查部署

首先,您需要在存储库中创建一个环境,并向其添加审阅者

然后,您需要在工作流程中添加一个作业,要求在执行部署到生产环境之前获得批准。

示例中使用名为Prod的环境请求审查:

name: main

on:
  push:
    branches:
      - main

jobs:
  test:
    uses: ./.github/workflows/build-test.yml
    secrets: inherit

  staging:
    uses: ./.github/workflows/staging-deploy.yml
    secrets: inherit

  manual-approval:
    environment: 'Prod'
    runs-on: ubuntu-20.04
    needs:
      - test
      - staging
    steps:
      - run: echo "Approved to Prod"

  prod:
    name: 'Deploy to Prod'
    uses: ./.github/workflows/deploy.yml
    needs: 
      - manual-approval
    with:
      stage: prod
    secrets: inherit
英文:

Github Actions allows you to review deployments by using environments.

First, you will need to create an environment in the repository, and add Reviewers to it.

Then, you will need to add a job in your workflow asking for this approval before executing the deploy to production.

Example with an environment named Prod asking for review:

name: main

on:
  push:
    branches:
      - main

jobs:
  test:
    uses: ./.github/workflows/build-test.yml
    secrets: inherit

  staging:
    uses: ./.github/workflows/staging-deploy.yml
    secrets: inherit

  manual-approval:
    environment: 'Prod'
    runs-on: ubuntu-20.04
    needs:
      - test
      - staging
    steps:
      - run: echo "Approved to Prod"

  prod:
    name: 'Deploy to Prod'
    uses: ./.github/workflows/deploy.yml
    needs: 
      - manual-approval
    with:
      stage: prod
    secrets: inherit

答案2

得分: 0

  • name: 暂停
    run: sleep 3
英文:

To sleep for 3 seconds you can use

- name: Pause
  run: sleep 3

huangapple
  • 本文由 发表于 2023年7月10日 20:09:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76653597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定