Repository navigation
act ignoring if: conditions — steps that should be skipped are running anyway #6190
|
I have a workflow with: - name: Deploy
if: github.ref == 'refs/heads/main'
run: ./deploy.shOn GitHub Actions this step only runs on the main branch. But when I run Is this expected? Does act evaluate {
"ref": "refs/heads/feature/my-branch"
}But the step still executes. This is dangerous because I almost deployed to prod from a local test. |
Replies: 2 comments
|
Yeah this is a known gotcha. The What actually works: pass the branch explicitly with act push -b feature/my-branchThis sets If you want to be extra safe for local testing, you can also add a second guard in the workflow itself: - name: Deploy
if: github.ref == 'refs/heads/main' && !env.ACT
run: ./deploy.sh
|
|
The advice to use First check what this run actually sees. Run - name: Inspect event ref
run: |
echo 'github.ref=${{ github.ref }}'
echo 'github.event.ref=${{ github.event.ref }}'If either value is |
Yeah this is a known gotcha.
actdoesn't automatically pick upgithub.reffrom your event.json the way you'd expect.The
--eventpathflag populatesgithub.event.*fields, butgithub.refandgithub.shacome from a different place — act infers them from your local git state or its own defaults, not from the event payload.What actually works: pass the branch explicitly with
-b:This sets
github.reftorefs/heads/feature/my-branchproperly, and yourif: github.ref == 'refs/heads/main'will correctly skip the deploy step.If you want to be extra safe for local testing, you can also add a second guard in the workflow itself: