簡體   English   中英

如何在 github 操作中獲取存儲庫的提交計數?

[英]How to get commit count of the repository in github actions?

對於我們的應用程序內部版本號,我們使用分支建築物中存儲庫截至日期為止的提交總數。

這個是早些時候使用實現的

git log --oneline | wc -l

之前我們用的是jenkins,現在改成github動作。

當嘗試使用類似的工作流程步驟來計算提交次數時,每次都只給出 1。

我的工作流程。

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ r12.1_githubactions ]
  pull_request:
    branches: [ r12.1_githubactions ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: DevBuild1

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3
      
      # Runs a single command using the runners shell
      - name: Run a one-line script
        run: |
          echo "checking count"
          $count = git log --oneline | wc -l
          echo $count

如果您查看actions/checkout存儲庫,您會注意到默認情況下它只獲取一次提交。 您可以使用fetch-depth參數更改此設置:

 - uses: actions/checkout@v3
   with:
     fetch-depth: 0

從結帳的自述文件:

0 表示所有分支和標簽的所有歷史記錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM