Skip to content

Commit

Permalink
script: move tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
sylingd committed Dec 20, 2019
1 parent 0a8bc74 commit cab2136
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 127 deletions.
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,15 @@ deploy:

env:
global:
# GitHub Token (for docs)
- secure: CWCrVum9h0996SkQgzGourEYisqdVw/PEl36Ue6D7gdsPGZgOhCzJCJkKH5Uk3fkNF4GXHA0u+8eOJGyMiHXWH1D10+fgYDUSuEEE8/kaUhAvDXymQwJim+tax1johoa5WyitjyWxCXFtfHBcBC6uDI02jkEhhiSUASsXetEFi9I9z4KI2zDLQk8s+y2PKGinusnFGcY1eSKISeDNYP3AZbaieVpgFsiVK+uTLxlmN+l2j7MfnOTZ05VAEQBRGpe0jB9aTm2nSPmXWHvVOb60RhrpI+U2xRGTej+VvoKjIYgz2oSdtC+SQQAtuBAeX+jdpkrK3/Y18n9qCDOjlHZv2RohQEcHzyIOcErF/bwW6ZqYNFOogB2svoiSNCrKPJLCTdl9L0dro+vLSUBxt6F10sTANswe8j9sNVOr9kfsamJRAGDlHItyGA5qC44miO+3ZQyEAXNLJHMctilSrmy3wZqUAOVXl6azJlZrzNt+XVZCrq5FMr+3Fc+p+RhoSheKJi2G8ICFDqqAqOgVxW6nV+3V6yG1arTqX8ArV2wHziFArwotIqdZwWnwdFCfn5kAZpoRefRx45zbj1qJEBO8ByZvwYq3LHr3tsFDenyriMXaNidqMfJlDtAKoyVKdDi/7oWSpzzvupX2ThxVeQF68IJ6v+9Y2U7SUo9LtdRFFk=
- secure: VtVRiZQIiVVsvVpoMAvYjFyr9ZeDWppMw0FZGeCKAcXdrJxaqe7XuQVPDcWZv1UQq4Gq1B2CbfBMPXrH19iaQ62Dcz+vvbg5euc4Ioix5tul7uawE0pOQdFcopua9BQxwGOyziiVvBXPjTMXEzzyKIRmW/Fg7/eUbVmBcSFVIz0SF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WvxP9vuvATHh86FpUBhYemOtnVA+EIrJkekJntTVpyd15T2q0qFKdUYwTmZG7J+Z0nofw3B4bzbUxs/gtJM=
# GitHub Token (for release)
- secure: lTAEtc+R4/W3C/OcmXQ/EfdxS9/6c8NoKZ/CzzBbprJ9vKo1AyeSINsu3yryGViQgL87WXWIN1d+0P7ssJw3SLDhQvJUCzAdraRjOe2VzWW5z2HD18Mm1+lK5FYveV32bGcF4k0g8HvsXXUb654iEh8jpxa6AjQX7c75owrMjKkJMRwZSfHvrzBOKLzAHHNtRmU2if/KoOHTZyxAJwVY3UkKsr+ihO7uJZheUA64UWe/yNgQOy2Shq/fV7PfxggqAX0WzVUdWOF04uD/APdwnTR3X8Eqz0W1ux+AR2jFm/+8fjugzAUFElaSK2XQJQf6u3/0iHY0tLRY5XzH59XabaqOduy5YCOwT69ekZdQ/j2RmExEouNCJU9E9Rr+y8gZFR2hhVoLRWnGb0zNNw3UlBgAd8ER0d9mkHllfzuHFpJm3LXzSozNNdx89weXPZNDleu2Gs/R3kF3BsNssxh5AsrX9xFj5br5TjWdpFAlWcbD6Ti/MtBbJVgFXdc76oVP6H9HGouu3Rb+dOZkbyN9Bxsepn6kEt1xYnD5HwIlhte8/v+EiUcAzLg21R91MFZK1NbZwivexK+mm3rx4ezg8LlzQxM4fIeTdRf9+L4hXajBoVKgbmIgLGEmxcLCOLgSxSSSowT+Sk9LaX7e30Pn6Qqy9x79JQUmdLu7eeQOFsM=
3 changes: 2 additions & 1 deletion build/pack-utils/common.js → build/extension-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ const root = path.resolve(__dirname, '..', '..');
const pack = path.resolve(root, 'dist-pack');
const dist = path.resolve(pack, 'copy-dist');
const encrypt = path.resolve(root, 'encrypt');
const config = require(path.resolve(root, 'extension.json'));
const package = require(path.resolve(root, 'package.json'));

