Skip to content

Commit

Permalink
GitHub Action: 更新update_contributors_images.yaml, 支持签名提交
Browse files Browse the repository at this point in the history
添加`ci_commit_with_signature.sh`脚本, 使用`GraphQL Api`实现提交签名, 提交者受`api`的制约不能更改
  • Loading branch information
maboloshi committed Nov 25, 2023
1 parent 63f6620 commit 41f770b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
18 changes: 7 additions & 11 deletions .github/workflows/main.user.js_version_update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ jobs:
run: |
sed -i "s/@version\s*[^\\s]*/@version $(TZ='Asia/Shanghai' date +'%Y-%m-%d')/" main.user.js
- name: Commit file main.user.js
- name: Commit and push main.user.js
if: ${{ env.AHEAD == 'true' }}
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add main.user.js
git commit -m "main.user.js Update to version $(TZ='Asia/Shanghai' date +'%Y-%m-%d')"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.CI_GITHUB_TOKEN }}
branch: ${{ github.ref }}
bash script/ci.sh \
${{ secrets.CI_GITHUB_TOKEN }} \
"maboloshi/github-chinese" \
"main.user.js" \
"main.user.js Update to version $(TZ='Asia/Shanghai' date +'%Y-%m-%d')"
"Signed-off-by: 沙漠之子 <[email protected]>"
46 changes: 46 additions & 0 deletions script/ci_commit_with_signature.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

TOKEN=$1
repoNwo=$2
branch=$(git rev-parse --abbrev-ref HEAD) # 或 git rev-parse HEAD
file_path=$3
encoded_file_content=$(base64 < "$file_path")
message_headline=$4
message_body=$5
expectedHeadOid=$(git rev-parse HEAD)

curl $GITHUB_GRAPHQL_URL --silent \
--write-out '%{stderr}HTTP status: %{response_code}\n\n' \
-H "Authorization: bearer $TOKEN" \
--data @- <<GRAPHQL | jq
{
"query": "mutation (\$input: CreateCommitOnBranchInput!) {
createCommitOnBranch(input: \$input) {
commit {
url
}
}
}",
"variables": {
"input": {
"branch": {
"repositoryNameWithOwner": "$repoNwo",
"branchName": "$branch"
},
"message": {
"headline": "$message_headline",
"body": "$message_body"
},
"fileChanges": {
"additions": [
{
"path": "$file_path",
"contents": "$encoded_file_content"
}
]
},
"expectedHeadOid": "$expectedHeadOid"
}
}
}
GRAPHQL

0 comments on commit 41f770b

Please sign in to comment.