我正在尝试修改自动生成的 Firebase 部署工作流程。
我想捕获部署 URL 并将其吐出到摘要页面。部署步骤会在日志中返回 url:
Deploying to Firebase preview channel pr---my-branch
/usr/local/bin/npx firebase-tools@latest hosting:channel:deploy pr---my-branch --expires 7d --project my-project --json
npm WARN exec The following package was not found and will be installed: [email protected]
***
"status": "success",
"result": ***
"my-project": ***
"site": "my-project",
"url": "https://my-project--pr-my-branch-w97r0jc8.web.app",
"version": "",
"expireTime": "2024-01-19T20:51:42.668928198Z"
***
***
***::endgroup::
***
details_url: 'https://my-project--pr-my-branch-w97r0jc8.web.app',
conclusion: 'success',
output: ***
title: 'Deploy preview succeeded',
summary: '[https://my-project--pr-my-branch-w97r0jc8.web.app](https://my-project--pr-my-branch-w97r0jc8.web.app)'
***
***
到目前为止我都失败了。因此我尝试从相同的 GitHub 变量构建它:
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools
name: Deploy to Firebase Hosting on demand
"on":
workflow_dispatch:
jobs:
build_and_preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci && npm run build
- id: deploy
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}"
projectId: my-project
channelId: "pr-${{ github.event.number }}-${{ github.event.pull_request.head.ref }}-${{ github.head_ref || github.ref_name }}"
- name: Set step summary
run: echo '🚀[Preview URL](https://my-project--pr-${{ github.event.number }}-${{ github.event.pull_request.head.ref }}-${{ github.head_ref || github.ref_name }}.web.app)' >> $GITHUB_STEP_SUMMARY
结果是:
https://my-project--pr---my-branch.web.app/
我想要得到的是:
https://my-project--pr-my-branch-w97r0jc8.web.app
我需要了解
w97r0jc8
部分的来源并重建创建 URL 的方式,或者从前面步骤的日志中捕获实际的 URL。请指教。
我还了解到,仅当工作流程由
github.event.number
触发时,github.event.pull_request.head.ref
、github.head_ref
和 pull_request
才可用,因此对于手动调度的工作流程,我可能需要以不同的方式进行此设置。 pull_request
触发了一个。
事实证明这很容易......荣誉@jonrsharpe!对于其他陷入困境的人,以下是如何获取某个步骤的输出变量:
- name: Set step summary
run: echo '🚀[Preview URL](${{ steps.deploy.outputs.details_url }})' >> $GITHUB_STEP_SUMMARY