Skip to content

Commit 894349f

Browse files
committed
Debug tree JSON
1 parent f74e16e commit 894349f

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

scripts/create-signed-commit.sh

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,69 @@
1818
# https://github.com/peter-evans/create-pull-request/issues/1241#issuecomment-1232477512
1919

2020
set -euxo pipefail
21-
21+
2222
# Configuration defaults
2323
github_token=${GITHUB_TOKEN:?}
2424
repo_owner="${REPO_OWNER:-mongodb}"
2525
repo_name="${REPO_NAME:-mongodb-atlas-kubernetes}"
2626
branch="${BRANCH:?}"
2727
commit_message="${COMMIT_MESSAGE:?}"
2828

29-
# Fetch the latest commit SHA
29+
# Fetch the latest commit SHA
3030
LATEST_COMMIT_SHA=$(curl -s -H "Authorization: token $github_token" \
31-
"https://api.github.com/repos/$repo_owner/$repo_name/git/ref/heads/$branch" | jq -r '.object.sha')
32-
31+
"https://api.github.com/repos/$repo_owner/$repo_name/git/ref/heads/$branch" | jq -r '.object.sha')
32+
3333
LATEST_TREE_SHA=$(curl -s -H "Authorization: token $github_token" \
34-
"https://api.github.com/repos/$repo_owner/$repo_name/git/commits/$LATEST_COMMIT_SHA" | jq -r '.tree.sha')
35-
34+
"https://api.github.com/repos/$repo_owner/$repo_name/git/commits/$LATEST_COMMIT_SHA" | jq -r '.tree.sha')
35+
36+
echo "Creating a signed commit in GitHub."
3637
echo "Latest commit SHA: $LATEST_COMMIT_SHA"
37-
echo "Latest tree SHA: $LATEST_TREE_SHA"
38-
38+
echo "Latest tree SHA: $LATEST_TREE_SHA"
39+
3940
# Collect all modified files
4041
MODIFIED_FILES=$(git diff --name-only --cached)
4142
echo "Modified files: $MODIFIED_FILES"
42-
43+
4344
# Create blob and tree
4445
NEW_TREE_ARRAY="["
4546
for FILE_PATH in $MODIFIED_FILES; do
4647
# Read file content encoded to base64
4748
ENCODED_CONTENT=$(base64 < "${FILE_PATH}")
48-
49+
4950
# Create blob
5051
BLOB_SHA=$(curl -s -X POST -H "Authorization: token $github_token" \
5152
-H "Accept: application/vnd.github.v3+json" \
5253
-d "{\"content\": \"$ENCODED_CONTENT\", \"encoding\": \"base64\"}" \
5354
"https://api.github.com/repos/$repo_owner/$repo_name/git/blobs" | jq -r '.sha')
54-
55+
5556
# Append file info to tree JSON
5657
NEW_TREE_ARRAY="${NEW_TREE_ARRAY}{\"path\": \"$FILE_PATH\", \"mode\": \"100644\", \"type\": \"blob\", \"sha\": \"$BLOB_SHA\"},"
57-
done
58-
58+
done
59+
5960
# Remove trailing comma and close the array
60-
NEW_TREE_ARRAY="${NEW_TREE_ARRAY%,}]"
61-
61+
NEW_TREE_ARRAY="${NEW_TREE_ARRAY%,}]"
62+
63+
echo "NEW_TREE_ARRAY:"
64+
echo "${NEW_TREE_ARRAY}" | jq .
65+
6266
# Create new tree
6367
NEW_TREE_SHA=$(curl -s -X POST -H "Authorization: token $github_token" \
6468
-H "Accept: application/vnd.github.v3+json" \
6569
-d "{\"base_tree\": \"$LATEST_TREE_SHA\", \"tree\": $NEW_TREE_ARRAY}" \
6670
"https://api.github.com/repos/$repo_owner/$repo_name/git/trees" | jq -r '.sha')
67-
71+
6872
echo "New tree SHA: $NEW_TREE_SHA"
69-
73+
7074
# Create a new commit
7175
NEW_COMMIT_SHA=$(curl -s -X POST -H "Authorization: token $github_token" \
7276
-H "Accept: application/vnd.github.v3+json" \
7377
-d "{\"message\": \"$commit_message\", \"tree\": \"$NEW_TREE_SHA\", \"parents\": [\"$LATEST_COMMIT_SHA\"]}" \
7478
"https://api.github.com/repos/$repo_owner/$repo_name/git/commits" | jq -r '.sha')
7579
echo "New commit SHA: $NEW_COMMIT_SHA"
76-
80+
7781
# Update the reference of the branch to point to the new commit
7882
curl -s -X PATCH -H "Authorization: token $github_token" \
7983
-H "Accept: application/vnd.github.v3+json" -d "{\"sha\": \"$NEW_COMMIT_SHA\"}" \
8084
"https://api.github.com/repos/$repo_owner/$repo_name/git/refs/heads/$branch"
81-
85+
8286
echo "Branch ${branch} updated to new commit ${NEW_COMMIT_SHA}."

0 commit comments

Comments
 (0)