我正在写一个GitHub动作。我希望我的一些步骤只在某些分支上运行。
整个动作被设置为只在master上运行和以开头的分支features/lr.
on:
push:
branches:
- master
- features/lr*
我有一个"部署"。我想在master上运行的步骤和以开头的分支features/lrd. (例如,如果我的分支命名为features/lr-foo,则应该跳过部署步骤。)
我知道我可以这样做if
条件:
- name: Deploy application
if: github.ref == 'refs/heads/master'
我还可以检查github.ref
是否匹配某个前缀或模式吗?它的语法是什么?
像这样的伪代码:
- name: Deploy application
if: github.ref == 'refs/heads/master' || github.ref.matches('refs/heads/lrd*')
提前感谢!
branches
、branches-ignore
、tags
和tags-ignore
关键字接受glob模式。你可以在docs - filter pattern中查看详细信息。
至于使用表达式,文档没有提到matches
函数,但也许你可以使用contains
,startsWith
或endsWith
。
受frenky的回答的启发,我最终在我的步骤中做了以下操作,这是丑陋的,但有效:
- name: Deploy application
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/features/lrd')