Skip to content

Commit

Permalink
workflow debug 6
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Oct 6, 2023
1 parent 33edb4c commit a8a3034
Showing 1 changed file with 1 addition and 75 deletions.
76 changes: 1 addition & 75 deletions .github/scripts/save-stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,5 @@ mkdir $package_dir
unzip -q $PROJECT_NAME-$PLATFORM-$VERSION.zip

"$package_dir/pharo/bin/pharo" --headless $package_dir/image/$PROJECT_NAME.image eval "
| getResponse getContents downloads text timestamp filename putResponse |
Transcript show: 'Getting download stats... '.
getResponse := ZnClient new
url:
'https://api.github.com/repos/openponk/$REPOSITORY_NAME/releases/tags/nightly';
accept: ZnMimeType applicationJson;
setBearerAuthentication: '$GITHUB_TOKEN';
get;
response.
Transcript show: 'Parsing download stats... '.
getContents := STONJSON fromString: getResponse entity contents.
Transcript show: 'Checking download stats are valid... '.
(getResponse status >= 300 or: [
(getContents includesKey: #assets) not ]) ifTrue: [
self error: (String streamContents: [ :s |
s << 'Get response status ' << getResponse status asString << '.'.
getResponse status == 404 ifTrue: [
s
<<
' If this is the first build of this repository, manually create pre-release named "nightly" first and create branch named dls (possibly with no files). This is whole body of response: '
<< getResponse entity contents ] ]) ].
Transcript show: 'Checking there were any downloads... '.
downloads := (getContents at: #assets) sumNumbers: [ :each |
each at: #download_count ].
downloads isZero ifTrue: [
^ 'No downloads of last nightly build - nothing to upload' ].
Transcript show: 'Building text... '.
text := String streamContents: [ :s |
s << 'name,created_at,download_count'.
s lf.
(getContents at: #assets) do: [ :each |
s << (each at: #name) asString << ','
<< (each at: #created_at) asString << ','
<< (each at: #download_count) asString.
s lf ] ].
Transcript show: 'Creating filename... '.
timestamp := DateAndTime now asString.
filename := ((timestamp first: 19) copyReplaceAll: ':' with: '')
, '.csv'.
Transcript show: 'Uploading stats... '.
putResponse := ZnClient new
url:
'https://api.github.com/repos/openponk/$REPOSITORY_NAME/contents/'
, filename;
accept: ZnMimeType applicationJson;
setBearerAuthentication: '$GITHUB_TOKEN';
entity: (ZnEntity
with: '{
\"content\":\"' , text asByteArray base64Encoded , '\",
\"message\":\"' , timestamp , '\",
\"branch\":\"dls\"
}'
type: ZnMimeType applicationJson);
put;
response.
Transcript show: 'Checking upload went ok... '.
(putResponse status >= 300) ifTrue: [
self error: (String streamContents: [ :s |
s << 'Put response status ' << putResponse status asString << '.'.
putResponse status == 404 ifTrue: [
s
<<
' If this is the first build of this repository, manually create branch named dls (possibly with no files). This is whole body of response: '
<< putResponse entity contents ] ]) ].
Transcript show: 'Finished... '.
^ 'Uploaded ' , downloads asString , ' download count'
self error: 'test'
"

0 comments on commit a8a3034

Please sign in to comment.