Skip to content

Commit 10ee44d

Browse files
committed
[fix] validating TX has not uid and avatar - Fix #729
[enh] release.sh use github token
1 parent 25dbb1d commit 10ee44d

File tree

4 files changed

+54
-35
lines changed

4 files changed

+54
-35
lines changed

github.sh

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,74 @@ fi
1313
current=`grep -P "version\": \"\d+.\d+.\d+(\w*)" package.json | grep -oP "\d+.\d+.\d+(\w*)"`
1414
echo "Current version: $current"
1515

16+
### Get repo URL
17+
REMOTE_URL=`git remote -v | grep -P "push" | grep -oP "https://github.com/[^/]+/[^/ ]+"`
18+
REPO=`echo $REMOTE_URL | sed "s/https:\/\/github.com\///g"`
19+
REPO_URL=https://api.github.com/repos/$REPO
20+
21+
### get auth token
22+
GITHUB_TOKEN=`cat ~/.config/duniter/.github`
23+
if [[ "_$GITHUB_TOKEN" != "_" ]]; then
24+
GITHUT_AUTH="Authorization: token $GITHUB_TOKEN"
25+
else
26+
echo "Unable to find github authentifcation token file: "
27+
echo " - You can create such a token at https://github.com/settings/tokens > 'Generate a new token'."
28+
echo " - Then copy the token and paste it in the file '~/.config/duniter/.github' using a valid token."
29+
exit
30+
fi
31+
1632
case "$1" in
1733
del)
18-
if [[ $2 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ ]]; then
19-
result=`curl -i 'https://api.github.com/repos/duniter/cesium/releases/tags/v'"$current"''`
20-
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://api.github.com/repos/duniter/cesium/releases/\d+"`
21-
if [[ $release_url != "" ]]; then
34+
result=`curl -i "$REPO_URL/releases/tags/v$current"`
35+
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "$REPO_URL/releases/\d+"`
36+
if [[ $release_url != "" ]]; then
2237
echo "Deleting existing release..."
23-
curl -XDELETE $release_url -u $2
24-
fi
25-
else
26-
echo "Wrong argument"
27-
echo "Usage:"
28-
echo " > ./github.sh del user:password"
29-
exit
38+
curl -H 'Authorization: token $GITHUB_TOKEN' -XDELETE $release_url
3039
fi
3140
;;
3241

3342
pre|rel)
34-
if [[ $2 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ && $3 != "" ]]; then
43+
if [[ $2 != "" ]]; then
3544

3645
if [[ $1 = "pre" ]]; then
3746
prerelease="true"
3847
else
3948
prerelease="false"
4049
fi
50+
description=`echo $2`
4151

42-
result=`curl -i 'https://api.github.com/repos/duniter/cesium/releases/tags/v'"$current"''`
43-
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://api.github.com/repos/duniter/cesium/releases/\d+"`
52+
result=`curl -s -H ''"$GITHUT_AUTH"'' "$REPO_URL/releases/tags/v$current"`
53+
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+/releases/\d+"`
4454
if [[ $release_url != "" ]]; then
4555
echo "Deleting existing release..."
46-
curl -XDELETE $release_url -u $2
56+
result=`curl -H ''"$GITHUT_AUTH"'' -XDELETE $release_url`
57+
if [[ "_$result" != "_" ]]; then
58+
error_message=`echo "$result" | grep -P "\"message\": \"[^\"]+" | grep -oP ": \"[^\"]+\""`
59+
echo "Delete existing release failed with error$error_message"
60+
exit
61+
fi
62+
else
63+
echo "Release not exists yet on github."
4764
fi
4865

4966
echo "Creating new release..."
50-
result=`curl -i https://api.github.com/repos/duniter/cesium/releases -u $2 -d '{"tag_name": "v'"$current"'","target_commitish": "master","name": "'"$current"'","body": "'"$3"'","draft": false,"prerelease": '"$prerelease"'}'`
51-
upload_url=`echo "$result" | grep -P "\"upload_url\": \"[^\"]+" | grep -oP "https://[a-z0-9/.]+"`
67+
echo " - tag: v$current"
68+
echo " - description: $description"
69+
result=`curl -H ''"$GITHUT_AUTH"'' -i $REPO_URL/releases -d '{"tag_name": "v'"$current"'","target_commitish": "master","name": "'"$current"'","body": "'"$description"'","draft": false,"prerelease": '"$prerelease"'}'`
70+
upload_url=`echo "$result" | grep -P "\"upload_url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"`
5271

5372
### Sending files
5473
echo "Uploading files to GitHub..."
5574
dirname=`pwd`
56-
curl -i -u $2 -H 'Content-Type: application/zip' -T $dirname/platforms/web/build/cesium-v$current-web.zip $upload_url?name=cesium-v$current-web.zip
57-
curl -i -u $2 -H 'Content-Type: application/vnd.android.package-archive' -T $dirname/platforms/android/build/outputs/apk/release/android-release.apk $upload_url?name=cesium-v$current-android.apk
58-
# curl -i -u $2 -H 'Content-Type: application/zip' -T $dirname/platforms/firefoxos/build/package.zip $upload_url?name=cesium-v$current-firefoxos.zip
59-
# curl -i -u $2 -H 'Content-Type: application/x-debian-package' -T $dirname/platforms/ubuntu/native/cesium_${current}_amd64.deb $upload_url?name=cesium-v${current}-ubuntu-amd64.deb
75+
curl -i -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T $dirname/platforms/web/build/cesium-v$current-web.zip $upload_url?name=cesium-v$current-web.zip
76+
curl -i -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/vnd.android.package-archive' -T $dirname/platforms/android/build/outputs/apk/release/android-release.apk $upload_url?name=cesium-v$current-android.apk
6077

