Skip to content

Commit e5f82f1

Browse files
committed
CLOUDP-313350: Fix the commit sign fix by removing EOLs
Signed-off-by: jose.vazquez <[email protected]>
1 parent c27a4ca commit e5f82f1

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

scripts/create-signed-commit.sh

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

2020
set -euo 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
47-
ENCODED_CONTENT=$(base64 < "${FILE_PATH}")
48-
48+
ENCODED_CONTENT=$(base64 -w0 < "${FILE_PATH}")
49+
4950
# Create blob
50-
BLOB_SHA=$(curl -s -X POST -H "Authorization: token $github_token" \
51+
BLOB_JSON=$(curl -s -X POST -H "Authorization: token $github_token" \
5152
-H "Accept: application/vnd.github.v3+json" \
5253
-d "{\"content\": \"$ENCODED_CONTENT\", \"encoding\": \"base64\"}" \
53-
"https://api.github.com/repos/$repo_owner/$repo_name/git/blobs" | jq -r '.sha')
54-
54+
"https://api.github.com/repos/$repo_owner/$repo_name/git/blobs")
55+
BLOB_SHA=$(echo "${BLOB_JSON}" | jq -r '.sha')
56+
5557
# Append file info to tree JSON
5658
NEW_TREE_ARRAY="${NEW_TREE_ARRAY}{\"path\": \"$FILE_PATH\", \"mode\": \"100644\", \"type\": \"blob\", \"sha\": \"$BLOB_SHA\"},"
57-
done
58-
59+
done
60+
5961
# Remove trailing comma and close the array
60-
NEW_TREE_ARRAY="${NEW_TREE_ARRAY%,}]"
61-
62+
NEW_TREE_ARRAY="${NEW_TREE_ARRAY%,}]"
63+
6264
# Create new tree
6365
NEW_TREE_SHA=$(curl -s -X POST -H "Authorization: token $github_token" \
6466
-H "Accept: application/vnd.github.v3+json" \
6567
-d "{\"base_tree\": \"$LATEST_TREE_SHA\", \"tree\": $NEW_TREE_ARRAY}" \
6668
"https://api.github.com/repos/$repo_owner/$repo_name/git/trees" | jq -r '.sha')
67-
69+
6870
echo "New tree SHA: $NEW_TREE_SHA"
69-
71+
7072
# Create a new commit
71-
set -x
7273
NEW_COMMIT_SHA=$(curl -s -X POST -H "Authorization: token $github_token" \
7374
-H "Accept: application/vnd.github.v3+json" \
7475
-d "{\"message\": \"$commit_message\", \"tree\": \"$NEW_TREE_SHA\", \"parents\": [\"$LATEST_COMMIT_SHA\"]}" \
75-
"https://api.github.com/repos/$repo_owner/$repo_name/git/commits" | jq -r '.sha')
76-
set +x
76+
"https://api.github.com/repos/$repo_owner/$repo_name/git/commits" | jq -r '.sha')
7777
echo "New commit SHA: $NEW_COMMIT_SHA"
78-
78+
7979
# Update the reference of the branch to point to the new commit
8080
curl -s -X PATCH -H "Authorization: token $github_token" \
8181
-H "Accept: application/vnd.github.v3+json" -d "{\"sha\": \"$NEW_COMMIT_SHA\"}" \
8282
"https://api.github.com/repos/$repo_owner/$repo_name/git/refs/heads/$branch"
83-
83+
8484
echo "Branch ${branch} updated to new commit ${NEW_COMMIT_SHA}."

0 commit comments

Comments
 (0)