@@ -44,62 +44,71 @@ function restoreVendorFolder {
4444}
4545
4646function loadEnvGitHubToken {
47- GITHUB_TOKEN=$( git config github.token)
48- if [ -z " $token " ]; then
47+ GITHUB_TOKEN=$( git config github.token || echo ' ' )
48+ if [ -z " ${GITHUB_TOKEN} " ]; then
4949 echo ' GitHub token is empty. Please run git config --add github.token "123"' ;
5050 exit 1;
5151 fi
5252}
5353
54+ function generate_post_data {
55+ cat << EOF
56+ {
57+ "tag_name": "v${VERSION} ",
58+ "target_commitish": "$branch ",
59+ "name": "v${VERSION} ",
60+ "body": "### Version ${VERSION} ",
61+ "draft": true,
62+ "prerelease": false
63+ }
64+ EOF
65+ }
66+
67+ function uploadArtifact {
68+ FILE_NAME=" $1 "
69+ MIME_TYPE=" $2 "
70+ ARTIFACT_OUT=$( curl -# -S -s -L \
71+ -H " Authorization: token ${GITHUB_TOKEN} " \
72+ -H " Content-Type: ${MIME_TYPE} " \
73+ --data-binary @${FILE_NAME} \
74+ " https://uploads.github.com/repos/$user /$repo /releases/$releaseId /assets?name=${FILE_NAME} " )
75+ echo " Uploaded: $( echo $ARTIFACT_OUT | jq -r ' .name' ) ."
76+ }
77+
5478function publishArtifacts {
5579
5680 if ! command -v jq & > /dev/null
5781 then
5882 echo " jq could not be found"
59- exit
83+ exit 1
6084 fi
6185
6286 if ! command -v git & > /dev/null
6387 then
6488 echo " git could not be found"
65- exit
89+ exit 1
6690 fi
6791
6892 loadEnvGitHubToken
6993 user=${GH_ORG:- " code-lts" }
7094 repo=${GH_REPO:- " doctum" }
71- echo " Create release ${VERSION} for repo: $user /$repo branch: $branch "
95+ echo " Create release ${VERSION} for repo: $user /$repo "
7296 read -r -p " Are you sure to publish the draft? [Y/n]" response
7397 response=${response,,} # tolower
7498 if [[ $response =~ ^(yes| y| ) ]] || [[ -z $response ]]; then
7599 RELEASE_OUT=" $( curl -H " Authorization: token ${GITHUB_TOKEN} " --data " $( generate_post_data) " " https://api.github.com/repos/$user /$repo /releases" ) "
100+ echo " Created release: $( echo $RELEASE_OUT | jq -r ' .html_url' ) "
76101 fi
77102
78- echo " Make and publish the signature for this release."
103+ echo " Upload artifacts for this release."
79104 read -r -p " Are you sure to upload artifacts to the draft? [Y/n]" response
80105 response=${response,,} # tolower
81106 if [[ $response =~ ^(yes| y| ) ]] || [[ -z $response ]]; then
82107 releaseId=$( echo $RELEASE_OUT | jq -r ' .id' )
83- curl -L \
84- -H " Authorization: token ${GITHUB_TOKEN} " \
85- -H " Content-Type: application/pgp-signature" \
86- --data-binary @doctum.phar \
87- " https://uploads.github.com/repos/$user /$repo /releases/$releaseId /assets?name=doctum.phar"
88- curl -L \
89- -H " Authorization: token ${GITHUB_TOKEN} " \
90- -H " Content-Type: application/pgp-signature" \
91- --data-binary @doctum.phar.sha256 \
92- " https://uploads.github.com/repos/$user /$repo /releases/$releaseId /assets?name=doctum.phar.sha256"
93- curl -L \
94- -H " Authorization: token ${GITHUB_TOKEN} " \
95- -H " Content-Type: application/pgp-signature" \
96- --data-binary @doctum.phar.asc \
97- " https://uploads.github.com/repos/$user /$repo /releases/$releaseId /assets?name=doctum.phar.asc"
98- curl -L \
99- -H " Authorization: token ${GITHUB_TOKEN} " \
100- -H " Content-Type: application/pgp-signature" \
101- --data-binary @doctum.phar.sha256.asc \
102- " https://uploads.github.com/repos/$user /$repo /releases/$releaseId /assets?name=doctum.phar.sha256.asc"
108+ uploadArtifact doctum.phar ' application/octet-stream'
109+ uploadArtifact doctum.phar.asc ' application/pgp-signature'
110+ uploadArtifact doctum.phar.sha256 ' text/plain'
111+ uploadArtifact doctum.phar.sha256.asc ' application/pgp-signature'
103112 fi
104113
105114}
0 commit comments