Skip to content

Commits via git are unverified; switch to GraphQL for commits #18565

Description

@strawgate

When using the GITHUB_TOKEN via git the resulting commits show up as unverified.

If the same commits are made with the GITHUB_TOKEN through the graphql api (as discussed here https://gist.github.com/swinton/03e84635b45c78353b1f71e41007fc7c?permalink_comment_id=5401086#gistcomment-5401086 ):

Referencing a dev.to post about making commits using gh's graphql api, Here's a solution that can handle an arbitrary number of files:

# Collect all changed file names
CHANGED=($(git diff --name-only | xargs))
forvaluein"${CHANGED[@]}";do
FILES="${FILES} -F files[][path]=$value -F files[][contents]=$(base64 -w0 $value)"done
gh api graphql \
-F githubRepository=${GIT_REPOSITORY} \
-F branchName=${PUBLISH_BRANCH} \
-F expectedHeadOid=$(git rev-parse HEAD) \
-F commitMessage="commit by github-actions[bot]" \
-F "query=@.github/api/createCommitOnBranch.gql" \
${FILES}

You do need to create the .github/api/createCommitOnBranch.gql file:

mutation (
$githubRepository: String!,
$branchName: String!,
$expectedHeadOid: GitObjectID!$commitMessage: String!$files: [FileAddition!]!
) {
createCommitOnBranch(
input: {
branch:
{
repositoryNameWithOwner: $githubRepository,
branchName: $branchName
},
message: {headline: $commitMessage},
fileChanges: {
additions: $files
}
expectedHeadOid: $expectedHeadOid
}
){
commit {
url
}
}
}

The resulting commits appear as signed/verified.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions