【问题标题】:Github Actions: Cache Error and end action without fail messageGithub 操作:缓存错误和结束操作,没有失败消息
【发布时间】:2023-01-24 23:30:03
【问题描述】:

我有一个 github 操作,可以将我的自述文件从一种格式转换为另一种格式,然后将新的自述文件推送到存储库。对于推动我已经定义了这个工作:

  push_readme:
    name: Push new Readme
    needs: generate_readme
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Download readme result from job 1 generate_readme
        uses: actions/download-artifact@v3
        with:
          name: readme
      - name: Commit files
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git status
          git add READMEmd.md
          git commit -m "Actions Generated Readme"
      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}

当没有要提交的内容时,提交会返回错误 - 只要在最近的推送中未更新自述文件,就会发生这种情况。这是预期的并且很好。但是,我想正确处理这个错误 s.t.该操作在它发生时就结束了,而没有告诉我它失败了。相反,我想要“没有新的自述文件要提交。结束操作”的意思。

谁能指出我该怎么做?我还没有找到解决方案。

【问题讨论】:

  • 这是git add命令中的READMEmd.md的错字吗?

标签: github github-actions git-commit


【解决方案1】:

您可以使用 Bash 并检查 git diff 以获取 README 文件,并检查 set an output parameterGITHUB_OUTPUT 以检查是否确实存在提交。

这是一个例子:

      - name: Commit files
        id: commit
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git status
          if [[ -n $(git diff README.md) ]]; then
            git add README.md
            git commit -m "Actions Generated Readme"
            echo "DONE=true" >> $GITHUB_OUTPUT
          else
            echo "README is the same. Nothing to commit."
          fi
      - name: Push changes
        if: ${{ steps.commit.DONE }}
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}

【讨论】:

    猜你喜欢
    • 2021-10-01
    • 1970-01-01
    • 2017-10-01
    • 1970-01-01
    • 2022-01-03
    • 2020-02-29
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多