Skip to content

Commit

Permalink
Add script to pull string changes from thimble on build
Browse files Browse the repository at this point in the history
  • Loading branch information
Gideon Thomas committed Mar 8, 2016
1 parent bcbc027 commit 7d9b8aa
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ notifications:
env:
global:
- secure: OvDWteGJ/ctOzXudDb8icaLCtdJTd1HbQq5T9HvS7ZF8IDs6xM+atqxYWeyC+2sm7fLNkWjndcKrXFqZ3TRltW7ibaKreUMtUVaVKc7mGBNBn/gVfCNvHRlbDYr6bMUVapk9x1Ql6p2jE/Ss+p2EEGkzvHPKn2RMRWOQQQM7wTQ=
- secure: "QBOXtZywpMPKVrYqu04c+7Qum6fzNWuerk81J68NNdjvILo0BoV0SPyASEEJVgRieMIUGpE+nKy1WMG5QnL1mL/qLbQJmotGjd7IBj+hSdz8aIfg01sGVe3IyHWv6T/aKCMzCvHqypwuP3O0yclU9gybyWjiRFCtiBuHCpLSRe4="
matrix:
- AWS_ACCESS_KEY_ID=AKIAI7XHSZFYVHFRTRIA CLOUDFRONT_DISTRIBUTION_ID=ENS8DUD0WOHD9
deploy:
Expand All @@ -29,6 +30,7 @@ deploy:
on:
repo: mozilla/brackets
branch: master
condition: $UPDATE_STRINGS != true
- provider: s3
access_key_id: AKIAI7XHSZFYVHFRTRIA
secret_access_key:
Expand All @@ -41,5 +43,6 @@ deploy:
on:
repo: mozilla/brackets
branch: production
condition: $UPDATE_STRINGS != true
after_deploy:
- node invalidate.js
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"mkdirp": "0.5.1",
"nunjucks": "2.3.0",
"properties-parser": "0.3.1",
"request": "^2.69.0",
"requirejs": "2.1.22"
},
"scripts": {
Expand Down
26 changes: 26 additions & 0 deletions scripts/get-file-sha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*global process */

var request = require("request");

request({
uri: "https://api.github.com/repos/mozilla/brackets/contents/" + process.argv[2],
method: "GET",
headers: {
"User-Agent": "gideonthomas"
}
}, function(err, res, body) {
"use strict";

if(!err && res.statusCode === 200) {
try {
var content = JSON.parse(body);
process.stdout.write(content.sha);
} catch(e) {
console.error("Failed to convert response to JSON with: ", e);
process.exit(0);
}
} else {
console.error("Failed to get file contents with: ", err || body);
process.exit(0);
}
});
55 changes: 55 additions & 0 deletions scripts/pull-new-strings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
set -e # exit with nonzero exit code if anything fails

if [ "$UPDATE_STRINGS" == "true" ]
then
# Get the latest tarball of Thimble and extract the locales/ directory
curl -L https://api.github.com/repos/mozilla/thimble.mozilla.org/tarball/master | \
tar -xv --include '/locales/' --strip-components 1

git add locales

CHANGED="$(git diff --cached --name-only --diff-filter=M locales)"
ADDED="$(git diff --cached --name-only --diff-filter=A locales)"

for CHANGED_FILE in $CHANGED
do
sha="$(node scripts/get-file-sha.js $CHANGED_FILE)"
locale="$(echo $CHANGED_FILE | sed -e 's/locales\///g' -e 's/\/editor\.properties//g')"
content="$(base64 $CHANGED_FILE)"
body="{ \
\"message\": \"Thimble-L10N - Update strings for $locale\", \
\"content\": \"$content\", \
\"sha\": \"$sha\" \
}"

curl --location-trusted -X PUT \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: token $GH_TOKEN" \
-d "$body"
"https://api.github.com/repos/mozilla/brackets/contents/$CHANGED_FILE"

echo "Successfully updated strings for $locale"
done

for ADDED_FILE in $ADDED
do
locale="$(echo $ADDED_FILE | sed -e 's/locales\///g' -e 's/\/editor\.properties//g')"
content="$(base64 $ADDED_FILE)"
body="{ \
\"message\": \"Thimble-L10N - Add strings for $locale\", \
\"content\": \"$content\", \
}"

curl --location-trusted -X PUT \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: token $GH_TOKEN" \
-d "$body"
"https://api.github.com/repos/mozilla/brackets/contents/$ADDED_FILE"
echo "Successfully added strings for $locale"
done

git reset locales
fi

0 comments on commit 7d9b8aa

Please sign in to comment.