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

feat(setup): add github actions as CI option #502

Merged
merged 23 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add base github actions integration
  • Loading branch information
jeetiss committed Dec 7, 2019
commit 915af26e9c98ed240da39888951958c0123ccc93
79 changes: 79 additions & 0 deletions packages/shipjs/src/step/setup/CI/addGithubActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { getGitConfig } from 'shipjs-lib';
import runStep from '../../runStep';
import fs from 'fs';
import path from 'path';
import ejs from 'ejs';
import mkdirp from 'mkdirp';
import { print } from '../../../util';
import { info, warning } from '../../../color';

// manualPrepare
export default ({ releaseBranch, dir, dryRun }) =>
runStep(
{
title: 'Creating GitHub Actions configuration',
},
() => {
const filePath = path.resolve(
dir,
'.github/workflows',
'shipjs-trigger.yml'
);

if (fs.existsSync(filePath)) {
return () => {
print(
`${warning(
'✘'
)} \`.github/workflows/shipjs-trigger.yml\` already exists.`
);
print(' You can manually configure GitHub Actions');
};
}
const content = getBaseConfig({
releaseBranch,
gitUserName: getGitConfig('user.name') || 'Your Name',
gitUserEmail: getGitConfig('user.email') || '[email protected]',
});
if (dryRun) {
print(`shipjs-trigger.yml`);
print(content);
} else {
mkdirp.sync(path.dirname(filePath));
fs.writeFileSync(filePath, content);
}
return () => {
print(`${info('✔')} Created \`.github/workflows/shipjs-trigger.yml\`.`);
print(' You still need to finish setting up at GitHub Actions.');
};
}
);

function getBaseConfig({ releaseBranch, gitUserName, gitUserEmail }) {
return ejs.render(
`
name: Ship js trigger
on:
push:
branches:
- <%= releaseBranch %>
jobs:
build:
name: Build
runs-on: Ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
registry-url: "https://registry.npmjs.org"
- run: git switch master
- run: npm install
- run: npm run release:trigger
env:
GITHUB_TOKEN: \${{ secrets.GH_TOKEN }}
NODE_AUTH_TOKEN: \${{ secrets.NPM_TOKEN }}

`,
{ releaseBranch, gitUserName, gitUserEmail }
);
}
20 changes: 20 additions & 0 deletions packages/shipjs/src/step/setup/CI/askGithubActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import inquirer from 'inquirer';
import formatMessage from '../formatMessage';

export default async function askGithubActions() {
const { manualPrepare } = await inquirer.prompt([
{
type: 'confirm',
name: 'manualPrepare',
message: formatMessage(
'Add manual prepare with issue comment?',
'You can create `@shipjs prepare` comment on any issue and then github actions run `shipjs prepare`'
),
default: true,
},
]);

return {
manualPrepare,
};
}
8 changes: 8 additions & 0 deletions packages/shipjs/src/step/setup/CI/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import askCircleCI from './askCircleCI';
import addCircleCIConfig from './addCircleCIConfig';

import askGithubActions from './askGithubActions';
import addGithubActions from './addGithubActions';

const noop = () => ({});

export default [
Expand All @@ -9,6 +12,11 @@ export default [
askQustions: askCircleCI,
addConfig: addCircleCIConfig,
},
{
name: 'Github Actions',
askQustions: askGithubActions,
addConfig: addGithubActions,
},
{
name: 'Nothing',
askQustions: noop,
Expand Down