Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Use JS for the deploy pipeline #1

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
68 changes: 68 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
"private": true,
"version": "1.0.0",
"license": "MIT",
"config": {
"releaseRepository": "https://github.com/Automattic/vip-go-skeleton.git"
},
"scripts": {
"preinstall": "composer install",
"lint-release": "composer lint-release",
"lint": "composer lint && composer verify",
"release": "composer release",
"clean": "rm -rf node_modules public/plugins/vendor",
"deploy-staging": "./scripts/deploy.sh https://github.com/Automattic/vip-go-skeleton.git develop",
"deploy-production": "./scripts/deploy.sh https://github.com/Automattic/vip-go-skeleton.git master"
"deploy-staging": "node scripts/deploy.js $npm_package_config_releaseRepository develop",
"deploy-production": "node scripts/deploy.js $npm_package_config_releaseRepository master"
},
"devDependencies": {
"husky": "^2.1.0"
"fs-extra": "^7.0.1",
"husky": "^2.1.0",
"ignore": "^5.1.1",
"minimist": "^1.2.0",
"simple-git": "^1.110.0"
},
"dependencies": {},
"husky": {
"hooks": {
"pre-commit": "npm run lint",
Expand Down
72 changes: 72 additions & 0 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const exec = require('child_process').execSync;
const parseArgs = require('minimist')
const path = require('path')
const fs = require('fs-extra')
const git = require('simple-git')
const ignore = require('ignore')

// Parse the command-line arguments.
const argv = parseArgs(process.argv.slice(2))
const srcBranch = argv._[1]
const upstreamRepo = argv._[0]

const rootDir = path.join(__dirname, '..')

const config = {
src: {
repo: rootDir,
releaseDir: path.join(rootDir, 'deploy/src/public'),
branch: srcBranch,
dir: path.join(rootDir, 'deploy/src'),
},
dist: {
repo: upstreamRepo,
repoDir: path.join(rootDir, 'deploy/dist-src'),
branch: `deploy/${srcBranch}-${Math.round(new Date().getTime()/1000)}`,
dir: path.join(rootDir, 'deploy/dist'),
},
build: 'npm install && npm run release',
distignore: path.join(rootDir, 'public/.distignore')
}

// Always start with fresh source and release directories.
fs.emptyDirSync(config.src.dir)
fs.emptyDirSync(config.dist.dir)
fs.emptyDirSync(config.dist.repoDir)

// Checkout a fresh copy of the source branch in a new directory.
fs.copySync(
path.join(config.src.repo, '.git'),
path.join(config.src.dir, '.git')
)

// Checkout a fresh source repository.
git(config.src.dir)
.reset('hard')
.checkout(config.src.branch)

// Checkout a fresh release repository.
git(config.dist.repoDir)
kasparsd marked this conversation as resolved.
Show resolved Hide resolved
.clone(config.dist.repo, config.dist.repoDir)
.reset('hard')
.checkoutBranch(config.dist.branch, config.src.branch)

// Run the build.
exec(config.build, {
cwd: config.src.dir
})

// Copy the build to the release directory.
fs.copySync(
config.src.releaseDir,
config.dist.dir,
{
filter: ignore().add(fs.readFileSync(config.distignore).toString()).createFilter()
}
)

// Now make the release directory a release repository.
fs.copySync(
path.join(config.dist.repoDir, '.git'),
path.join(config.dist.dir, '.git')
)