Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ cache:
- $HOME/.yarn-cache
before_install:
- |
echo "machine github.com login reactjs-bot password $GITHUB_TOKEN" >~/.netrc
unset GITHUB_TOKEN

if [ "$TEST_TYPE" != build_website ] && \
! git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qvE '(\.md$)|(^(docs|examples))/'
then
Expand All @@ -35,7 +38,6 @@ script:
set -e

GH_PAGES_DIR="$TRAVIS_BUILD_DIR"/../react-gh-pages
echo "machine github.com login reactjs-bot password $GITHUB_TOKEN" >~/.netrc
git config --global user.name "$GITHUB_USER_NAME"
git config --global user.email "$GITHUB_USER_EMAIL"

Expand Down Expand Up @@ -121,7 +123,7 @@ env:
# SECRET_TOKEN
- secure: dkpPW+VnoqC/okhRdV90m36NcyBFhcwEKL3bNFExAwi0dXnFao8RoFlvnwiPlA23h2faROkMIetXlti6Aju08BgUFV+f9aL6vLyU7gUent4Nd3413zf2fwDtXIWIETg6uLnOpSykGKgCAT/hY3Q2oPLqOoY0OxfgnbqwxkxljrE=
# GITHUB_TOKEN
- secure: EHCyCSKMwKlLHNtcj9nmkRzmiiPE3aDGlPcnEyrDJeRI0SeN/iCXHXfFivR0vFq3vr+9naMBczAR2AEidtps5KbJrKqdZnjPFRbmfVtzWr/LlvVCub3u13Pub6TdKIVBTny1PuZ5X8GvdxMNVig89jGjvzhhWuQRaz3VhJnTra4=
- secure: Sn+HwLSkbgM5MqVszq/CJHcOsZax17zwW0ILpGgAaEKD6MHNmEBdc71skaLr+6R4gHVO5ybV2cgSxHuBLHKzYoidq5ksGKRHNeXfyOv8jeHGTN/FjwMQbM+WkIK3wFroLsuQ1kW2FBfFEXqx4rET6GXwdcqycGl8GSFB1l0VNzE=
# COVERALLS_TOKEN
- secure: h/cUq+TrUMZOQmkFD7CvuwX0uAwmjIfKZ4qSUzY+QzUtDzOzA0L/XF84xTBq1Q5YYsEiaoF6GxxGCdrLQiBA/ZTd+88UHgeZPMRvi0xG9Q+PeePVOsZMTxy4/WWFgOfSQCk49Mj9zizGgO78i6vxq+SDXMtFHnZ+TpPJIEW6/m0=
notifications:
Expand Down
84 changes: 43 additions & 41 deletions scripts/facts-tracker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@

var fs = require('fs');
var path = require('path');
var execSync = require('child_process').execSync;

