我在这里看到了一些关于减少 worfklow 文件中条件语句数量的巧妙想法https://stackoverflow.com/a/79267991并尝试为主工作流程文件创建一个包装器。
因此,我为工作流程文件创建了一个包装器,就像答案中建议的那样
name: Wrapper for Salesforce DX Pull Requests
on:
push:
paths:
- "unpackaged/force-app/**"
- ".github/workflows/sfdxPullRequests.yml"
- "pmdRules.xml"
jobs:
verify:
runs-on: ubuntu-latest
outputs:
auth: ${{steps.setauth.outputs.url}}
deploy: ${{steps.deploy.outputs.text}}
apex-tests: ${{ steps.apex.outputs.text }}
coverage: ${{ steps.apex.outputs.coverage }}
name: Verify conditions and run the main flow
steps:
- name: "Checkout source code"
uses: actions/checkout@v3
- name: "Verify if project has been setup"
id: "verify"
shell: bash
env:
SFDX_DISABLE_DNS_CHECK: true
run: |
cd unpackaged
if [ -e sfdx-project.json ]
then
echo "File sfdx-project.json is present, project has been setup"
echo "setup=1" >> $GITHUB_OUTPUT
else
echo "File not found, project has not been setup"
echo "setup=0" >> $GITHUB_OUTPUT
fi
# Checkout the repo - uses: actions/checkout@v3 with: # Repository name with owner. For example, actions/checkout Default: ${{ github.repository }}
cd ..
- name: "Run main workflow file"
if: ${{ steps.verify.outputs.setup == 1 }}
uses: ./.github/workflows/sfdxPullRequests.yml
但我收到错误
Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/uletas/uletas/.github/workflows/sfdxPullRequests.yml'. Did you forget to run actions/checkout before running your local action?
这让我很困惑,为什么我必须将我的主工作流程文件重命名为操作?
无论如何,我已将我的主工作流程文件从
./.github/workflows/sfdxPullRequests.yml
重命名为 ./.github/workflows/pullRequests/action.yml
并再次尝试并收到另一个错误
Error
No event triggers defined in `on`
这让我很困惑,因为答案建议从主文件中删除
on
条件,以便仅运行包装器工作流程。
无论如何,我已经阅读了文档,发现我可以使用
on:
workflow_call
在我的主文件中指示可以从其他工作流程调用此工作流程。
但是,当我再次运行此工作流程时,
name: Wrapper for Salesforce DX Pull Requests
on:
push:
paths:
- "unpackaged/force-app/**"
- ".github/workflows/sfdxPullRequests.yml"
- "pmdRules.xml"
jobs:
verify:
runs-on: ubuntu-latest
outputs:
auth: ${{steps.setauth.outputs.url}}
deploy: ${{steps.deploy.outputs.text}}
apex-tests: ${{ steps.apex.outputs.text }}
coverage: ${{ steps.apex.outputs.coverage }}
name: Verify conditions and run the main flow
steps:
- name: "Checkout source code"
uses: actions/checkout@v3
- name: "Verify if project has been setup"
id: "verify"
shell: bash
env:
SFDX_DISABLE_DNS_CHECK: true
run: |
cd unpackaged
if [ -e sfdx-project.json ]
then
echo "File sfdx-project.json is present, project has been setup"
echo "setup=1" >> $GITHUB_OUTPUT
else
echo "File not found, project has not been setup"
echo "setup=0" >> $GITHUB_OUTPUT
fi
# Checkout the repo - uses: actions/checkout@v3 with: # Repository name with owner. For example, actions/checkout Default: ${{ github.repository }}
cd ..
- name: "Run main workflow file"
if: ${{ steps.verify.outputs.setup == 1 }}
uses: ./.github/workflows/pullRequests
这不起作用,我收到了另一个错误,例如
Unrecognized named-value: 'steps'. Located at position 1 within expression: steps.check.outputs.alive
我又迷茫了,尝试更换
jobs:
deployCodeAndRunTestsOnValEnv:
runs-on: ubuntu-latest
outputs:
auth: ${{steps.setauth.outputs.url}}
deploy: ${{steps.deploy.outputs.text}}
apex-tests: ${{ steps.apex.outputs.text }}
coverage: ${{ steps.apex.outputs.coverage }}
进入
jobs:
deployCodeAndRunTestsOnValEnv:
runs-on: ubuntu-latest
outputs:
auth:
value: ${{steps.setauth.outputs.url}}
deploy:
value: ${{steps.deploy.outputs.text}}
apex-tests:
value: ${{ steps.apex.outputs.text }}
coverage:
value: ${{ steps.apex.outputs.coverage }}
然而,在我的主要工作流程文件上,这也没有帮助。
这完全不可能吗?
这个文档说我什至不必将我的主工作流程文件重命名为
action.yml
。这里出了什么问题?
看起来我还不明白我不能在操作步骤中使用可重用的工作流程。
所以我需要更新我的工作流程以从
job
级别调用主工作流程
jobs:
check-if-there-are-commits:
runs-on: ubuntu-latest
outputs:
alive: ${{ steps.check.outputs.alive }}
alive2: ${{ steps.check.outputs.alive2 }}
setup: ${{ steps.verify.outputs.setup }}
...
run-main-build:
needs: check-if-there-are-commits
if: ${{ ( needs.check-if-there-are-commits.outputs.alive == 'true' || needs.check-if-there-are-commits.outputs.alive2 == 'true' ) && needs.check-if-there-are-commits.outputs.setup == 1 }}
uses: ./.github/workflows/sfdxNightlyJob.yml
with:
alive: ${{ needs.check-if-there-are-commits.outputs.alive }}