feat(create): Generating github action to deploy to github pages (#366)

This commit is contained in:
Matsu
2022-06-09 23:13:36 +03:00
committed by GitHub
parent 873e6f325d
commit 2bc4282efa
3 changed files with 59 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
name: Build and Deploy
on: [push]
permissions:
contents: write
jobs:
build-and-deploy:
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Install and Build 🔧
run: |
npm install
npm run build
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
branch: gh-pages # The branch the action should deploy to.
folder: _site # The folder the action should deploy.

View File

@@ -6,7 +6,10 @@ import { mkdir, readFile } from 'fs/promises';
import path from 'path';
import { existsSync } from 'fs';
import degit from 'degit';
import { generateGithubActionsDeployment } from './deployment-generator.js';
const EXAMPLES_PATH = `modernweb-dev/rocket/examples/`;
const TARGET_BRANCH = `#next`;
const program = new Command();
const choices = await readFile(new URL('./choices.json', import.meta.url)).then(res =>
@@ -114,7 +117,7 @@ export class CreateCli {
let newFolderPath = path.join('.', `rocket-mission`);
if (choices.find(choice => choice.value === url)) {
newFolderPath = path.join('.', `rocket-${url}`);
url = `modernweb-dev/rocket/examples/${url}#next`;
url = `${EXAMPLES_PATH}${url}${TARGET_BRANCH}`;
}
console.log(`${blue('>')} Fueling up the rocket...`);
@@ -168,6 +171,8 @@ export class CreateCli {
}
} while (cloneError === true);
await generateGithubActionsDeployment(newFolderPath);
console.log(`${green('✔')} Final checks are green!`);
console.log('');
console.log('Next steps:');

View File

@@ -0,0 +1,31 @@
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { mkdir } from 'fs/promises';
import path from 'path';
import { blue } from 'colorette';
const GITHUB_ACTION_FILE_PATH = '.github/workflows';
const GITHUB_DEPLOYMENT_FILE_NAME = 'github-build-and-deploy-rocket-action.yml';
const GITHUB_DEPLOYMENT_FILE_PATH = `./deployments/github-pages/${GITHUB_DEPLOYMENT_FILE_NAME}`;
export async function generateGithubActionsDeployment(newFolderPath) {
console.log(`${blue('>')} Generating deployment actions...`);
const githubActionsPath = path.join(newFolderPath, GITHUB_ACTION_FILE_PATH);
await createDeploymentsFolder(githubActionsPath);
const githubDeploymentFile = readFileSync(path.join('.', GITHUB_DEPLOYMENT_FILE_PATH));
const githubDeploymentFileTarget = path.join(
'.',
newFolderPath,
GITHUB_ACTION_FILE_PATH,
GITHUB_DEPLOYMENT_FILE_NAME,
);
writeFileSync(githubDeploymentFileTarget, githubDeploymentFile);
}
async function createDeploymentsFolder(deploymentsPath) {
if (!existsSync(deploymentsPath)) {
await mkdir(deploymentsPath, { recursive: true });
}
}