我有一个 git 操作,我必须确保没有要添加的内容然后不提交或推送。
但是我如何检查是否有需要添加和提交的内容。
这是我目前的做法的一个例子:
on:
push:
branches:
- testing
name: Build
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out current commit
- name: Install
run: npm install
- name: Build
run: npm run build
- name: Commit
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Build" -a
- name: Push
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
最佳答案
以下是我的建议:
- 您可以添加一个单独的步骤来进行差异检查
- 使用差异检查输出进行添加/提交
它会像下面这样(以下示例是我们如何提取新翻译并 checkin 更改):
- name: Check if there is any new translations
id: verify_diff
run: |
npx prettier -w packages/trn/transifex
git diff --quiet packages/trn/transifex/en_US.json || echo "::set-output name=new_translations_exist::true"
- name: Commit files
if: steps.verify_diff.outputs.new_translations_exist == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add packages/trn/transifex
git commit -m "bot: extract the latest transactions"
git push
关于Github 操作无需提交,工作树干净,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71362008/