module.exports = {
version: package.version,
config: package.webextension,
config,
resolve: path.resolve,
root,
pack,
Expand Down
5 changes: 2 additions & 3 deletions build/pack-utils/amo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const merge = require('merge');
const common = require('./common');
const signAddon = require('sign-addon').default;
const exec = require('child_process').exec;
const AMOUser = require(common.encrypt('amo.json'));

module.exports = function(manifest) {
return new Promise(resolve => {
Expand All @@ -25,8 +24,8 @@ module.exports = function(manifest) {
signAddon({
xpiPath: zipPath,
version: common.version,
apiKey: AMOUser.key,
apiSecret: AMOUser.secret,
apiKey: common.config.firefox.mozilla.key,
apiSecret: process.env[common.config.firefox.mozilla.secret],
id: common.config.firefox.amo
})
.then(() => {
Expand Down
78 changes: 65 additions & 13 deletions build/pack-utils/cws.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,65 @@
const fs = require('fs');
const fetch = require('node-fetch');
const exec = require('child_process').exec;
const webStore = require('chrome-webstore-upload');
const common = require('./common');
const CWSUser = require(common.encrypt('cws.json'));
const client = webStore({
extensionId: common.config.chrome.id,
clientId: CWSUser.id,
clientSecret: CWSUser.secret,
refreshToken: CWSUser.token
});
const common = require('../extension-config');
const webStoreId = common.config.chrome.store.id;
const webStoreToken = process.env[common.config.chrome.store.token];
const webStoreSecret = process.env[common.config.chrome.store.secret];

let _webStoreToken = null;
function getToken() {
if (_webStoreToken) {
return Promise.resolve(_webStoreToken);
}
return new Promise((resolve, reject) => {
fetch('https://www.googleapis.com/oauth2/v4/token', {
method: "POST",
headers: {
"Content-Type": 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
client_id: webStoreId,
client_secret: webStoreSecret,
refresh_token: webStoreToken,
grant_type: 'refresh_token'
}).toString()
})
.then(res => res.json())
.then(res => {
if (res.access_token) {
_webStoreToken = res.access_token;
resolve(_webStoreToken);
} else {
reject(res.error);
}
})
.catch(reject);
});
}

function upload(readStream, token) {
return fetch('https://www.googleapis.com/upload/chromewebstore/v1.1/items/' + common.config.chrome.id, {
method: "PUT",
headers: {
Authorization: `Bearer ${token}`,
'x-goog-api-version': '2'
},
body: readStream
})
.then(res => res.json());
}

function publish(target = 'default', token) {
const url = 'https://www.googleapis.com/chromewebstore/v1.1/items/' + common.config.chrome.id + '/publish?publishTarget=' + target;
return fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
'x-goog-api-version': '2'
}
})
.then(res => res.json());
}

module.exports = function() {
return new Promise(resolve => {
Expand All @@ -19,15 +70,16 @@ module.exports = function() {
resolve();
} else {
const distStream = fs.createReadStream(zipPath);
client.fetchToken().then(token => {
client.uploadExisting(distStream, token)
.then(() => client.publish("default", token))
getToken().then(token => {
upload(distStream, token)
.then(() => publish("default", token))
.then(() => {
fs.unlinkSync(zipPath);
resolve();
})
.catch(console.log);
});
})
.catch(console.log);
}
});
})
Expand Down
5 changes: 2 additions & 3 deletions build/pack-utils/xpi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const merge = require('merge');
const common = require('./common');
const signAddon = require('sign-addon').default;
const exec = require('child_process').exec;
const AMOUser = require(common.encrypt('amo.json'));

module.exports = function(manifest, outputDir) {
return new Promise(resolve => {
Expand All @@ -26,8 +25,8 @@ module.exports = function(manifest, outputDir) {
signAddon({
xpiPath: zipPath,
version: common.version,
apiKey: AMOUser.key,
apiSecret: AMOUser.secret,
apiKey: common.config.firefox.mozilla.key,
apiSecret: process.env[common.config.firefox.mozilla.secret],
id: common.config.firefox.xpi,
downloadDir: common.pack
})
Expand Down
4 changes: 2 additions & 2 deletions build/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const publishRelease = require('publish-release');
const rootDir = path.resolve(__dirname, '..');
const package = require('../package.json');
const output = path.resolve(rootDir, 'dist-pack');
const GitHubUser = require(path.resolve(rootDir, 'encrypt', 'github.json'));
const config = require('./extension-config').config;

if (!package.webextension.github.enable) {
console.log("GitHub not enabled");
Expand Down Expand Up @@ -34,7 +34,7 @@ const gitName = package.repository.url.match(/(\w+)\/(\w+)\.git/);
const tagName = package.webextension.github.tag.replace('{VER}', package.version);

publishRelease({
token: GitHubUser.token,
token: process.env[config.github.token],
owner: gitName[1],
repo: gitName[2],
tag: tagName,
Expand Down
33 changes: 33 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"dist": "HeaderEditor-{VER}",
"autobuild": {
"xpi": true,
"amo": true,
"cwx": true,
"crx": false
},
"firefox": {
"mozilla": {
"key": "user:12835504:478",
"secret": "AMO_SECRET"
},
"version": "52.0",
"xpi": "headereditor@addon.firefoxcn.net",
"amo": "headereditor-amo@addon.firefoxcn.net",
"update": "https://ext.firefoxcn.net/headereditor/install/update.json"
},
"chrome": {
"store": {
"id": "532608894666-d0d7mq11u6oue4hqrtduu6rcid1sd8cb.apps.googleusercontent.com",
"token": "CWS_TOKEN",
"secret": "CWS_SECRET"
},
"id": "eningockdidmgiojffjmkdblpjocbhgh",
"update": "https://ext.firefoxcn.net/headereditor/install/update.xml"
},
"github": {
"enable": true,
"token": "GITHUB_RELEASE_TOKEN",
"tag": "{VER}"
}
}
25 changes: 1 addition & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,11 @@
"release": "node ./build/release.js",
"pack": "node ./build/pack.js"
},
"webextension": {
"dist": "HeaderEditor-{VER}",
"autobuild": {
"xpi": false,
"amo": false,
"cwx": true,
"crx": false
},
"firefox": {
"version": "52.0",
"xpi": "headereditor@addon.firefoxcn.net",
"amo": "headereditor-amo@addon.firefoxcn.net",
"update": "https://ext.firefoxcn.net/headereditor/install/update.json"
},
"chrome": {
"id": "eningockdidmgiojffjmkdblpjocbhgh",
"update": "https://ext.firefoxcn.net/headereditor/install/update.xml"
},
"github": {
"enable": true,
"tag": "{VER}"
}
},
"dependencies": {
"dateformat": "^3.0.3",
"fast-deep-equal": "^2.0.1",
"merge": "^1.2.0",
"node-fetch": "^2.6.0",
"text-encoding": "^0.7.0",
"vue": "^2.5.17",
"vue-material": "^1.0.0-beta-10.2",
Expand All @@ -57,7 +35,6 @@
"arg": "^2.0.0",
"babel-eslint": "^9.0.0",
"babel-loader": "^8.0.2",
"chrome-webstore-upload": "^0.2.2",
"copy-webpack-plugin": "^4.5.2",
"core-js": "2",
"cross-env": "^5.2.0",
Expand Down
Loading

0 comments on commit cab2136

Please sign in to comment.