function escape(value) {
return '\'' + value.replace(/'/g, "'\\''") + '\'';
}
var execFileSync = require('child_process').execFileSync;

var cwd = null;
function exec(command) {
console.error('>', command.replace(process.env.GITHUB_TOKEN, '************'));
var options = {
stdio: [null, null, null],
};
function exec(command, args) {
console.error('>', [command].concat(args));
var options = {};
if (cwd) {
options.cwd = cwd;
}
return execSync(command, options).toString();
return execFileSync(command, args, options).toString();
}


Expand All @@ -45,7 +39,7 @@ if (isInsideOfTravis) {
process.exit(0);
}

if (!process.env.GITHUB_USER || !process.env.GITHUB_TOKEN) {
if (!process.env.GITHUB_USER) {
console.error(
'In order to use facts-tracker, you need to configure a ' +
'few environment variables in order to be able to commit to the ' +
Expand All @@ -60,8 +54,6 @@ if (isInsideOfTravis) {
'In a different tab, go to https://travis-ci.org/' +
process.env.TRAVIS_REPO_SLUG + '/settings\n' +
' - Make sure "Build only if .travis.yml is present" is ON\n' +
' - Fill "Name" with "GITHUB_TOKEN" and "Value" with the token you ' +
'just generated. Press "Add"\n' +
' - Fill "Name" with "GITHUB_USER" and "Value" with the name of the ' +
'account you generated the token with. Press "Add"\n' +
'\n' +
Expand All @@ -72,16 +64,22 @@ if (isInsideOfTravis) {
}

exec(
'echo "machine github.com login $GITHUB_USER password $GITHUB_TOKEN"' +
'> ~/.netrc'
'git',
[
'config',
'--global',
'user.name',
process.env.GITHUB_USER_NAME || 'facts-tracker',
]
);
exec(
'git config --global user.name ' +
escape(process.env.GITHUB_USER_NAME || 'facts-tracker')
);
exec(
'git config --global user.email ' +
escape(process.env.GITHUB_USER_EMAIL || 'facts-tracker@no-reply.github.com')
'git',
[
'config',
'--global',
'user.email',
process.env.GITHUB_USER_EMAIL || 'facts-tracker@no-reply.github.com',
]
);
}

Expand All @@ -95,50 +93,54 @@ function getRepoSlug() {
return process.env.TRAVIS_REPO_SLUG;
}

var remotes = exec('git remote -v').split('\n');
var remotes = exec('git', ['remote', '-v']).split('\n');
for (var i = 0; i < remotes.length; ++i) {
var match = remotes[i].match(/^origin\t[^:]+:([^\.]+).+\(fetch\)/);
if (match) {
return match[1];
}
}

console.error('Cannot find repository slug, sorry.');
process.exit(1);
}

var repoSlug = getRepoSlug();
var currentCommitHash = exec('git rev-parse HEAD').trim();
var currentCommitHash = exec('git', ['rev-parse', 'HEAD']).trim();
var currentTimestamp = new Date().toISOString()
.replace('T', ' ')
.replace(/\..+/, '');

function checkoutFactsFolder() {
var factsFolder = '../' + repoSlug.split('/')[1] + '-facts';
if (!fs.existsSync(factsFolder)) {
var escapedRepoURL;
var repoURL;
if (isInsideOfTravis) {
escapedRepoURL = 'https://$GITHUB_TOKEN@github.com/' + escape(repoSlug) + '.git';
repoURL = 'https://$GITHUB_USER@github.com/' + repoSlug + '.git';
} else {
escapedRepoURL = escape('git@github.com:' + repoSlug + '.git');
repoURL = 'git@github.com:' + repoSlug + '.git';
}

exec(
'git clone ' +
'--branch facts ' +
'--depth=5 ' +
escapedRepoURL + ' ' +
escape(factsFolder)
'git',
[
'clone',
'--branch',
'facts',
'--depth=5',
repoURL,
factsFolder,
]
);
}

cwd = path.resolve(factsFolder);
exec('git fetch');
if (exec('git status --porcelain')) {
exec('git', ['fetch']);
if (exec('git', ['status', '--porcelain'])) {
console.error('facts-tracker: `git status` is not clean, aborting.');
process.exit(1);
}
exec('git rebase origin/facts');
exec('git', ['rebase', 'origin/facts']);
}
checkoutFactsFolder();

Expand All @@ -155,7 +157,7 @@ for (var i = 2; i < process.argv.length; i += 2) {

var filename = name + '.txt';
try {
var lastLine = exec('tail -n 1 ' + escape(filename));
var lastLine = exec('tail', ['-n', '1', filename]);
} catch (e) {
// ignore error
}
Expand All @@ -175,10 +177,10 @@ for (var i = 2; i < process.argv.length; i += 2) {
console.log(value);
}

if (exec('git status --porcelain')) {
exec('git add --all');
exec('git commit -m ' + escape('Adding facts for ' + currentCommitHash));
exec('git push origin facts');
if (exec('git', ['status', '--porcelain'])) {
exec('git', ['add', '--all']);
exec('git', ['commit', '-m', 'Adding facts for ' + currentCommitHash]);
exec('git', ['push', 'origin', 'facts']);
} else {
console.error('facts-tracker: nothing to update');
}
Expand Down