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(GHA): workflow file creation onboarding #577

Merged
merged 87 commits into from
Sep 6, 2022

Conversation

kanadgupta
Copy link
Member

@kanadgupta kanadgupta commented Aug 22, 2022

🚥 Fix RM-5048

🧰 Changes

The Linear ticket has all the details on what we're trying to do here!

Must Haves:

  • GitHub Action Onboarding + Codegen ✏️
    • validate
    • openapi
    • docs (and friends1)
  • YAML file tests
    • validate
    • openapi
    • docs (and friends1)
  • E2E tests
    • validate
    • openapi
    • docs
  • Magical repo detection ✨
  • Better error handling for if user doesn't have .github/workflows directory created
  • Save a little boolean to the configstore when we ask if they'd like to set it up so we annoy them with too many asks
    • Major release matching (h/t @erunion for the idea)
  • Link out to GitHub's docs on adding repo secrets (that includes a little snippet of the API key)
    • And just an overall pass at all the language
  • Docs (to happen in a separate PR, ticketed in RM-5060)

Nice to haves:

Archive

🧬 QA & Testing

I've added a metric ton of tests for all of this, but I think once this is merged, we should play around with it in a beta release just to make sure it functions as expected.

If you'd like to play around with this work yourself, check out this branch and run the following commands:

# Install and set up the build
npm ci && npm run build

# You can use this command and select a valid file from the prompt, like ` __tests__/__fixtures__/petstore-simple-weird-version.json`
bin/rdme validate

# Alternatively, you can just pass the `github` flag which will run the GHA creation flow every time:
bin/rdme validate --github

# Alternatively, you can just pass the file directly into the command:
bin/rdme validate __tests__/__fixtures__/petstore-simple-weird-version.json

I used validate above since that one is the quickest to test (i.e. doesn't require auth), but you can also test any of the following commands as well:

  • openapi
  • docs
  • docs:single
  • changelogs
  • changelogs:single
  • custompages
  • custompages:single

If you follow the prompts, you'll end up with a brand-spankin'-new GitHub Actions workflow file that contains that command 🪄

Footnotes

  1. changelogs, custompages, etc... it's fairly easy to add new commands! I'll probably just write E2E tests for the docs command since the other ones are just super lightweight wrappers around the docs logic 2

  2. (this seems like it could be very prone to breakage... not gonna do it but I'll list it here for posterity)

doing this so we can preserve the `this` scope
after thinking about it some more, this doesn't feel necessary since we can just grab it from the current package. it also might cause issues if we create a broken workflow file due to breaking changes. instead we should add a dependabot config.
i like this way just in case the opts string is empty (which is unlikely but w/e)
not sure why these are failing 🤔
Tests were failing because we had defined our regex expressions globally
this will be a lot faster when writing tests for other suites
@kanadgupta kanadgupta marked this pull request as ready for review August 30, 2022 23:52
@kanadgupta kanadgupta added enhancement New feature or request command:docs Issues pertaining to the `docs`, `changelogs`, or `custompages` commands command:openapi Issues pertaining to the `openapi`, `validate`, `reduce`, or `swagger` commands command:categories Issues pertaining to the `categories` commands labels Aug 31, 2022
Copy link
Member

@erunion erunion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

giphy-1

__tests__/cmds/openapi/reduce.test.ts Show resolved Hide resolved
__tests__/lib/createGHA.test.ts Outdated Show resolved Hide resolved
__tests__/lib/createGHA.test.ts Outdated Show resolved Hide resolved
__tests__/lib/createGHA.test.ts Outdated Show resolved Hide resolved
src/cmds/changelogs/index.ts Outdated Show resolved Hide resolved
src/lib/createGHA/baseFile.ts Show resolved Hide resolved
@@ -12,6 +13,7 @@ export type Options = {
folder?: string;
};

@supportsGHA
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diffs in these files are way cleaner now @erunion :chefs-kiss:

Copy link
Member

@erunion erunion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this! Would love to encapsulate the getGithubArg stuff into the decorator at some point (because we can probably do a @authRequired one too) but I don't think it's worth the --help refactor it's going to require right now.

__tests__/cmds/docs/index.test.ts Outdated Show resolved Hide resolved
CmdClass: SingleCustomPageCommand,
opts: { key, filePath: './custompages/rdme.md' },
},
])('$cmd', ({ cmd, CmdClass, opts }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh neat I didn't know you could do $cmd like this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i also learned about this today 😌

also removed the unnecessary boolean return value since it's a void function
@kanadgupta kanadgupta merged commit 9ee808e into main Sep 6, 2022
@kanadgupta kanadgupta deleted the kanad/rm-5048-add-prompt-flow-to-cli-for-creating branch September 6, 2022 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command:categories Issues pertaining to the `categories` commands command:docs Issues pertaining to the `docs`, `changelogs`, or `custompages` commands command:openapi Issues pertaining to the `openapi`, `validate`, `reduce`, or `swagger` commands enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants