github actions中如何判断仓库是否有变更

name: Auto Update to Github Pages.

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Set SSH Environment
        env:
          DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
        run: |
          mkdir -p ~/.ssh/
          echo "$DEPLOY_KEY" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
          git config --global user.name $USER_NAME
          git config --global user.email $USER_EMAIL
         
      - name: Summit repo to hugo_source branch.
        run: |
          git clone -b ${SUBMMIT_BRANCH} $REPO_SSH ${SUBMMIT_BRANCH}
          cd ${SUBMMIT_BRANCH}
          rm -r content
          cp -r ../${CLONE_DIR}/content .

          git add .
          git status
          git commit -m 'Actions auto update' && git push -f origin ${SUBMMIT_BRANCH} || echo "No changes to commit"

最关键的代码是最后一行,当仓库没有变更时,就会执行echo部分,这样actions并不会报错

git commit -m 'Actions auto update' && git push -f origin ${SUBMMIT_BRANCH} || echo "No changes to commit"

你可能感兴趣的:(杂项,工具,github,git,ssh)