如何在 GitHub Actions 工作流程中获取多个部署 URL?

问题描述 投票:0回答:0

我有一个针对每个拉取请求运行 Playwright 测试的 GitHub Actions 工作流,我想获取与每个拉取请求关联的两个部署的 URL。

这是我的工作流程示例:

name: Playwright Tests
on:
  deployment_status:
  workflow_dispatch:
    inputs:
      environment:
        description: 'Environment to run tests against'
        type: environment
        required: true
jobs:
  test:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    if: github.event.deployment_status.state == 'success'
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18.x'
      - name: Install dependencies
        run: yarn install
      - name: Go to Dashboard directory
        run: cd apps/dashboard
      - name: Install Playwright
        run: npx playwright install --with-deps
      - name: Get deployment URLs
        run: |
            deployment_urls=()
            for deployment in "${{ toJson(github.event.deployments) }}"; do
             target_url=$(echo $deployment | jq -r '.target_url')
             deployment_urls+=($target_url)
            done
            echo "Deployment URLs: ${deployment_urls[@]}"
        id: get_urls
      - name: Run Playwright tests
        run: npx playwright test
        env:
          # This might depend on your test-runner/language binding
          DEPLOYMENT_URL1: ${{ steps.get_urls.outputs.deployment_urls[0] }}
          DEPLOYMENT_URL2: ${{ steps.get_urls.outputs.deployment_urls[1] }}
      - name: Upload Playwright reports
        uses: actions/upload-artifact@v3
        with:
          name: playwright-report
          path: playwright-report

但是,当我尝试在我的工作流程中访问

github.event.deployments
数组时,它返回 null。我也尝试过使用
github.event.deployment_status.target_url
但它只返回最新的 URL。

我不想使用任何 API 来获取那些部署 URL!如果您需要更多详细信息,请告诉我,谢谢!

更新:

我对工作流文件进行了更改,将

github.deployments
替换为
github.deployment
。尽管转储了整个有效载荷,它仍然只显示最近的部署。

github github-actions environment
© www.soinside.com 2019 - 2024. All rights reserved.