Skip to content

Commit

Permalink
Merge branch 'v3' into feat-create-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
aorinevo authored Nov 2, 2024
2 parents 8924f71 + 930c65c commit 58b1e64
Show file tree
Hide file tree
Showing 20 changed files with 844 additions and 1,116 deletions.
103 changes: 103 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Contributing to Shepherd

Thank you for considering contributing to Shepherd! By contributing, you help improve the tool for everyone. Here are some guidelines to help you get started.

## Table of Contents

- [Code of Conduct](#code-of-conduct)
- [How to Contribute](#how-to-contribute)
- [Reporting Bugs](#reporting-bugs)
- [Suggesting Enhancements](#suggesting-enhancements)
- [Contributing Code](#contributing-code)
- [Development Setup](#development-setup)
- [Running e2e Tests](#running-e2e-tests)
- [Style Guide](#style-guide)
- [Pull Request Process](#pull-request-process)

## Code of Conduct

This project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to the project maintainers.

## How to Contribute

### Reporting Bugs

If you find a bug, please create an issue and include the following:

- Steps to reproduce the bug
- Expected behavior
- Actual behavior
- Screenshots or logs if applicable

### Suggesting Enhancements

Enhancements are welcome! To suggest an enhancement:

- Check if the enhancement is already reported by searching the issues.
- Open an issue and describe:
- The current state and the enhancement you suggest.
- Why you think this enhancement would be useful.

### Contributing Code

1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Make your changes.
4. Commit your changes (`git commit -m 'Add new feature'`).
5. Push to the branch (`git push origin feature-branch`).
6. Open a pull request.

## Development Setup

To set up the project for development:

1. Clone your forked repository:

```sh
git clone https://github.com/<your-username>/shepherd.git
cd shepherd
```

2. Install dependencies:

```sh
npm install
```

3. Run tests:
```sh
npm run test
```

To incrementally compile the source code while developing, run:
`sh
npm run build:watch
`

## Running e2e Tests

To ensure the robustness of your contributions, end-to-end (e2e) tests are crucial. Here's how to run e2e tests in the Shepherd project:

1. Run the e2e tests:
```sh
npm run e2e-test
```

This command builds the project and runs the e2e tests. Ensure all e2e tests pass before finalizing your pull request. If you add new features, consider adding corresponding e2e tests.

## Style Guide

Follow the code style defined by the project:

- Use [ESLint](https://eslint.org/) for linting. Run `npm run lint` to check for linting errors.
- Run `npm run fix-lint` to automatically fix linting issues.

## Pull Request Process

1. Ensure your changes pass all tests and lint checks.
2. Write a clear and descriptive title and description for your pull request.
3. Link to any relevant issues.
4. Wait for the maintainers to review your pull request. They may suggest changes.
5. Make requested changes and update the pull request.

Thank you for contributing to Shepherd!
49 changes: 8 additions & 41 deletions e2e/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,19 @@ Commands:
"
`;
exports[`CLI End-to-End Tests should successfully checkout using repos flag 1`] = `
"Using 2 selected repos
exports[`CLI End-to-End Tests should successfully run apply on a migration 1`] = `""`;
[aorinevo/shepherd-test-repo-1] 1/2
> Running should_migrate steps
✔ Completed all should_migrate steps successfully
> Running post_checkout steps
✔ Completed all post_checkout steps successfully
[aorinevo/shepherd-test-repo-2] 2/2
> Running should_migrate steps
✔ Completed all should_migrate steps successfully
> Running post_checkout steps
✔ Completed all post_checkout steps successfully
Checked out 2 out of 2 repos
"
`;
exports[`CLI End-to-End Tests should successfully run apply on a migration 1`] = `
"
[NerdWalletOSS/shepherd] 1/1
ℹ Running apply steps
$ touch $SHEPHERD_REPO_DIR/testfile.js && echo "some content" > $SHEPHERD_REPO_DIR/testfile.js
Step "touch $SHEPHERD_REPO_DIR/testfile.js && echo "some content" > $SHEPHERD_REPO_DIR/testfile.js" exited with 0
✔ Completed all apply steps successfully
"
`;
exports[`CLI End-to-End Tests should successfully run apply on a migration 2`] = `
"On branch 2024.10.06-test-migration
Untracked files:
(use "git add <file>..." to include in what will be committed)
testfile.js
exports[`CLI End-to-End Tests should successfully run checkout on a migration targeting a single repo 1`] = `
"Loading candidate repos
Loaded 1 repos
Checking out repos
nothing added to commit but untracked files present (use "git add" to track)
"
`;
exports[`CLI End-to-End Tests should successfully run checkout on a migration 1`] = `
"
[NerdWalletOSS/shepherd] 1/1
Checked out repo
> Running should_migrate steps
Completed all should_migrate steps successfully
Completed all should_migrate steps successfully
> Running post_checkout steps
Completed all post_checkout steps successfully
Completed all post_checkout steps successfully
Checked out 1 out of 1 repos
"
Expand Down
29 changes: 19 additions & 10 deletions e2e/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ describe('CLI End-to-End Tests', () => {
);
});

afterAll(() => {
const testMigrationDir = path.resolve(os.homedir(), '.shepherd', '2024.10.06-test-migration');
fs.rmSync(testMigrationDir, { recursive: true });
});

const cliPath = path.resolve(__dirname, '../lib/cli.js');

const runCLI = (args: string) => {
Expand All @@ -33,22 +38,26 @@ describe('CLI End-to-End Tests', () => {
expect(output.split('.').length).toEqual(3);
});

it('should successfully run checkout on a migration', async () => {
it('should successfully run checkout on a migration targeting a single repo', async () => {
const output = runCLI(`checkout ${path.join(__dirname, './assets/checkout-apply')}`);
expect(output).toMatchSnapshot();
});

it('should successfully run checkout on a migration targeting multiple repos', async () => {
const output = runCLI(
`checkout ${path.join(__dirname, './assets/checkout-apply')} --repos="aorinevo/shepherd-test-repo-1,aorinevo/shepherd-test-repo-2"`
);
expect(output).toContain('shepherd-test-repo-1');
expect(output).toContain('shepherd-test-repo-2');
});

it('should successfully run apply on a migration', async () => {
const output = runCLI(`apply ${path.join(__dirname, './assets/checkout-apply')}`);
expect(output).toMatchSnapshot();
const gitDiffOutput = execSync(`cd ${shepherdRepoDir} && git status`, { encoding: 'utf-8' });
expect(output).toContain('shepherd-test-repo-1');
expect(output).toContain('shepherd-test-repo-2');
expect(output).toContain('NerdWalletOSS/shepherd');
const repoDir = path.resolve(shepherdRepoDir, '../../aorinevo/shepherd-test-repo-1');
const gitDiffOutput = execSync(`cd ${repoDir} && git diff`, { encoding: 'utf-8' });
expect(gitDiffOutput).toMatchSnapshot();
});

it('should successfully checkout using repos flag', async () => {
const output = runCLI(
`checkout --repos "aorinevo/shepherd-test-repo-1,aorinevo/shepherd-test-repo-2" ${path.join(__dirname, './assets/checkout-apply')}`
);
expect(output).toMatchSnapshot();
});
});
16 changes: 7 additions & 9 deletions examples/eslintrc-yml/shepherd.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
id: 2018.08.15-eslintrc-yml
title: Rename all .eslintrc files to .eslintrc.yml
id: 2024.10.06-test-migration
title: |
feat: test migration
adapter:
type: github
search_query: repo:NerdWalletOSS/shepherd-demo path:/ filename:.eslintrc
search_query: repo:NerdWalletOSS/shepherd path:/
hooks:
should_migrate:
- ls .eslintrc
apply:
- mv .eslintrc .eslintrc.yml
pr_message:
- echo "Hey! This PR renames `.eslintrc` to `.eslintrc.yml`"
apply: 'touch $SHEPHERD_REPO_DIR/testfile.js && echo "some content" > $SHEPHERD_REPO_DIR/testfile.js'
pr_message: |
echo "e2e test suite"
Loading

0 comments on commit 58b1e64

Please sign in to comment.