6178
echo "Successfully uploading files"
62-
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://api.github.com/repos/[a-z0-9/.]+"`
63-
echo " -> Release url: $release_url"
79+
echo " -> Release url: https://github.com/$REPO/releases/tag/v$current"
6480
else
6581
echo "Wrong arguments"
6682
echo "Usage:"
67-
echo " > ./github.sh pre|rel user:password <release_description>"
83+
echo " > ./github.sh pre|rel <release_description>"
6884
echo "With:"
6985
echo " - pre: use for pre-release"
7086
echo " - rel: for full release"

release.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ if [[ $2 =~ ^[0-9]+.[0-9]+.[0-9]+((a|b)[0-9]+)?$ && $3 =~ ^[0-9]+$ ]]; then
4040
;;
4141
esac
4242

43+
# Load env.sh if exists
44+
if [ -f "${DIRNAME}/env.sh" ]; then
45+
source ${DIRNAME}/env.sh
46+
fi
47+
4348
# force nodejs version to 5
4449
if [ -d "$NVM_DIR" ]; then
4550
. $NVM_DIR/nvm.sh
@@ -60,7 +65,6 @@ if [[ $2 =~ ^[0-9]+.[0-9]+.[0-9]+((a|b)[0-9]+)?$ && $3 =~ ^[0-9]+$ ]]; then
6065
echo "----------------------------------"
6166
echo "- Building Android artifact..."
6267
echo "----------------------------------"
63-
source ./env.sh
6468
ionic build android --release
6569

6670
#ionic build firefoxos --release
@@ -91,12 +95,12 @@ if [[ $2 =~ ^[0-9]+.[0-9]+.[0-9]+((a|b)[0-9]+)?$ && $3 =~ ^[0-9]+$ ]]; then
9195
echo " Waiting 30s, for propagation to github..."
9296
sleep 30s
9397

94-
if [[ $4 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ && "_$5" != "_" ]]; then
98+
if [[ "_$4" != "_" ]]; then
9599
echo "**********************************"
96100
echo "* Uploading artifacts to Github..."
97101
echo "**********************************"
98102

99-
./github.sh $1 $4 "'"$5"'"
103+
./github.sh $1 $4
100104

101105
echo "----------------------------------"
102106
echo "- Building desktop versions..."
@@ -129,12 +133,11 @@ cesium-desktop-v$2-linux-x64.tar.gz"
129133
echo "* Build release succeed !"
130134
echo "**********************************"
131135

132-
echo " WARN - missing arguments: "
133-
echo " user:password 'release_description'"
136+
echo " WARN - missing arguments 'release_description'"
134137
echo
135138
echo " Binaries files NOT sending to github repository"
136139
echo " Please run:"
137-
echo " > ./github.sh pre|rel user:password 'release_description'"
140+
echo " > ./github.sh pre|rel 'release_description'"
138141
echo
139142
echo " Desktop artifact are NOT build"
140143
echo " Please run:"
@@ -145,10 +148,10 @@ cesium-desktop-v$2-linux-x64.tar.gz"
145148
else
146149
echo "Wrong version format"
147150
echo "Usage:"
148-
echo " > ./release.sh [pre|rel] <version> <android-version> <github_credentials>"
151+
echo " > ./release.sh [pre|rel] <version> <android-version> <release_description>"
149152
echo "with:"
150153
echo " version: x.y.z"
151154
echo " android-version: nnn"
152-
echo " github_credentials: user:password (a valid GitHub user account)"
155+
echo " release_description: a short description of the release"
153156
fi
154157

www/js/services/cache-services.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ angular.module('cesium.cache.services', ['angular-cache'])
55

66
var
77
constants = {
8-
LONG: 1 * 60 * 60 * 1000 /*5 min*/,
8+
LONG: 1 * 60 * 60 * 1000 /*1 hour*/,
9+
MEDIUM: 5 * 60 * 1000 /*5 min*/,
910
SHORT: csSettings.defaultSettings.cacheTimeMs
1011
},
1112
cacheNames = []

www/js/services/tx-services.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
159159
var sliceTime = csSettings.data.walletHistorySliceSecond;
160160
fromTime = fromTime - (fromTime % sliceTime);
161161
for(var i = fromTime; i - sliceTime < nowInSec; i += sliceTime) {
162-
var startTime = Math.max(i, fromTime);
163162
jobs.push(BMA.tx.history.times({pubkey: pubkey, from: i, to: i+sliceTime-1})
164163
.then(_reduceTx)
165164
);
@@ -361,7 +360,7 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
361360
data.balance = balance;
362361

363362
// Will add uid (+ plugin will add name, avatar, etc. if enable)
364-
return csWot.extendAll((data.tx.history || []).concat(data.tx.pendings||[]), 'pubkey');
363+
return csWot.extendAll((data.tx.history || []).concat(data.tx.validating||[]).concat(data.tx.pendings||[]), 'pubkey');
365364
})
366365
.then(function() {
367366
console.debug('[tx] TX and sources loaded in '+ (new Date().getTime()-now) +'ms');

0 commit comments

Comments
 (0)