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

[#61] Add GitHub add-on #97

Merged
merged 10 commits into from
Aug 26, 2022
20 changes: 20 additions & 0 deletions skeleton/github/.github/ISSUE_TEMPLATE/bug_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "Bug Report"
about: "You found something that is not working. Report it so that it can be fixed. πŸ‘·β€"
title: "Fix: "
labels: "type : bug"
---

## Issue

Describe the issue you are facing. Show us the implementation: screenshots, GIFs, etc.

## Expected

Describe what should be the correct behavior.

## Steps to reproduce

1.
2.
3.
14 changes: 14 additions & 0 deletions skeleton/github/.github/ISSUE_TEMPLATE/chore_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: "Chore"
about: "Open a chore issue for a minor update."
title: "Update "
labels: "type : chore"
---

## Why

Describe the update in detail and why it is needed.

## Who Benefits?

Describe who will be the beneficiaries e.g. everyone, specific chapters, clients...
14 changes: 14 additions & 0 deletions skeleton/github/.github/ISSUE_TEMPLATE/feature_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: "Feature"
about: "Open a feature issue to add new functionalities."
title: "Add "
labels: "type : feature"
---

## Why

Describe the big picture of the feature and why it is needed.

## Who Benefits?

Describe who will be the beneficiaries e.g. everyone, specific chapters, clients...
22 changes: 22 additions & 0 deletions skeleton/github/.github/ISSUE_TEMPLATE/story_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: "Story"
about: "Open a feature story"
title: "[Type] As a user, I can "
labels: "type : feature"
---

## Why

Describe the idea of the user story as in what the motive of the user story is.

## Acceptance Criteria

List down how the user story will be tested and what criteria are necessary for the user story to be accepted.

## Design

(Optional) Add design screenshots or Figma links for UI/UX-related stories.

## Resources

(Optional) Add useful resources such as links to documentation, implementation ideas, or best practices.
13 changes: 13 additions & 0 deletions skeleton/github/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
https://github.com/nimblehq/git-template/issues/??
malparty marked this conversation as resolved.
Show resolved Hide resolved

## What happened πŸ‘€

Describe the big picture of your changes here to communicate to the team why we should accept this pull request.

## Insight πŸ“

Describe in detail how to test the changes, which solution you tried but did not go with, referenced documentation is welcome as well.

## Proof Of Work πŸ“Ή

Show us the implementation: screenshots, GIFs, etc.
19 changes: 19 additions & 0 deletions skeleton/github/.github/PULL_REQUEST_TEMPLATE/release_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Link to the milestone on Github e.g. https://github.com/nimblehq/project-name/milestone/1?closed=1
or
Link to the project management tool for the release

## Features

Provide the ID and title of the issue in the section for each type (feature, chore and bug). The link is optional.

- [ch1234] As a user, I can log in
or
- [[ch1234](https://github.com/nimblehq/project-name/issues/1234)] As a user, I can log in

## Chores

- Same structure as in ## Feature

## Bugs

- Same structure as in ## Feature
34 changes: 34 additions & 0 deletions skeleton/github/.github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Lint

on:
push:

env:
TERRAFORM_VERSION: "1.2.4"

jobs:
linting:
name: Linting

runs-on: ubuntu-latest

timeout-minutes: 5

steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout the repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Install Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}

- name: Run Terraform format
run: terraform fmt -recursive -check
34 changes: 34 additions & 0 deletions skeleton/github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
48 changes: 44 additions & 4 deletions src/commands/generate/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { existsSync } from 'fs-extra';
import { prompt } from 'inquirer';

import Generator from '.';
Expand Down Expand Up @@ -33,6 +32,10 @@ describe('Generator command', () => {
Error('This type has not been implemented!')
);
});

it('does NOT create any files', () => {
expect(projectDir).toBeEmpty();
});
});

