• 全国 [切换]
  • 二维码
    错改网

    手机WAP版

    手机也能找商机,信息同步6大终端平台!

    微信小程序

    微信公众号

    当前位置: 首页 » 行业新闻 » 热点新闻 » 正文

    Workflow: check whether the PR is up to date

    放大字体  缩小字体 发布日期:2021-04-21 13:15:04   浏览次数:742  发布人:7af1****  IP:124.223.189***  评论:0
    导读

    Someone asked me to review his pr which is not ye up to date with the target branch. I think there should be a github action which can auto mark the pr as failed if it isn't up to date yet. So I creat

    Someone asked me to review his pr which is not ye up to date with the target branch. I think there should be a github action which can auto mark the pr as failed if it isn't up to date yet.

    So I create a github action. Here's the steps:

    1. In the repository, create a folder named .github
    2. In the .github folder, create a child folder named workflows
    3. In the workflows folder, create a file with whatever name you like, in my case check-pr.yml
    4. In the check-pr.yml, add the content below:

    name: PR-Check on: pull_request: branches: [ "dev", "main", "prod" ] jobs: Check-pr-uptodate: runs-on: ubuntu-latest steps: - name: Check out repository with: fetch-depth: 0 uses: actions/checkout@v4 - run: echo "The repository has been cloned to the runner" - run: | if git merge-base --is-ancestor origin/${{github.event.pull_request.base.ref}} HEAD then echo "Branch is up to date" else echo "Branch needs update" exit 1 fi

    Explanation:

    • on: specify the event to trigger the action.
      • pull_request: the action is triggered by pull request.
        • branches: the target branch of the pr. If the pr's target branch is not in the list, the action will not be triggered.
    • jobs: job's the action will do. You can set multiple jobs in one action file.
      • Check-pr-uptodate: this is a custom job name, you can set to whatever you like.
        • runs-on: the operating system you want to run the action on.
        • steps: One job may have many steps, they are executed by sequence.
          • name: You can give the step a name
          • uses: the already ready to use actions provided, you can search them on github.
          • with: the options applied to the action of the current step
          • run: command to run

    As you can see, some steps does not have a name. In fact, the last two steps written by my self does not have a name. But the first one which is from github actions collection does, and it also has a uses option to specify what action to run.

    I searched a few and don't know if it works if you place the file in other branch other than main(the default branch).But I recommended you don't waste two much time on it and just place it in the main branch, then it will work perfectly.

    It looks like so easy to do but I took half of a day to make it work, honestly.

    本文由博客一文多发平台 OpenWrite 发布!

    不推荐电脑端访问(用户少)
    请微信扫一扫,查看完整信息(记得微信收藏)
     
    (文/匿名(若涉版权问题请联系我们核实发布者) / 非法信息举报 / 删稿)
    打赏
    免责声明
    • 
    本文为昵称为 7af1**** 发布的作品,本文仅代表发布者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,发布者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们154208694@qq.com删除,我们积极做(权利人与发布者之间的调停者)中立处理。郑重说明:不 违规举报 视为放弃权利,本站不承担任何责任!
    有个别老鼠屎以营利为目的遇到侵权情况但不联系本站或自己发布违规信息然后直接向本站索取高额赔偿等情况,本站一概以诈骗报警处理,曾经有1例诈骗分子已经绳之以法,本站本着公平公正的原则,若遇 违规举报 我们100%在3个工作日内处理!
    0 条相关评论
     

    (c)2008-现在 cuogai.com All Rights Reserved.