0

My goal is to generate verified commits, using GitHub's Graphql API. I created a test repository to validate the verified PR creation, and I see the GitHub Action generating the new README.md file. However, it is not added to existing PR (link removed, see provided answer) in progress.

When the GitHub Action runs, I get the following error:

Switched to a new branch 'feature/verified-commit'
branch 'feature/verified-commit' set up to track 'origin/feature/verified-commit'.
time="2024-12-23T23:30:48Z" level=info msg="Found Chart directories [roles/argo-cd]"
time="2024-12-23T23:30:48Z" level=info msg="Generating README Documentation for chart roles/argo-cd"
-rw-r--r-- 1 runner docker 409 Dec 23 23:30 .github/api/commit.gql
error parsing " 'query" value: open .github/api/commit.gql': no such file or directory

Thank you for letting me know what I miss.

2 Answers 2

0

You need to split flags (-F) and their values into separate elements to pass them correctly when expanded. This is how the step should look:

run: |
  git config user.email '${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com'
  git config user.name '${{ github.actor }}'
  git fetch
  git switch ${{ github.head_ref }}
  helm-docs --values-file=./defaults/main.yaml
  if [ -n "$(git ls-files -om --deduplicate)" ]; then
    declare -a params
    params+=("-F") 
    params+=("repository='${{ github.repository }}'")
    params+=("-F") 
    params+=("branchName='${{ github.head_ref }}'")
    params+=("-F") 
    params+=("oid='${{ github.event.pull_request.head.sha }}'")
    params+=("-F") 
    params+=("message='docs(github-action): update documentation'")
    mapfile -t clips < <(git ls-files -d --deduplicate)
    mapfile -t files < <(git ls-files -om --deduplicate)
    for file in "${files[@]}"; do
      type='addition'
      for clip in "${clips[@]}"; do
        if [ "$clip" == "$file" ]; then
          type='deletion'
        fi
      done
      params+=("-F") 
      params+=("fileChanges[][file][type]='$type'")
      params+=("-F") 
      params+=("fileChanges[][file][path]='$file'")
      if [ "$type" == 'addition' ]; then
        params+=("-F") 
        params+=("fileChanges[][file][contents]='$(base64 -w 0 $file)'")
      fi
    done
    params+=("-F") 
    params+=("[email protected]/api/commit.gql")
    echo "${params[@]}"
    gh api graphql "${params[@]}"
  fi
Sign up to request clarification or add additional context in comments.

1 Comment

Actually, you don't. I moved away from gh api graphql binary usage, with a proper actions/github-script implementation. See the accepted answer.
0

I ended-up using the GitHub GraphQL API with actions/github-script into workflow, instead of actually using the binary. The step handles properly both additions and deletions, with CreateCommitOnBranch mutation.

Previous implementation, without verified signature:

enter image description here

New implementation:

enter image description here

You can examine the actual PR with the new implementation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.