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

Update PostAction with symbol parameters to cmd file arguments #1600

Closed
abhisheksaxena741 opened this issue Jul 3, 2018 · 12 comments
Closed
Labels
feature The issue defines new feature. Iteration:2023April size:2.0 triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Milestone

Comments

@abhisheksaxena741
Copy link

abhisheksaxena741 commented Jul 3, 2018

I need to pass symbols parameters to args when executing setup.cmd file using postActions property as below .template.config file.

Here, i am passing two symbols of type string jsonFileNamePath and myfilename as arguments to setup.cmd.

{
  "$schema": "http://json.schemastore.org/template",
  "identity": "SampleTemplate",
  "groupIdentity": "SampleTemplate",
  "author": "Abhishek",
  "classifications": ["api", "apiswagger"],
  "name": "Sample Template",
  "shortName": "SampleTemplate",
  "tags": {
    "language": "C#"
  },
  "sourceName": "SampleTemplate",
  "primaryOutputs": [
	{
		"path": "SampleTemplate.csproj"
	}
  ],
  "guids": [
    "98048C9C-BF28-46BA-A98E-63767EE5E3A8",
    "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
  ],
  "symbols": {
    "skipRestore": {
      "type": "parameter",
      "datatype": "bool",
      "description": "Skips the execution of 'dotnet restore' on project creation.",
      "defaultValue": "false"
    },
    "jsonFileNamePath": {
      "type": "parameter",
      "datatype": "string",
      "description": "Path of the json file ",
      "defaultValue": "myjson.json",
	  "isRequired" : "true"
    },
    "myfilename": {
      "type": "parameter",
      "datatype": "string",
      "description": "Name of the json file ",
      "defaultValue": "myjson",
	  "isRequired" : "true"
    }
  },
  "postActions": [
    {
      "condition": "(!skipRestore)",
      "description": "Restore NuGet packages required by this project.",
      "manualInstructions": [
        { "text": "Run 'dotnet restore'" }
      ],
      "actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
      "continueOnError": true
    },
	{
    "actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2",
    "args": {
      "executable": "setup.cmd",
      "args": "jsonFileNamePath myfilename"
    },
    "manualInstructions": [{ 
       "text": "Run 'setup.cmd jsonFileNamePath myfilename'" 
       }],
    "continueOnError": "false",
    "description ": "setups the project by calling setup.cmd"
  }
  ]
}
@mlorbetske
Copy link
Contributor

Currently, post-actions do not support accessing user input. As a workaround, you could change setup.cmd to contain the values you're currently passing (or generate another script that calls setup.cmd) - treating that file like normal template content

@mlorbetske
Copy link
Contributor

Closing this since there hasn't been any activity. Please let us know if this approach doesn't work for your use case.

@skoruba
Copy link

skoruba commented Aug 10, 2018

@mlorbetske I think, it will be very useful - be able to pass the symbols in postAction. I'd like to solve a similiar use case.

I want to run command like this:

{
      "actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2",
      "args": {
        "executable": "dotnet",
        "args": "run /seed --project src/(name).csproj"
      },
      "manualInstructions": [
        {
          "text": "Seeds the initial user database"
        }
      ],
      "continueOnError": false,
      "description ": "seeds the database"
    }

I need get the name of created csproj according user input.
Any idea how to achieve that?
Thx.

@mlorbetske
Copy link
Contributor

mlorbetske commented Aug 10, 2018

@skoruba currently, this would be achieved by including script files in your template content that execute the command you want (presumably you’d want both a .cmd file and a .sh file) that perform the action you’d like and call the script file from the post-action. The script file being subject to the operations set up in template.json, if it contains the original value of sourceName (and either sourceName has distinct value forms, or a derived symbol is used to capture the identity form), after creation it would contain the name the user had chosen.

@abhisheksaxena741
Copy link
Author

Thanks all for the suggestions, however we were expecting some straight forward approach. I hope we can suggest this type of requirements as Enhancement feature.

@mlorbetske
Copy link
Contributor

A post-action rework with access to parameters & such has been on our radar for a while now, the responses here were intended to help enable this sort of functionality in the short run. I’ll re-open this to make sure we track this scenario.

@mlorbetske mlorbetske reopened this Sep 12, 2018
@donJoseLuis
Copy link
Contributor

  1. Adding item to specific project corresponding to a targeted delivery area
  2. Once this has been done for the entire backlog, the next steps will be to prioritize within each project & output a delivery roadmap.
  3. At that point, the issues will be assigned to a corresponding milestone
  4. The team will then begin to deliver against the road map, contributions always welcome

@donJoseLuis donJoseLuis added triaged The issue was evaluated by the triage team, placed on correct area, next action defined. needsprioritization labels Mar 19, 2020
@donJoseLuis donJoseLuis changed the title Pass symbol parameters to arguments of cmd file Update PostAction with symbol parameters to cmd file arguments Mar 24, 2020
@wazzamatazz
Copy link

Just to add another use case: the previous suggested workaround of using a symbol replacement in the script file itself isn't always viable, because the action might be e.g. to encrypt and/or store sensitive information such as a client secret somewhere.

@donJoseLuis
Copy link
Contributor

@wazzamatazz , thanks for the additional details. We are currently updating documents (working through that particular backlog). We can then move on to the "Template authoring" backlog, relevant to this issue. Please stay tuned.

@vlada-shubina vlada-shubina added the feature The issue defines new feature. label Sep 28, 2020
@bekir-ozturk bekir-ozturk added this to the Backlog milestone Mar 17, 2021
@bekir-ozturk bekir-ozturk modified the milestones: Backlog, July Sprint May 25, 2021
@vlada-shubina vlada-shubina modified the milestones: July Sprint, Backlog Jun 30, 2021
@brunoamancio
Copy link

Reported in July 2018, nothing done in October 2021.

@vlada-shubina
Copy link
Member

This can be also helpful for other post actions:

  • add the reference to existing project specified via parameter
  • add the project to existing solution specified via parameter

@vlada-shubina
Copy link
Member

The issue was resolved in #6312.
Note: template author needs to opt-in to use this behavior by using applyFileRenamesToArgs and applyFileRenamesToManualInstructions properties in post-action definition. The replacements are based on fileRename for symbols and sourceName file renames and not applied automatically unless argument is mentioned in applyFileRenamesToArgs.

See more details in https://github.com/dotnet/templating/blob/main/docs/Post-Action-Registry.md#base-configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature The issue defines new feature. Iteration:2023April size:2.0 triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Projects
None yet
Development

No branches or pull requests

9 participants