Skip to content

Conversation

aishwaryabh
Copy link
Contributor

@aishwaryabh aishwaryabh commented Aug 12, 2025

Issue describing the changes in this PR

resolves#4593

This issue allows users to run func pack when they want to create a zip file that they can use the azure CLI to deploy. The general syntax of the command is as follows:

func pack [path of folder to pack] [language specific options] [--no-build] [--output]

When the user runs func --help the following is displayed:
image

Note that func pack will NOT be displayed when the user does func --help until we clean up the CLI and add all the validations for each command when running func pack. This will be done in a future PR

This PR adds the applicable E2E tests for the different scenarios and for each language worker runtime as well.

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • I have added all required tests (Unit tests, E2E tests)

@aishwaryabh aishwaryabh marked this pull request as ready for review August 19, 2025 00:27
@aishwaryabh aishwaryabh requested a review from a team as a code owner August 19, 2025 00:27
@aishwaryabh aishwaryabh force-pushed the aibhandari/refactor-func-pack branch from 7aa5ae6 to 0a7f737 Compare August 19, 2025 00:45
@aishwaryabh aishwaryabh force-pushed the aibhandari/refactor-func-pack branch from f0aba02 to 6b7ed31 Compare August 22, 2025 16:51
@aishwaryabh aishwaryabh force-pushed the aibhandari/refactor-func-pack branch from 0761d80 to 377294c Compare August 29, 2025 15:32
@@ -1,10 +1,9 @@
# Azure Functions CLI 4.2.2
# Azure Functions CLI 4.2.3
Copy link
Member

Choose a reason for hiding this comment

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

I think new feature = minor

{
if (refreshSecrets)
Copy link
Member

Choose a reason for hiding this comment

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

What does refresh secrets have to do with func pack? Does this need to be in this PR?

Copy link
Contributor Author

@aishwaryabh aishwaryabh Aug 29, 2025

Choose a reason for hiding this comment

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

So in the secret manager, the appsettings are lazy loaded. This works for most scenarios, but it doesn't work for func pack if the user inputs a directory that they are trying to pack, since the worker runtime is determined by this Init action which is called in ConsoleApp. We could switch directories directly before running this action, but the problem is that we still need to store what the value of the current directory is (in case the user doesn't have an ouput directory where they want the zip file to be located). I also don't think it made sense to have a hardcoded scenario for only if it's func pack, switch directories. Does that make sense?

Copy link
Contributor Author

@aishwaryabh aishwaryabh Aug 29, 2025

Choose a reason for hiding this comment

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

I know that we eventually want to allow all commands to have func <command> <folder path> but I thought this was a bit out of the scope of the PR to modify the Init action to account for this for all of the commands (since we only want this to happen for func pack), so I decided to have this as a workaround.

Comment on lines +35 to +36
"When enabled, Core Tools starts a Docker container, builds the app inside that container," +
" and creates a ZIP file with all dependencies restored in .python_packages.")
Copy link
Member

Choose a reason for hiding this comment

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

nit: indent desc strings

Suggested change
"When enabled, Core Tools starts a Docker container, builds the app inside that container," +
" and creates a ZIP file with all dependencies restored in .python_packages.")
"When enabled, Core Tools starts a Docker container, builds the app inside that container," +
" and creates a ZIP file with all dependencies restored in .python_packages.")


namespace Azure.Functions.Cli.Actions.LocalActions.PackAction
{
[Action(Name = "pack powershell", ParentCommandName = "pack", ShowInHelp = false, HelpText = "Arguments specific to PowerShell apps when running func pack")]
Copy link
Member

Choose a reason for hiding this comment

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

Is this false because there are no custom pwsh args right now? Can we add a comment that mentions that

Parser
.Setup<bool>("no-build")
.WithDescription("Do not build the project before packaging. Optionally provide a directory when func pack as the first argument that has the build contents." +
"Otherwise, default is the current directory.")
Copy link
Member

Choose a reason for hiding this comment

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

If a line is connected to the one above, you should indent to make that clear

Suggested change
"Otherwise, default is the current directory.")
"Otherwise, default is the current directory.")

NoBuild = NoBuild
};

var oldCurrentDirectory = Environment.CurrentDirectory;
Copy link
Member

Choose a reason for hiding this comment

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

originalCurrentDirectory ?

EnsureNpmExists();

// Change to the function app directory for npm operations
var previousDirectory = Environment.CurrentDirectory;
Copy link
Member

Choose a reason for hiding this comment

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

Let's be consistent across all the commands on what we're calling this


if (string.IsNullOrEmpty(options.FolderPath))
{
ColoredConsole.WriteLine(WarningColor("No folder path specified. Using current directory as build output directory."));
Copy link
Member

Choose a reason for hiding this comment

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

For this, can we do more than just defaulting to current? This is probably a good place to check for .props etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oo yes that's valid. I can add this scenario

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

Successfully merging this pull request may close these issues.

4 participants