mirror of
https://github.com/google/blockly.git
synced 2025-12-15 22:00:07 +01:00
fix(build): Fix GitHub pages & deployment task (#7186)
* fix(build): Include node_modules/@blockly/ in gh-pages branch
- Add node_modules/@blockly to the list of files added to the gh-pages
branch.
- Add a _config.yml file telling Jekyll (which is needed to produce
the homepage served at https://google.github.io/blockly/, and hence
can't be disabled with a .nojekyll file instead) not to exclude
node_modules (which it does by default).
* refactor(build): Modernise git_tasks.js
- Various style updates:
- Use CONSTANT_CASE.
- Use /** JSDoc comments */
- Use `template ${literals}`.
- Use git switch instead of git checkout.
- Try to avoid use of remote names; use URLs where possible.
* refactor(build): Look up upstream git remote
Since git reset can't take a URL but needs an actual remote name,
use git branch -v to look up the remote for
github.com/google/blockly and then use that remote name.
* chores(build): format
This commit is contained in:
committed by
GitHub
parent
ace9c4a188
commit
4adc932ed5
1
_config.yml
Normal file
1
_config.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
exclude: []
|
||||||
@@ -14,83 +14,128 @@ const execSync = require('child_process').execSync;
|
|||||||
const buildTasks = require('./build_tasks');
|
const buildTasks = require('./build_tasks');
|
||||||
const packageTasks = require('./package_tasks');
|
const packageTasks = require('./package_tasks');
|
||||||
|
|
||||||
const upstream_url = "https://github.com/google/blockly.git";
|
const UPSTREAM_URL = 'https://github.com/google/blockly.git';
|
||||||
|
|
||||||
// Stash current state, check out the named branch, and sync with
|
/**
|
||||||
// google/blockly.
|
* Extra paths to include in the gh_pages branch (beyond the normal
|
||||||
|
* contents of master / develop). Passed to shell unquoted, so can
|
||||||
|
* include globs.
|
||||||
|
*/
|
||||||
|
const EXTRAS = [
|
||||||
|
'build/msg',
|
||||||
|
'dist/*_compressed.js*',
|
||||||
|
'node_modules/@blockly',
|
||||||
|
];
|
||||||
|
|
||||||
|
let upstream = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get name of git remote for upstream (typically 'upstream', but this
|
||||||
|
* is just convention and can be changed.)
|
||||||
|
*/
|
||||||
|
function getUpstream() {
|
||||||
|
if (upstream) return upstream;
|
||||||
|
for (const line of String(execSync('git remote -v')).split('\n')) {
|
||||||
|
const [remote, url] = line.split('\t');
|
||||||
|
if (url.includes('github.com/google/blockly')) {
|
||||||
|
upstream = remote;
|
||||||
|
return upstream;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error('Unable to determine upstream URL');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stash current state, check out the named branch, and sync with
|
||||||
|
* google/blockly.
|
||||||
|
*/
|
||||||
function syncBranch(branchName) {
|
function syncBranch(branchName) {
|
||||||
return function(done) {
|
return function(done) {
|
||||||
execSync('git stash save -m "Stash for sync"', { stdio: 'inherit' });
|
execSync('git stash save -m "Stash for sync"', { stdio: 'inherit' });
|
||||||
checkoutBranch(branchName);
|
checkoutBranch(branchName);
|
||||||
execSync('git pull ' + upstream_url + ' ' + branchName,
|
execSync(`git pull ${UPSTREAM_URL} ${branchName}`, { stdio: 'inherit' });
|
||||||
{ stdio: 'inherit' });
|
execSync(`git push origin ${branchName}`, { stdio: 'inherit' });
|
||||||
execSync('git push origin ' + branchName, { stdio: 'inherit' });
|
|
||||||
done();
|
done();
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stash current state, check out develop, and sync with google/blockly.
|
/**
|
||||||
|
* Stash current state, check out develop, and sync with
|
||||||
|
* google/blockly.
|
||||||
|
*/
|
||||||
function syncDevelop() {
|
function syncDevelop() {
|
||||||
return syncBranch('develop');
|
return syncBranch('develop');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Stash current state, check out master, and sync with google/blockly.
|
/**
|
||||||
|
* Stash current state, check out master, and sync with
|
||||||
|
* google/blockly.
|
||||||
|
*/
|
||||||
function syncMaster() {
|
function syncMaster() {
|
||||||
return syncBranch('master');
|
return syncBranch('master');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function: get a name for a rebuild branch. Format: rebuild_mm_dd_yyyy.
|
/**
|
||||||
|
* Helper function: get a name for a rebuild branch. Format:
|
||||||
|
* rebuild_mm_dd_yyyy.
|
||||||
|
*/
|
||||||
function getRebuildBranchName() {
|
function getRebuildBranchName() {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const mm = date.getMonth() + 1; // Month, 0-11
|
const mm = date.getMonth() + 1; // Month, 0-11
|
||||||
const dd = date.getDate(); // Day of the month, 1-31
|
const dd = date.getDate(); // Day of the month, 1-31
|
||||||
const yyyy = date.getFullYear();
|
const yyyy = date.getFullYear();
|
||||||
return 'rebuild_' + mm + '_' + dd + '_' + yyyy;
|
return `rebuild_${mm}_${dd}_${yyyy}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function: get a name for a rebuild branch. Format: rebuild_yyyy_mm.
|
/**
|
||||||
|
* Helper function: get a name for a rebuild branch. Format:
|
||||||
|
* rebuild_yyyy_mm.
|
||||||
|
*/
|
||||||
function getRCBranchName() {
|
function getRCBranchName() {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const mm = date.getMonth() + 1; // Month, 0-11
|
const mm = date.getMonth() + 1; // Month, 0-11
|
||||||
const yyyy = date.getFullYear();
|
const yyyy = date.getFullYear();
|
||||||
return 'rc_' + yyyy + '_' + mm;
|
return `rc_${yyyy}_${mm}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// If branch does not exist then create the branch.
|
/**
|
||||||
// If branch exists switch to branch.
|
* If branch does not exist then create the branch.
|
||||||
|
* If branch exists switch to branch.
|
||||||
|
*/
|
||||||
function checkoutBranch(branchName) {
|
function checkoutBranch(branchName) {
|
||||||
execSync('git checkout ' + branchName + ' || git checkout -b ' + branchName,
|
execSync(`git switch -c ${branchName}`,
|
||||||
{ stdio: 'inherit' });
|
{ stdio: 'inherit' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and push an RC branch.
|
/**
|
||||||
// Note that this pushes to google/blockly.
|
* Create and push an RC branch.
|
||||||
|
* Note that this pushes to google/blockly.
|
||||||
|
*/
|
||||||
const createRC = gulp.series(
|
const createRC = gulp.series(
|
||||||
syncDevelop(),
|
syncDevelop(),
|
||||||
function(done) {
|
function(done) {
|
||||||
const branchName = getRCBranchName();
|
const branchName = getRCBranchName();
|
||||||
execSync('git checkout -b ' + branchName, { stdio: 'inherit' });
|
execSync(`git switch -C ${branchName}`, { stdio: 'inherit' });
|
||||||
execSync('git push ' + upstream_url + ' ' + branchName,
|
execSync(`git push ${UPSTREAM_URL} ${branchName}`, { stdio: 'inherit' });
|
||||||
{ stdio: 'inherit' });
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create the rebuild branch.
|
/** Create the rebuild branch. */
|
||||||
function createRebuildBranch(done) {
|
function createRebuildBranch(done) {
|
||||||
const branchName = getRebuildBranchName();
|
const branchName = getRebuildBranchName();
|
||||||
console.log('make-rebuild-branch: creating branch ' + branchName);
|
console.log(`make-rebuild-branch: creating branch ${branchName}`);
|
||||||
execSync('git checkout -b ' + branchName, { stdio: 'inherit' });
|
execSync(`git switch -C ${branchName}`, { stdio: 'inherit' });
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push the rebuild branch to origin.
|
/** Push the rebuild branch to origin. */
|
||||||
function pushRebuildBranch(done) {
|
function pushRebuildBranch(done) {
|
||||||
console.log('push-rebuild-branch: committing rebuild');
|
console.log('push-rebuild-branch: committing rebuild');
|
||||||
execSync('git commit -am "Rebuild"', { stdio: 'inherit' });
|
execSync('git commit -am "Rebuild"', { stdio: 'inherit' });
|
||||||
const branchName = getRebuildBranchName();
|
const branchName = getRebuildBranchName();
|
||||||
execSync('git push origin ' + branchName, { stdio: 'inherit' });
|
execSync(`git push origin ${branchName}`, { stdio: 'inherit' });
|
||||||
console.log('Branch ' + branchName + ' pushed to GitHub.');
|
console.log(`Branch ${branchName} pushed to GitHub.`);
|
||||||
console.log('Next step: create a pull request against develop.');
|
console.log('Next step: create a pull request against develop.');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@@ -103,20 +148,20 @@ function pushRebuildBranch(done) {
|
|||||||
const updateGithubPages = gulp.series(
|
const updateGithubPages = gulp.series(
|
||||||
function(done) {
|
function(done) {
|
||||||
execSync('git stash save -m "Stash for sync"', { stdio: 'inherit' });
|
execSync('git stash save -m "Stash for sync"', { stdio: 'inherit' });
|
||||||
execSync('git checkout gh-pages || git checkout -b gh-pages', { stdio: 'inherit' });
|
execSync('git switch -C gh-pages', { stdio: 'inherit' });
|
||||||
execSync('git fetch upstream', { stdio: 'inherit' });
|
execSync(`git fetch ${getUpstream()}`, { stdio: 'inherit' });
|
||||||
execSync('git reset --hard upstream/develop', { stdio: 'inherit' });
|
execSync(`git reset --hard ${getUpstream()}/develop`, { stdio: 'inherit' });
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
buildTasks.cleanBuildDir,
|
buildTasks.cleanBuildDir,
|
||||||
packageTasks.cleanReleaseDir,
|
packageTasks.cleanReleaseDir,
|
||||||
buildTasks.build,
|
buildTasks.build,
|
||||||
function(done) {
|
function(done) {
|
||||||
// The build and dist directories are normally gitignored, so we have to force add.
|
// Extra paths (e.g. build/, dist/ etc.) are normally gitignored,
|
||||||
execSync('git add -f build/msg/* dist/*_compressed.js*', {stdio: 'inherit'});
|
// so we have to force add.
|
||||||
|
execSync(`git add -f ${EXTRAS.join(' ')}`, {stdio: 'inherit'});
|
||||||
execSync('git commit -am "Rebuild"', {stdio: 'inherit'});
|
execSync('git commit -am "Rebuild"', {stdio: 'inherit'});
|
||||||
execSync('git push ' + upstream_url + ' gh-pages --force',
|
execSync(`git push ${UPSTREAM_URL} gh-pages --force`, {stdio: 'inherit'});
|
||||||
{stdio: 'inherit'});
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user