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: Add port number feature to build command #1346

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

plato79
Copy link

@plato79 plato79 commented Apr 14, 2024

Status

READY

Description

Added the port number to the build option for #1327

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • πŸ› οΈ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • βœ… Build configuration change
  • πŸ“ Documentation
  • πŸ—‘οΈ Chore

@plato79 plato79 requested a review from a team as a code owner April 14, 2024 22:50
@tomarra tomarra changed the title Added port number feature to build command feat: Add port number feature to build command Apr 15, 2024
@tomarra
Copy link
Contributor

tomarra commented Apr 15, 2024

Hi @plato79 πŸ‘‹thanks for taking on the issue and opening a PR! It looks like there are some failures in CI so please take a look at the output and get everything to green before we start the review process. Thanks!

vars was initialized with "var" though it should have been "final".
@plato79
Copy link
Author

plato79 commented Apr 15, 2024

The only "problem" was the initialization of "vars" variable which I didn't change. I fixed it as final. It should now pass ci analyze step. Though some of the tests fails and I don't think it's because of my additions.

@plato79
Copy link
Author

plato79 commented Apr 16, 2024

Now, it's past anlalyze.. Though there is an error in prod_server_builder test. This one is a bit complex though, while the fix is very easy.

The code below is the reason for the error.

prod_server_builder.dart:

    final vars = <String, dynamic>{
      'dartVersion': dartVersion,
      'port': port,
    };

    logger.detail('[codegen] running pre-gen...');
    await prodServerBundleGenerator.hooks.preGen(
      vars: vars,
      workingDirectory: workingDirectory.path,
      onVarsChanged: (v) => vars..addAll(v ?? {}),
    );

There is a vars variable which has default dartVersion which is "stable" and default port which is "8080". There is possibility additional variables are provided through mason. We add those to the current variables defined in vars we have here. It modifies the value if the same key is used so everything is alright.

...until no variables are sent to here. Which makes v null (it says it shouldn't happen but it happens). Why vhas null value I am not sure. I thought that code would execute only when there is a value in v but this is not the situation.

Now the fix is easy as you can see. Just adding a null check fixes. But this time flutter says I shouldn't add a null check to a variable which shouldn't be null at all. While the code above fixes the problem and causes no problem, it probably will pop up in the ci analyze section as error just like the previous `"vars" should be defined as final" warning appears as error in analyze.

Do you have any suggestion about this?

@plato79
Copy link
Author

plato79 commented Apr 16, 2024

Now, it's past anlalyze.. Though there is an error in prod_server_builder test. This one is a bit complex though, while the fix is very easy.

The code below is the reason for the error.

prod_server_builder.dart:

    final vars = <String, dynamic>{
      'dartVersion': dartVersion,
      'port': port,
    };

    logger.detail('[codegen] running pre-gen...');
    await prodServerBundleGenerator.hooks.preGen(
      vars: vars,
      workingDirectory: workingDirectory.path,
      onVarsChanged: (v) => vars..addAll(v ?? {}),
    );

There is a vars variable which has default dartVersion which is "stable" and default port which is "8080". There is possibility additional variables are provided through mason. We add those to the current variables defined in vars we have here. It modifies the value if the same key is used so everything is alright.

...until no variables are sent to here. Which makes v null (it says it shouldn't happen but it happens). Why vhas null value I am not sure. I thought that code would execute only when there is a value in v but this is not the situation.

Now the fix is easy as you can see. Just adding a null check fixes. But this time flutter says I shouldn't add a null check to a variable which shouldn't be null at all. While the code above fixes the problem and causes no problem, it probably will pop up in the ci analyze section as error just like the previous `"vars" should be defined as final" warning appears as error in analyze.

Do you have any suggestion about this?

Ok, that was not the cause. Still checking to see what the real problem here is.

…"vars"

When there are no "port" number defined in this test, it causes error. This fixes it.
@plato79
Copy link
Author

plato79 commented Apr 16, 2024

This last commit should fix the error in the test.

@plato79
Copy link
Author

plato79 commented Apr 17, 2024

The failing tests are actually runs successfully if you execute the commands outside of the test. For example build_test fails, but if you run dart run build/bin/server.dart in the temporary directory it created and call http://localhost:8080 it works. But the test itself cannot get a response from that page.

@tomarra Are you sure that these tests worked without problem before I made the change?

plato79 and others added 4 commits April 20, 2024 10:19
Set the port parameter to 8080 if it's not supplied. This fixes the problems with tests which don't provide port number.
@plato79
Copy link
Author

plato79 commented Apr 25, 2024

I think this is ready for merge. What do you think?

@alestiago
Copy link
Contributor

alestiago commented May 16, 2024

Hi @plato79! I've added this to the review column for the next iteration (May 18 to May 31). Hopefully we get to review it by then πŸ™Œ

@alestiago alestiago removed their assignment May 24, 2024
@tomarra
Copy link
Contributor

tomarra commented May 24, 2024

Hi @plato79 πŸ‘‹

I got this PR updated with main and we are still seeing failures in the CI pipeline. In looking more closely at the output it actually looks like there are changes that are needed on the Docker side of things. While the Dart code looks like it solves the need the Dockerfile needs to be updated to reflect the port change. Pretty sure this is why the tests are failing to establish a connection with the container to run the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants