GitHub Actions条件条件正则表达式 [英] GitHub Actions CI Conditional Regex
问题描述
我正在尝试将我的CI工作流程从CircleCI迁移到GitHub Actions.我面临的最后一个主要困难是部署.
I'm trying to move my CI workflow from CircleCI to GitHub Actions. The last major struggle I'm facing is with deployment.
目前,我的工作流程是,当我将标签推入GitHub存储库时,它将运行测试,然后运行部署.唯一的问题是CircleCI筛选器标签仅在标签与正则表达式匹配时运行该作业:/v[0-9]+(\.[0-9]+)*/
.
Currently my workflow is such that when I push a tag to my GitHub repo, it will run the tests, then run the deployment. Only thing is CircleCI filters tags to only run the job if the tag matches the regex: /v[0-9]+(\.[0-9]+)*/
.
在运行部署之前,如何检查确保插入的标签与上面的正则表达式模式匹配?
How can I check to ensure the tag I pushed matches the regex pattern above before running the deployment?
我目前有以下GitHub Actions yml文件:
I currently have the following GitHub Actions yml file:
name: CI
on: [create]
jobs:
# ...
deploy:
runs-on: ubuntu-latest
if: github.event.ref_type == 'tag' && github.event.ref == SOMETHING HERE
steps:
- uses: actions/checkout@v1
# ...
在if
块下,我需要将github.event.ref == SOMETHING HERE
更改为其他内容.我查看了 GitHub Actions文档页面的上下文和表达式语法.但是由于GitHub Actions的灵活性和强大性,似乎应该有一种方法或方法来执行此操作,或者至少应采取某种解决方法.
Under the if
block, I need to change github.event.ref == SOMETHING HERE
to be something else. I have looked in the Contexts and expression syntax for GitHub Actions documentation page. But due to how flexible and powerful GitHub Actions is, it seems like there should be a method or way to do this, or at least some type of workaround.
如何确保标记(github.event.ref
)与正则表达式模式(/v[0-9]+(\.[0-9]+)*/
)匹配?
How can I ensure the tag (github.event.ref
) matches the regex pattern (/v[0-9]+(\.[0-9]+)*/
)?
推荐答案
不幸的是,我认为还没有任何方法可以对if
条件表达式进行正则表达式匹配.
Unfortunately, I don't think there is any way to do regex matching on if
conditional expressions yet.
一种选择是对push
事件使用过滤.
One option is to use filtering on push
events.
on:
push:
tags:
- 'v*.*.*'
Another option is to do the regex check in a separate step where it creates a step output. This can then be used in an if
conditional.
- name: Check Tag
id: check-tag
run: |
if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo ::set-output name=match::true
fi
- name: Build
if: steps.check-tag.outputs.match == 'true'
run: |
echo "Tag is a match"
这篇关于GitHub Actions条件条件正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!