Skip to content
Open
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
21 changes: 17 additions & 4 deletions .github/workflows/update_gh_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ name: Update GitHub Pages
on:
workflow_dispatch: # Manually trigger. Colon is required.
inputs:
branch:
description: 'Branch to publish from'
samples_branch:
description: 'Blockly-Samples branch to publish from (for examples)'
required: true
default: 'main'
type: string
core_branch:
description: 'Blockly core branch to publish from (for plugins)'
required: true
default: 'main'
type: string
Expand All @@ -20,10 +25,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
- name: Checkout Blockly-Samples
uses: actions/checkout@v3
with:
ref: ${{ inputs.samples_branch || 'main' }}
path: blockly-samples

- name: Checkout Blockly
uses: actions/checkout@v3
with:
ref: ${{ inputs.branch || 'main' }}
repository: 'RaspberryPiFoundation/blockly'
ref: ${{ inputs.core_branch || 'main' }}
path: blockly

- name: Setup Node
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"clean": "lerna run clean --scope '@blockly/*'",
"deploy:prepare": "npm run deploy:prepare:plugins && npm run deploy:prepare:examples && gulp predeploy",
"deploy:prepare:examples": "npm install --workspace=examples && npm run prepare-examples && npm run predeploy --if-present --workspace=examples",
"deploy:prepare:plugins": "npm run clean && npm run build && lerna run predeploy --scope '@blockly/*'",
"deploy:prepare:plugins": "cd ../blockly && npx nx reset && lerna run clean --scope '@blockly/*' && lerna run build --scope '@blockly/*' && lerna run predeploy --scope '@blockly/*'",
"deploy": "npm run deploy:prepare && gulp deploy",
"deploy:upstream": "npm run deploy:prepare && gulp deployUpstream",
"format": "prettier --write .",
Expand Down
9 changes: 8 additions & 1 deletion scripts/copy-blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ const {copyDirectoryContents} = require('./copy-helpers');

// Also copy local workspace plugins from the `plugins/` directory (this repo).
try {
const pluginsDir = path.resolve(__dirname, '..', 'plugins');
const pluginsDir = path.resolve(
__dirname,
'..',
'..',
'blockly',
'packages',
'plugins',
);
const pluginDirs = await fs.readdir(pluginsDir, {withFileTypes: true});
const copiedLocal = [];
for (const d of pluginDirs) {
Expand Down
62 changes: 46 additions & 16 deletions scripts/gh-predeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const {copyFilesWithBase, copyDirectoryContents} = require('./copy-helpers');
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);

const PLUGIN_FOLDER_PATH = path.join('..', 'blockly', 'packages', 'plugins');

/**
* Inject head HTML for a plugin or example page on gh-pages.
* @param {string} initialContents The initial page HTML, as a string.
Expand Down Expand Up @@ -209,8 +211,11 @@ function createExampleTabs(pageRoot, pages, isLocal) {
* building for gh-pages.
*/
function createPluginPage(pluginDir, isLocal) {
const packageJson = require(resolveApp(`plugins/${pluginDir}/package.json`));
const initialPath = path.join('plugins', pluginDir, 'test', 'index.html');
const pluginPath = path.join(PLUGIN_FOLDER_PATH, pluginDir);
const packageJson = require(
resolveApp(path.join(pluginPath, 'package.json')),
);
const initialPath = path.join(pluginPath, 'test', 'index.html');
const initialContents = fs.readFileSync(initialPath).toString();

let contents = injectHeader(
Expand All @@ -236,9 +241,11 @@ function createPluginPage(pluginDir, isLocal) {
* building for gh-pages.
*/
function createReadmePage(pluginDir, isLocal) {
const packageJson = require(resolveApp(`plugins/${pluginDir}/package.json`));
const packageJson = require(
resolveApp(path.join(PLUGIN_FOLDER_PATH, pluginDir, 'package.json')),
);
const initialContents = fs
.readFileSync(`./plugins/${pluginDir}/README.md`)
.readFileSync(path.join(PLUGIN_FOLDER_PATH, pluginDir, 'README.md'))
.toString();

const converter = new showdown.Converter();
Expand Down Expand Up @@ -279,9 +286,13 @@ function createReadmePage(pluginDir, isLocal) {
modifiedContents = injectFooter(modifiedContents);

// Make sure the directory exists, then write to it.
const dirString = `./gh-pages/plugins/${pluginDir}/`;
fs.mkdirSync(dirString, {recursive: true});
fs.writeFileSync(`${dirString}/README.html`, modifiedContents, 'utf-8');
const dirPath = path.join('gh-pages', 'plugins', pluginDir);
fs.mkdirSync(dirPath, {recursive: true});
fs.writeFileSync(
path.join(dirPath, 'README.html'),
modifiedContents,
'utf-8',
);
}

/**
Expand All @@ -295,11 +306,26 @@ function preparePlugin(pluginDir, isLocal) {
console.log(`Preparing ${pluginDir} plugin for deployment.`);
createPluginPage(pluginDir, isLocal);
createReadmePage(pluginDir, isLocal);
copyFilesWithBase(
[path.join('plugins', pluginDir, 'build', 'test_bundle.js')],
const testBundleFilePath = path.join(
PLUGIN_FOLDER_PATH,
pluginDir,
'build',
'test_bundle.js',
);
const destinationFilePath = path.join(
'gh-pages',
'plugins',
path.join('gh-pages', 'plugins'),
pluginDir,
'build',
'test_bundle.js',
);
if (
fs.existsSync(testBundleFilePath) &&
fs.statSync(testBundleFilePath).isFile()
) {
fs.mkdirSync(path.dirname(destinationFilePath), {recursive: true});
fs.copyFileSync(testBundleFilePath, destinationFilePath);
}
}

/**
Expand All @@ -308,13 +334,12 @@ function preparePlugin(pluginDir, isLocal) {
* for deployment to GitHub Pages.
*/
function getPluginFolders() {
const dir = 'plugins';
return fs.readdirSync(dir).filter(function (file) {
return fs.readdirSync(PLUGIN_FOLDER_PATH).filter(function (file) {
return (
fs.statSync(path.join(dir, file)).isDirectory() &&
fs.existsSync(path.join(dir, file, 'package.json')) &&
fs.statSync(path.join(PLUGIN_FOLDER_PATH, file)).isDirectory() &&
fs.existsSync(path.join(PLUGIN_FOLDER_PATH, file, 'package.json')) &&
// Only prepare plugins with test pages.
fs.existsSync(path.join(dir, file, '/test/index.html'))
fs.existsSync(path.join(PLUGIN_FOLDER_PATH, file, '/test/index.html'))
);
});
}
Expand Down Expand Up @@ -483,7 +508,12 @@ function prepareExample(exampleDir, isLocal, done) {
const pages = fileList.filter((f) => pageRegex.test(f));
// Add headers and footers to HTML pages.
pages.forEach((page) =>
createExamplePage(`${baseDir}/${exampleDir}`, page, demoConfig, isLocal),
createExamplePage(
path.join(baseDir, exampleDir),
page,
demoConfig,
isLocal,
),
);

// Copy over all other files mentioned in the demoConfig to the
Expand Down
Loading