describe('given infrastructure type is advanced', () => {
Expand All @@ -41,7 +44,10 @@ describe('Generator command', () => {

beforeAll(async () => {
(prompt as unknown as jest.Mock)
.mockResolvedValueOnce({ provider: 'aws' })
.mockResolvedValueOnce({
provider: 'aws',
versionControl: 'github',
})
.mockResolvedValueOnce({ infrastructureType: 'advanced' });

await Generator.run([projectDir]);
Expand All @@ -52,8 +58,34 @@ describe('Generator command', () => {
remove('/', projectDir);
});

it('creates a new project folder', () => {
expect(existsSync(projectDir)).toBe(true);
it('creates expected directories', () => {
const expectedDirectories = [
'modules/alb/',
'modules/bastion/',
'modules/ecr/',
'modules/ecs/',
'modules/log/',
'modules/rds/',
'modules/s3/',
'modules/security_group/',
'modules/ssm/',
'modules/vpc/',
'.github/',
];

expect(projectDir).toHaveDirectories(expectedDirectories);
});

it('creates expected files', () => {
const expectedFiles = [
'.gitignore',
'main.tf',
'variables.tf',
'providers.tf',
'outputs.tf',
];

expect(projectDir).toHaveFiles(expectedFiles);
});

it('displays the success message', () => {
Expand Down Expand Up @@ -86,6 +118,10 @@ describe('Generator command', () => {
Error('This provider has not been implemented!')
);
});

it('does NOT create any files', () => {
expect(projectDir).toBeEmpty();
});
});

describe('given provider is Heroku', () => {
Expand All @@ -110,6 +146,10 @@ describe('Generator command', () => {
Error('This provider has not been implemented!')
);
});

it('does NOT create any files', () => {
expect(projectDir).toBeEmpty();
});
});

describe('postProcess', () => {
Expand Down
22 changes: 19 additions & 3 deletions src/commands/generate/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Command } from '@oclif/core';
import { prompt } from 'inquirer';

import { getProjectPath } from '../../helpers/file';
import { getProjectPath, remove } from '../../helpers/file';
import { detectTerraform, formatCode } from '../../helpers/terraform';
import {
applyVersionControl,
versionControlChoices,
} from '../../templates/addons/versionControl';
import { generateAwsTemplate } from '../../templates/aws';

type GeneralOptions = {
projectName: string;
versionControl?: 'github' | 'gitlab';
malparty marked this conversation as resolved.
Show resolved Hide resolved
provider: 'aws' | 'gcp' | 'heroku';
};

Expand Down Expand Up @@ -53,13 +58,19 @@ export default class Generator extends Command {
async run(): Promise<void> {
const { args } = await this.parse(Generator);

const providerPrompt = await prompt(providerChoices);
const generalPrompt = await prompt<GeneralOptions>([
...versionControlChoices,
...providerChoices,
]);
const generalOptions: GeneralOptions = {
projectName: args.projectName,
provider: providerPrompt.provider,
provider: generalPrompt.provider,
versionControl: generalPrompt.versionControl,
};

try {
this.applyCore(generalOptions);

switch (generalOptions.provider) {
case 'aws':
await generateAwsTemplate(generalOptions);
Expand All @@ -75,10 +86,15 @@ export default class Generator extends Command {

this.log('The infrastructure has been generated!');
} catch (error) {
remove('/', generalOptions.projectName);
console.error(error);
}
}

private applyCore(generalOptions: GeneralOptions): void {
applyVersionControl(generalOptions);
}

private async postProcess(generalOptions: GeneralOptions): Promise<void> {
try {
if (await detectTerraform()) {
Expand Down
64 changes: 64 additions & 0 deletions src/templates/addons/versionControl/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { applyVersionControl } from '.';
import { GeneralOptions } from '../../../commands/generate';
import { remove } from '../../../helpers/file';

describe('Version control add-on', () => {
describe('given valid GeneralOptions', () => {
describe('given github version control', () => {
const projectDir = 'version-control-github-addon-test';

beforeAll(() => {
const generalOptions: GeneralOptions = {
projectName: projectDir,
provider: 'aws',
versionControl: 'github',
};

applyVersionControl(generalOptions);
});

afterAll(() => {
jest.clearAllMocks();
remove('/', projectDir);
});

it('creates expected files', () => {
const expectedFiles = [
'.github/ISSUE_TEMPLATE/bug_template.md',
'.github/ISSUE_TEMPLATE/chore_template.md',
'.github/ISSUE_TEMPLATE/feature_template.md',
'.github/ISSUE_TEMPLATE/story_template.md',
'.github/PULL_REQUEST_TEMPLATE/release_template.md',
'.github/workflows/lint.yml',
'.github/PULL_REQUEST_TEMPLATE.md',
'.gitignore',
];

expect(projectDir).toHaveFiles(expectedFiles);
});
});

describe('given gitlab version control', () => {
const projectDir = 'version-control-gitlab-addon-test';

beforeAll(() => {
const generalOptions: GeneralOptions = {
projectName: projectDir,
provider: 'aws',
versionControl: 'gitlab',
};

applyVersionControl(generalOptions);
});

afterAll(() => {
jest.clearAllMocks();
remove('/', projectDir);
});

it('does NOT create any files', () => {
expect(projectDir).toBeEmpty();
});
});
});
});
Loading