如何在 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 indicates all history for all branches and tags.
对于我们的应用程序内部版本号,我们使用的是截至分支建筑物中存储库日期为止的提交总数。
这个是之前使用
实现的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 indicates all history for all branches and tags.