sinedied / devto-cli

Dev.to authoring CLI to create and publish markdown files as articles, using assets hosted on GitHub.
MIT License
33 stars 3 forks source link

Github CI tries to commit when there is nothing to commit #23

Closed rpsu closed 2 years ago

rpsu commented 2 years ago

The publish.yml workflow tries to make a git commit even when it appears like there is nothing to commit. This appears to happens when I've published the posts from my local and the CI updates posts.

Run sinedied/publish-devto@v2
/usr/bin/docker run --name db2d7b541e79b11954185a9e3aef5ffeb8abc_8c4255 --label 7db2d7 --workdir /github/workspace 
......
Found 7 article(s)
- Retrieving articles from dev.to…
......
/usr/bin/git add posts/2015/....
/usr/bin/git -c user.name="dev.to bot" -c user.email="sinedied+devtobot@gmail.com" commit -m chore: update published articles [skip ci]
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
Error: Error: Cannot commit changes: The process '/usr/bin/git' failed with exit code 1

and the publish.yml file I have:

# This workflow will push and update articles on dev.to each time a new
# commit is pushed to the main branch.
#
# To make it work, you need a dev.to API key, see:
# https://docs.dev.to/api/#section/Authentication/api_key
#
# Once you have generated the token, you need to add them as a secret in your
# GitHub repository:
# - DEVTO_TOKEN: your dev.to API key
# See https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets
# for more information about GitHub secrets.

name: publish
on:
  push:
    branches: [main]

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 14

    - name: Publish articles on dev.to
      uses: sinedied/publish-devto@v2
      with:
        # Your dev.to personal API key to publish and update articles.
        # See https://docs.dev.to/api/#section/Authentication/api_key
        devto_key: ${{ secrets.DEVTO_TOKEN }}
        # Your GitHub personal access token, used to create commits for updated files.
        # If you have a protected branch, you need to create a commit with the
        github_token: ${{ secrets.GITHUB_TOKEN }}
        # (Optional) The files to publish. Default is "posts/**/*.md"
        files: 'posts/**/*.md'
        # (Optional) The git branch to use. Default is 'main'.
        branch: main
        # (Optional) Use conventional commit messages. Default is false.
        # See https://www.conventionalcommits.org. 
        conventional_commits: true
pabloromeo commented 2 years ago

I've seen this behavior too and opened an issue at https://github.com/sinedied/publish-devto/issues/18

sinedied commented 2 years ago

Thanks for the report! If it's fixed in the CLI it will also fix it for the GitHub Action, I'll have a look

pabloromeo commented 2 years ago

Hey! Since I didn't know if you were still maintaining this, I forked and fixed it here, in this commit: https://github.com/cloudx-labs/publish-devto/commit/0235a3f1238c369904ac72026bddbe6a071ef0a2

In that repo I also added support for dry-run in the github action, and added output parameters so other actions can do stuff with the summary of actions taken. For example, in my usage, I'm using an output summary of a dry-run which I post as a comment in the PR, to inform of the changes that would be published.

sinedied commented 2 years ago

Its fixed thanks to @pabloromeo's PR 😉

I'll soon release an updated version of the GitHub action, but I could also include your work on dry-run and output summary if you would like to propose it as a PR?