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

fix(createGHA): git remote connection errors #705

Merged
merged 6 commits into from
Dec 7, 2022

Conversation

kanadgupta
Copy link
Member

@kanadgupta kanadgupta commented Dec 7, 2022

🚥 Fixes #704

🧰 Changes

Turns out we were missing some error handling in our git logic, which was leading to the errors like we're seeing in #704 (and maybe even #664):

fatal: unable to access 'https://XXXX.appsflyer.com/YYYYY/ZZZZZ.git/': Could not resolve host: XXXX.appsflyer.com

This is because the command git remote show <remote>1 errors out if unable to connect to the remote URL. Thankfully, the fix was a single .catch statement 😮‍💨

When in these files, I made a couple of other tiny touch-ups:

  • Split out our describe blocks in __tests__/lib/createGHA.test.ts, which weren't properly being separated due to certain describe block titles being the same when they shouldn't be.
  • Added a debug statement somewhere where it'd be helpful
  • Fixed up a stupid typo where I put a false in the wrong place, leading to an ugly stdout statement here:

CleanShot 2022-12-07 at 11 16 18@2x

when it should actually be this:

CleanShot 2022-12-07 at 11 33 40@2x

🧬 QA & Testing

You can reproduce this issue pretty easily by doing the following on the main branch:

# 1. install + build deps
npm ci

# 2. retrieves origin remote URL so you can use this later
git remote get-url origin

# 3. set the remote URL to some garbage
git remote set-url origin https://badremoteurl.git
# 4. run a command and note the error
$ bin/rdme openapi:validate __tests__/__fixtures__/petstore-simple-weird-version.json

fatal: unable to access 'https://badremoteurl.git/': Could not resolve host: badremoteurl.git
# 5. when you're done, set your origin remote URL back to what it was before
# it was https://github.com/readmeio/rdme.git but might be different for you
git remote set-url origin https://github.com/readmeio/rdme.git

If you run through steps 1-5 in this branch, you should see the following output in step 4 instead:

# 4. run a command and it succeeds as expected
$ bin/rdme openapi:validate __tests__/__fixtures__/petstore-simple-weird-version.json
__tests__/__fixtures__/petstore-simple-weird-version.json is a valid OpenAPI API definition!

If you see the same results and the tests + code look good, we should be good to go!

Footnotes

  1. this is almost always git remote show origin

Comment on lines -55 to +73
{ cmd: 'openapi:validate', CmdClass: OpenAPIValidateCommand, opts: { spec: 'petstore.json' } },
{ cmd: 'openapi', CmdClass: OpenAPICommand, opts: { key, spec: 'petstore.json', id: 'spec_id' } },
{ cmd: 'docs', CmdClass: DocsCommand, opts: { key, folder: './docs', version: '1.0.0' } },
{ cmd: 'docs', CmdClass: DocsCommand, opts: { key, filePath: './docs/rdme.md', version: '1.0.0' } },
{ cmd: 'changelogs', CmdClass: ChangelogsCommand, opts: { key, filePath: './changelogs' } },
{ cmd: 'changelogs', CmdClass: ChangelogsCommand, opts: { key, filePath: './changelogs/rdme.md' } },
{ cmd: 'custompages', CmdClass: CustomPagesCommand, opts: { key, filePath: './custompages' } },
{ cmd: 'openapi:validate', CmdClass: OpenAPIValidateCommand, opts: { spec: 'petstore.json' }, label: '' },
{ cmd: 'openapi', CmdClass: OpenAPICommand, opts: { key, spec: 'petstore.json', id: 'spec_id' }, label: '' },
{ cmd: 'docs', CmdClass: DocsCommand, opts: { key, folder: './docs', version: '1.0.0' }, label: '' },
{
cmd: 'docs',
CmdClass: DocsCommand,
label: ' (single)',
opts: { key, filePath: './docs/rdme.md', version: '1.0.0' },
},
{ cmd: 'changelogs', CmdClass: ChangelogsCommand, opts: { key, filePath: './changelogs' }, label: '' },
{
cmd: 'changelogs',
CmdClass: ChangelogsCommand,
label: ' (single)',
opts: { key, filePath: './changelogs/rdme.md' },
},
{ cmd: 'custompages', CmdClass: CustomPagesCommand, opts: { key, filePath: './custompages' }, label: '' },
Copy link
Member Author

Choose a reason for hiding this comment

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

This stuff just splits up the describe blocks, which were getting unwieldy since we consolidated the docs and docs:single commands.

@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`#createGHA command inputs changelogs should run GHA creation workflow and generate valid workflow file 1`] = `
exports[`#createGHA command inputs changelogs (single) should run GHA creation workflow and generate valid workflow file 1`] = `
Copy link
Member Author

Choose a reason for hiding this comment

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

These are just the resulting snapshot changes from splitting up the describe blocks above. No actual content changes here.

@@ -191,7 +210,7 @@ describe('#createGHA', () => {
delete process.env.TEST_RDME_NPM_SCRIPT;
});

it('should not run if repo only contains non-GitHub remotes', () => {
it('should not run if repo solely contains non-GitHub remotes', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed this so I don't have to see it when grepping the testbed for .only lol

@@ -186,7 +191,7 @@ export default async function createGHA(
if (msg) info(msg, false);

if (opts.github) {
info(chalk.bold("\n🚀 Let's get you set up with GitHub Actions! 🚀\n", false));
info(chalk.bold("\n🚀 Let's get you set up with GitHub Actions! 🚀\n"), false);
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm so mad about this lol. Look at the garbage it yields in production 😭
CleanShot 2022-12-07 at 11 16 18@2x

Copy link
Member

Choose a reason for hiding this comment

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

Might be worth changing the signature on info to have that includeEmojiPrefix option be supplied as an object instead to prevent this from happening again

Copy link
Member Author

Choose a reason for hiding this comment

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

done: 8be0062

@kanadgupta kanadgupta added bug Something isn't working GHA / CI Issues specific to GitHub Actions or other CI environments refactor Issues about tackling technical debt labels Dec 7, 2022
@kanadgupta kanadgupta changed the title Fix/remote error catch fix(createGHA): git remote connection errors Dec 7, 2022
@kanadgupta kanadgupta marked this pull request as ready for review December 7, 2022 16:31
@@ -186,7 +191,7 @@ export default async function createGHA(
if (msg) info(msg, false);

if (opts.github) {
info(chalk.bold("\n🚀 Let's get you set up with GitHub Actions! 🚀\n", false));
info(chalk.bold("\n🚀 Let's get you set up with GitHub Actions! 🚀\n"), false);
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth changing the signature on info to have that includeEmojiPrefix option be supplied as an object instead to prevent this from happening again

@kanadgupta kanadgupta merged commit 18f5468 into main Dec 7, 2022
@kanadgupta kanadgupta deleted the fix/remote-error-catch branch December 7, 2022 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working GHA / CI Issues specific to GitHub Actions or other CI environments refactor Issues about tackling technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rdme CLI requires connection to remote git repo
3 participants