Ejemplo n.º 1
0
        private GitHubActions.Step CreateArchiveFilesStep(AzurePipelines.Step step)
        {
            //coming from:
            //- task: ArchiveFiles@2
            //  displayName: 'Archive files'
            //  inputs:
            //    rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output'
            //    includeRootFolder: false
            //    archiveType: zip
            //    archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
            //    replaceExistingArchive: true

            //Going to: //https://github.com/marketplace/actions/create-zip-file
            //- uses: montudor/[email protected]
            //  with:
            //    args: zip -qq -r ./dir.zip ./dir

            string rootFolderOrFile = GetStepInput(step, "rootFolderOrFile");
            string archiveFile      = GetStepInput(step, "archiveFile");

            string zipCommand = "zip -qq -r " + archiveFile + " " + rootFolderOrFile;

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                uses = "montudor/[email protected]",
                with = new Dictionary <string, string>
                {
                    { "args", zipCommand }
                },
                step_message = "Note: This is a third party action: https://github.com/marketplace/actions/create-zip-file"
            };

            return(gitHubStep);
        }
Ejemplo n.º 2
0
        private GitHubActions.Step CreateAntStep(AzurePipelines.Step step)
        {
            //coming from:
            //- task: Ant@1
            //  inputs:
            //    workingDirectory: ''
            //    buildFile: 'build.xml'
            //    javaHomeOption: 'JDKVersion'
            //    jdkVersionOption: '1.8'
            //    jdkArchitectureOption: 'x64'
            //    publishJUnitResults: true
            //    testResultsFiles: '**/TEST-*.xml'

            //Going to:
            //- name: Build with Ant
            //  run: ant -noinput -buildfile build.xml

            string buildFile = GetStepInput(step, "buildFile");

            string antCommand = "ant -noinput -buildfile " + buildFile;

            step.script = antCommand;

            GitHubActions.Step gitHubStep = CreateScriptStep("", step);

            return(gitHubStep);
        }
Ejemplo n.º 3
0
        private GitHubActions.Step CreateUseRubyStep(AzurePipelines.Step step)
        {
            //coming from:
            //# Use Ruby version: Use the specified version of Ruby from the tool cache, optionally adding it to the PATH
            //- task: UseRubyVersion@0
            //  inputs:
            //    #versionSpec: '>= 2.4'
            //    #addToPath: true # Optional

            //Going to:
            //- uses: actions/setup-ruby@v1
            //  with:
            //    ruby-version: 2.6.x


            string version = GetStepInput(step, "versionSpec");

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                name = "Setup Ruby " + version,
                uses = "actions/setup-ruby@v1",
                with = new Dictionary <string, string>
                {
                    { "ruby-version", version }
                }
            };


            return(gitHubStep);
        }
Ejemplo n.º 4
0
        private GitHubActions.Step CreateDotNetCommandStep(AzurePipelines.Step step)
        {
            string runScript = "dotnet ";

            if (step.inputs.ContainsKey("command") == true)
            {
                runScript += GetStepInput(step, "command") + " ";
            }
            if (step.inputs.ContainsKey("projects") == true)
            {
                runScript += GetStepInput(step, "projects") + " ";
            }
            if (step.inputs.ContainsKey("arguments") == true)
            {
                runScript += GetStepInput(step, "arguments") + " ";
            }
            //Remove the new line characters
            runScript = runScript.Replace("\n", "");
            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                run = runScript
            };

            return(gitHubStep);
        }
Ejemplo n.º 5
0
        private GitHubActions.Step CreateDockerStep(AzurePipelines.Step step)
        {
            //From: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/docker?view=azure-devops
            //- task: Docker@2
            //  displayName: Build
            //  inputs:
            //    command: build
            //    repository: contosoRepository
            //    dockerfile: MyDockerFile
            //    containerRegistry: dockerRegistryServiceConnection
            //    tags: tag1
            //    arguments: --secret id=mysecret,src=mysecret.txt

            //To: https://github.com/marketplace/actions/docker-build-push
            //- name: Build the Docker image
            //  run: docker build . --file MyDockerFile --tag my-image-name:$(date +%s)


            string tags       = GetStepInput(step, "tags");
            string dockerFile = GetStepInput(step, "dockerfile");
            string arguments  = GetStepInput(step, "arguments");

            //Very very simple. Needs more branches and logic
            string dockerScript = "docker build . --file " + dockerFile + " --tag " + tags + " " + arguments;

            step.script = dockerScript;
            GitHubActions.Step gitHubStep = CreateScriptStep("", step);
            return(gitHubStep);
        }
Ejemplo n.º 6
0
        private GitHubActions.Step CreateDownloadBuildArtifacts(AzurePipelines.Step step)
        {
            string artifactName = GetStepInput(step, "artifactname");

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                uses = "actions/[email protected]",
                with = new Dictionary <string, string>
                {
                    { "name", artifactName }
                }
            };

            //From:
            //- task: DownloadBuildArtifacts@0
            //  displayName: 'Download the build artifacts'
            //  inputs:
            //    buildType: 'current'
            //    downloadType: 'single'
            //    artifactName: 'drop'
            //    downloadPath: '$(build.artifactstagingdirectory)'

            //To:
            //- name: Download serviceapp artifact
            //  uses: actions/[email protected]
            //  with:
            //    name: serviceapp
            return(gitHubStep);
        }
Ejemplo n.º 7
0
        private GitHubActions.Step CreateXamariniOSStep(AzurePipelines.Step step)
        {
            //coming from:
            //- task: XamariniOS@2
            //  inputs:
            //    solutionFile: '**/*.sln'
            //    configuration: 'Release'
            //    buildForSimulator: true
            //    packageApp: false

            //Going to: https://levelup.gitconnected.com/using-github-actions-with-ios-and-android-xamarin-apps-693a93b48a61
            //- name: iOS
            //  run: |
            //    cd Blank
            //    nuget restore
            //    msbuild Blank.iOS/Blank.iOS.csproj /verbosity:normal /t:Rebuild /p:Platform=iPhoneSimulator /p:Configuration=Debug

            string projectFile   = GetStepInput(step, "projectFile");
            string configuration = GetStepInput(step, "configuration");

            string script = "" +
                            "cd Blank\n" +
                            "nuget restore\n" +
                            "cd Blank.Android\n" +
                            "msbuild " + projectFile + " /verbosity:normal /t:Rebuild /p:Platform=iPhoneSimulator /p:Configuration=" + configuration;

            step.script = script;

            GitHubActions.Step gitHubStep = CreateScriptStep("", step);

            return(gitHubStep);
        }
Ejemplo n.º 8
0
        private GitHubActions.Step CreateXamarinAndroidStep(AzurePipelines.Step step)
        {
            //coming from:
            //- task: XamarinAndroid@1
            //  inputs:
            //    projectFile: '**/*droid*.csproj'
            //    outputDirectory: '$(outputDirectory)'
            //    configuration: '$(buildConfiguration)'

            //Going to: https://levelup.gitconnected.com/using-github-actions-with-ios-and-android-xamarin-apps-693a93b48a61
            //- name: Android
            //  run: |
            //    cd Blank
            //    nuget restore
            //    cd Blank.Android
            //    msbuild '**/*droid*.csproj' /verbosity:normal /t:Rebuild /p:Configuration='$(buildConfiguration)'

            string projectFile   = GetStepInput(step, "projectFile");
            string configuration = GetStepInput(step, "configuration");

            string script = "" +
                            "cd Blank\n" +
                            "nuget restore\n" +
                            "cd Blank.Android\n" +
                            "msbuild " + projectFile + " /verbosity:normal /t:Rebuild /p:Configuration=" + configuration;

            step.script = script;

            GitHubActions.Step gitHubStep = CreateScriptStep("", step);

            return(gitHubStep);
        }
Ejemplo n.º 9
0
        private GitHubActions.Step CreateMavenStep(AzurePipelines.Step step)
        {
            //coming from:
            //- task: Maven@3
            //  inputs:
            //    mavenPomFile: 'Maven/pom.xml'
            //    mavenOptions: '-Xmx3072m'
            //    javaHomeOption: 'JDKVersion'
            //    jdkVersionOption: '1.8'
            //    jdkArchitectureOption: 'x64'
            //    publishJUnitResults: true
            //    testResultsFiles: '**/surefire-reports/TEST-*.xml'
            //    goals: 'package'

            //Going to:
            //- name: Build with Maven
            //  run: mvn -B package --file pom.xml

            string pomFile = GetStepInput(step, "mavenPomFile");

            string pomCommand = "mvn -B package --file " + pomFile;

            step.script = pomCommand;

            GitHubActions.Step gitHubStep = CreateScriptStep("", step);

            return(gitHubStep);
        }
Ejemplo n.º 10
0
        private GitHubActions.Step CreateUsePythonStep(AzurePipelines.Step step)
        {
            //coming from:
            //- task: UsePythonVersion@0
            //  inputs:
            //    versionSpec: '3.7'
            //    addToPath: true
            //    architecture: 'x64'

            //Going to:
            //- name: Setup Python 3.7
            //  uses: actions/setup-python@v1
            //  with:
            //    python-version: '3.7'

            string version = GetStepInput(step, "versionSpec");

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                name = "Setup Python " + version,
                uses = "actions/setup-python@v1",
                with = new Dictionary <string, string>
                {
                    { "python-version", version }
                }
            };


            return(gitHubStep);
        }
Ejemplo n.º 11
0
        private GitHubActions.Step CreateNodeToolStep(AzurePipelines.Step step)
        {
            //coming from:
            //- task: NodeTool@0
            //  inputs:
            //    versionSpec: '10.x'
            //  displayName: 'Install Node.js'

            //Going to:
            //- name: Use Node.js 10.x
            //  uses: actions/setup-node@v1
            //  with:
            //    node-version: 10.x

            string version = GetStepInput(step, "versionSpec");

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                name = "Use Node.js " + version,
                uses = "actions/setup-node@v1",
                with = new Dictionary <string, string>
                {
                    { "node-version", version }
                }
            };

            return(gitHubStep);
        }
Ejemplo n.º 12
0
        private GitHubActions.Step CreateNuGetCommandStep(AzurePipelines.Step step)
        {
            string command = GetStepInput(step, "command");

            if (string.IsNullOrEmpty(command) == false)
            {
                command = "restore";
            }
            string restoresolution = GetStepInput(step, "restoresolution");

            GitHubActions.Step gitHubStep = CreateScriptStep("powershell", step);
            gitHubStep.run = "nuget " + command + " " + restoresolution;

            //coming from:
            //# NuGet
            //# Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
            //- task: NuGetCommand@2
            //  inputs:
            //    #command: 'restore' # Options: restore, pack, push, custom
            //    #restoreSolution: '**/*.sln' # Required when command == Restore
            //    #feedsToUse: 'select' # Options: select, config
            //    #vstsFeed: # Required when feedsToUse == Select
            //    #includeNuGetOrg: true # Required when feedsToUse == Select
            //    #nugetConfigPath: # Required when feedsToUse == Config
            //    #externalFeedCredentials: # Optional
            //    #noCache: false
            //    #disableParallelProcessing: false
            //    restoreDirectory:
            //    #verbosityRestore: 'Detailed' # Options: quiet, normal, detailed
            //    #packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' # Required when command == Push
            //    #nuGetFeedType: 'internal' # Required when command == Push# Options: internal, external
            //    #publishVstsFeed: # Required when command == Push && NuGetFeedType == Internal
            //    #publishPackageMetadata: true # Optional
            //    #allowPackageConflicts: # Optional
            //    #publishFeedCredentials: # Required when command == Push && NuGetFeedType == External
            //    #verbosityPush: 'Detailed' # Options: quiet, normal, detailed
            //    #packagesToPack: '**/*.csproj' # Required when command == Pack
            //    #configuration: '$(BuildConfiguration)' # Optional
            //    #packDestination: '$(Build.ArtifactStagingDirectory)' # Optional
            //    #versioningScheme: 'off' # Options: off, byPrereleaseNumber, byEnvVar, byBuildNumber
            //    #includeReferencedProjects: false # Optional
            //    #versionEnvVar: # Required when versioningScheme == ByEnvVar
            //    #majorVersion: '1' # Required when versioningScheme == ByPrereleaseNumber
            //    #minorVersion: '0' # Required when versioningScheme == ByPrereleaseNumber
            //    #patchVersion: '0' # Required when versioningScheme == ByPrereleaseNumber
            //    #packTimezone: 'utc' # Required when versioningScheme == ByPrereleaseNumber# Options: utc, local
            //    #includeSymbols: false # Optional
            //    #toolPackage: # Optional
            //    #buildProperties: # Optional
            //    #basePath: # Optional, specify path to nuspec files
            //    #verbosityPack: 'Detailed' # Options: quiet, normal, detailed
            //    #arguments: # Required when command == Custom

            //Going to:
            //- name: Nuget Push
            //  run: nuget push *.nupkg

            return(gitHubStep);
        }
Ejemplo n.º 13
0
        private GitHubActions.Step CreateCopyFilesStep(AzurePipelines.Step step)
        {
            //Use PowerShell to copy files
            step.script = "Copy '" + GetStepInput(step, "sourcefolder") + "/" + GetStepInput(step, "contents") + "' '" + GetStepInput(step, "targetfolder") + "'";

            GitHubActions.Step gitHubStep = CreateScriptStep("powershell", step);
            return(gitHubStep);
        }
Ejemplo n.º 14
0
        private GitHubActions.Step CreateAzureWebAppDeploymentStep(AzurePipelines.Step step)
        {
            string webappName = GetStepInput(step, "webappname");
            string appName    = GetStepInput(step, "appName");
            string package    = GetStepInput(step, "package");
            string slotName   = GetStepInput(step, "slotname");
            string imageName  = GetStepInput(step, "imageName");

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                uses = "Azure/webapps-deploy@v2",
                with = new Dictionary <string, string>()
            };

            if (webappName != null)
            {
                gitHubStep.with.Add("app-name", webappName);
            }
            else if (appName != null)
            {
                gitHubStep.with.Add("app-name", appName);
            }
            if (package != null)
            {
                gitHubStep.with.Add("package", package);
            }
            if (slotName != null)
            {
                gitHubStep.with.Add("slot-name", slotName);
            }
            if (imageName != null)
            {
                gitHubStep.with.Add("images", imageName);
            }

            //coming from:
            //- task: AzureRmWebAppDeployment@3
            //  displayName: 'Azure App Service Deploy: web service'
            //  inputs:
            //    azureSubscription: 'connection to Azure Portal'
            //    WebAppName: $(WebServiceName)
            //    DeployToSlotFlag: true
            //    ResourceGroupName: $(ResourceGroupName)
            //    SlotName: 'staging'
            //    Package: '$(build.artifactstagingdirectory)/drop/MyProject.Service.zip'
            //    TakeAppOfflineFlag: true
            //    JSONFiles: '**/appsettings.json'

            //Going to:
            //- name: Deploy web service to Azure WebApp
            //  uses: Azure/webapps-deploy@v1
            //  with:
            //    app-name: myproject-service
            //    package: serviceapp
            //    slot-name: staging

            return(gitHubStep);
        }
Ejemplo n.º 15
0
        public GitHubActions.Step CreateMSBuildSetupStep()
        {
            //To:
            //- name: Setup MSBuild.exe
            //  uses: microsoft/[email protected]

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                uses = "microsoft/[email protected]"
            };

            return(gitHubStep);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Convert a single Azure DevOps Pipeline task to a GitHub Actions task
        /// </summary>
        /// <param name="input">Yaml to convert</param>
        /// <returns>Converion object, with original yaml, processed yaml, and comments on the conversion</returns>
        public ConversionResponse ConvertAzurePipelineTaskToGitHubActionTask(string input)
        {
            string yaml           = "";
            string processedInput = ConversionUtility.StepsPreProcessing(input);

            GitHubActions.Step gitHubActionStep = new GitHubActions.Step();

            //Process the YAML for the individual job
            AzurePipelines.Job azurePipelinesJob = GenericObjectSerialization.DeserializeYaml <AzurePipelines.Job>(processedInput);
            if (azurePipelinesJob != null && azurePipelinesJob.steps != null && azurePipelinesJob.steps.Length > 0)
            {
                //As we needed to create an entire (but minimal) pipelines job, we need to now extract the step for processing
                StepsProcessing stepsProcessing = new StepsProcessing();
                gitHubActionStep = stepsProcessing.ProcessStep(azurePipelinesJob.steps[0]);

                //Find all variables in this text block, we need this for a bit later
                VariablesProcessing vp           = new VariablesProcessing(_verbose);
                List <string>       variableList = vp.SearchForVariables(processedInput);

                //Create the GitHub YAML and apply some adjustments
                if (gitHubActionStep != null)
                {
                    //add the step into a github job so it renders correctly
                    GitHubActions.Job gitHubJob = new GitHubActions.Job
                    {
                        steps = new GitHubActions.Step[1] //create an array of size 1
                    };
                    //Load the step into the single item array
                    gitHubJob.steps[0] = gitHubActionStep;

                    //Finally, we can serialize the job back to yaml
                    yaml = GitHubActionsSerialization.SerializeJob(gitHubJob, variableList);
                }
            }

            //Load failed tasks and comments for processing
            List <string> allComments = new List <string>();

            if (gitHubActionStep != null)
            {
                allComments.Add(gitHubActionStep.step_message);
            }

            //Return the final conversion result, with the original (pipeline) yaml, processed (actions) yaml, and any comments
            return(new ConversionResponse
            {
                pipelinesYaml = input,
                actionsYaml = yaml,
                comments = allComments
            });
        }
Ejemplo n.º 17
0
        private GitHubActions.Step CreateMSBuildStep(AzurePipelines.Step step)
        {
            //coming from:
            //# Visual Studio build
            //# Build with MSBuild and set the Visual Studio version property
            //- task: VSBuild@1
            //  inputs:
            //    solution: 'MySolution.sln'
            //    vsVersion: 'latest' # Optional. Options: latest, 16.0, 15.0, 14.0, 12.0, 11.0
            //    msbuildArgs: # Optional
            //    platform: # Optional
            //    configuration: # Optional
            //    clean: false # Optional
            //    maximumCpuCount: false # Optional
            //    restoreNugetPackages: false # Optional
            //    msbuildArchitecture: 'x86' # Optional. Options: x86, x64
            //    logProjectEvents: true # Optional
            //    createLogFile: false # Optional
            //    logFileVerbosity: 'normal' # Optional. Options: quiet, minimal, normal, detailed, diagnostic

            //Going to:
            //- run: msbuild MySolution.sln /p:configuration=release

            string solution      = GetStepInput(step, "solution");
            string platform      = GetStepInput(step, "platform");
            string configuration = GetStepInput(step, "configuration");
            string msbuildArgs   = GetStepInput(step, "msbuildArgs");
            string run           = "msbuild '" + solution + "'";

            if (configuration != null)
            {
                run += " /p:configuration='" + configuration + "'";
            }
            if (platform != null)
            {
                run += " /p:platform='" + platform + "'";
            }
            if (msbuildArgs != null)
            {
                run += " " + msbuildArgs;
            }
            step.script = run;

            //To script
            GitHubActions.Step gitHubStep = CreateScriptStep("", step);
            gitHubStep.run = run;

            return(gitHubStep);
        }
Ejemplo n.º 18
0
        public GitHubActions.Step CreateSetupGradleStep()
        {
            //Going to:
            //- name: Grant execute permission for gradlew
            //  run: chmod +x gradlew

            AzurePipelines.Step step = new Step
            {
                name   = "Grant execute permission for gradlew",
                script = "chmod +x gradlew"
            };
            GitHubActions.Step gitHubStep = CreateScriptStep("", step);

            return(gitHubStep);
        }
Ejemplo n.º 19
0
        private GitHubActions.Step CreateAzureAppServiceManageStep(AzurePipelines.Step step)
        {
            //https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-app-service-manage?view=azure-devops
            //coming from:
            //- task: AzureAppServiceManage@0
            //displayName: 'Swap Slots: web service'
            //inputs:
            //  azureSubscription: 'connection to Azure Portal'
            //  WebAppName: $(WebServiceName)
            //  ResourceGroupName: $(ResourceGroupName)
            //  SourceSlot: 'staging'

            //Going to:
            //- name: Swap web service staging slot to production
            //  uses: Azure/[email protected]
            //  with:
            //    inlineScript: az webapp deployment slot swap --resource-group MyProjectRG --name featureflags-data-eu-service --slot staging --target-slot production


            string resourceGroup = GetStepInput(step, "resourcegroupname");
            string webAppName    = GetStepInput(step, "webappname");
            string sourceSlot    = GetStepInput(step, "sourceslot");
            string targetSlot    = GetStepInput(step, "targetslot");

            if (string.IsNullOrEmpty(targetSlot) == true)
            {
                targetSlot = "production";
            }
            //TODO: Add other properties for az webapp deployment

            string script = "az webapp deployment slot swap --resource-group " + resourceGroup +
                            " --name " + webAppName +
                            " --slot " + sourceSlot +
                            " --target-slot " + targetSlot + "";

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                uses = "Azure/[email protected]",
                with = new Dictionary <string, string>
                {
                    { "inlineScript", script }
                }
            };

            return(gitHubStep);
        }
Ejemplo n.º 20
0
        public GitHubActions.Step CreateSetupJavaStep(string javaVersion)
        {
            if (javaVersion == null)
            {
                return(null);
            }
            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                name = "Setup JDK " + javaVersion,
                uses = "actions/setup-java@v1",
                with = new Dictionary <string, string>
                {
                    { "java-version", javaVersion }
                }
            };

            return(gitHubStep);
        }
Ejemplo n.º 21
0
        private GitHubActions.Step CreateScriptStep(string shellType, AzurePipelines.Step step)
        {
            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                run   = step.script,
                shell = shellType
            };

            if (gitHubStep.run == null)
            {
                if (step.powershell != null)
                {
                    gitHubStep.run = step.powershell;
                }
                else if (step.pwsh != null)
                {
                    gitHubStep.run = step.pwsh;
                }
                else if (step.bash != null)
                {
                    gitHubStep.run = step.bash;
                }
                else
                {
                    if (step.inputs != null)
                    {
                        string runValue = GetStepInput(step, "script");
                        gitHubStep.run = runValue;
                    }
                }
            }
            if (gitHubStep.shell == "")
            {
                gitHubStep.shell = null;
            }
            if (step.condition != null)
            {
                gitHubStep._if = ConditionsProcessing.TranslateConditions(step.condition);
            }

            return(gitHubStep);
        }
Ejemplo n.º 22
0
        private GitHubActions.Step CreateAzureManageResourcesStep(AzurePipelines.Step step)
        {
            string resourceGroup             = GetStepInput(step, "resourcegroupname");
            string armTemplateFile           = GetStepInput(step, "csmfile");
            string armTemplateParametersFile = GetStepInput(step, "csmparametersfile");

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                uses = "Azure/github-actions/arm@master",
                env  = new Dictionary <string, string>
                {
                    { "AZURE_RESOURCE_GROUP", resourceGroup },
                    { "AZURE_TEMPLATE_LOCATION", armTemplateFile },
                    { "AZURE_TEMPLATE_PARAM_FILE", armTemplateParametersFile },
                }
            };

            //coming from:
            //- task: AzureResourceGroupDeployment@2
            //  displayName: 'Deploy ARM Template to resource group'
            //  inputs:
            //    azureSubscription: 'connection to Azure Portal'
            //    resourceGroupName: $(ResourceGroupName)
            //    location: '[resourceGroup().location]'
            //    csmFile: '$(build.artifactstagingdirectory)/drop/ARMTemplates/azuredeploy.json'
            //    csmParametersFile: '$(build.artifactstagingdirectory)/drop/ARMTemplates/azuredeploy.parameters.json'
            //    overrideParameters: '-environment $(AppSettings.Environment) -locationShort $(ArmTemplateResourceGroupLocation)'

            //Going to:
            //https://github.com/Azure/github-actions/tree/master/arm
            //action "Manage Azure Resources" {
            //  uses = "Azure/github-actions/arm@master"
            //  env = {
            //    AZURE_RESOURCE_GROUP = "<Resource Group Name"
            //    AZURE_TEMPLATE_LOCATION = "<URL or Relative path in your repository>"
            //    AZURE_TEMPLATE_PARAM_FILE = "<URL or Relative path in your repository>"
            //  }
            //  needs = ["Azure Login"]
            //}}

            return(gitHubStep);
        }
Ejemplo n.º 23
0
        private GitHubActions.Step CreatePythonStep(AzurePipelines.Step step)
        {
            //coming from:
            //- task: PythonScript@0
            //  inputs:
            //    scriptSource: 'filePath'
            //    scriptPath: 'Python/Hello.py'

            //Going to:
            //- run: python Python/Hello.py

            string scriptPath = GetStepInput(step, "scriptPath");

            string pythonCommand = "python " + scriptPath;

            step.script = pythonCommand;

            GitHubActions.Step gitHubStep = CreateScriptStep("", step);

            return(gitHubStep);
        }
Ejemplo n.º 24
0
        public GitHubActions.Step CreateGradleStep(AzurePipelines.Step step)
        {
            //coming from:
            //- task: Gradle@2
            // inputs:
            //   workingDirectory: ''
            //   gradleWrapperFile: 'gradlew'
            //   gradleOptions: '-Xmx3072m'
            //   publishJUnitResults: false
            //   testResultsFiles: '**/TEST-*.xml'
            //   tasks: 'assembleDebug'

            //Going to:
            //- name: Build with Gradle
            //  run: ./gradlew build

            step.script = "./gradlew build";
            GitHubActions.Step gitHubStep = CreateScriptStep("", step);

            return(gitHubStep);
        }
Ejemplo n.º 25
0
        //https://github.com/Azure/sql-action
        private GitHubActions.Step CreateSQLAzureDacPacDeployStep(AzurePipelines.Step step)
        {
            string serverName = GetStepInput(step, "servername");
            string dacPacFile = GetStepInput(step, "dacpacfile");
            string arguments  = GetStepInput(step, "additionalarguments");

            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                uses = "azure/sql-action@v1",
                with = new Dictionary <string, string>
                {
                    { "server-name", serverName },
                    { "connection-string", "${{ secrets.AZURE_SQL_CONNECTION_STRING }}" },
                    { "dacpac-package", dacPacFile },
                    { "arguments", arguments }
                },
                step_message = "Note: Connection string needs to be specified - this is different than Pipelines where the server, database, user, and password were specified separately. It's recommended you use secrets for the connection string."
            };

            //coming from:
            //- task: SqlAzureDacpacDeployment@1
            //  displayName: 'Azure SQL dacpac publish'
            //  inputs:
            //    azureSubscription: 'my connection to Azure Portal'
            //    ServerName: '$(databaseServerName).database.windows.net'
            //    DatabaseName: '$(databaseName)'
            //    SqlUsername: '******'
            //    SqlPassword: '******'
            //    DacpacFile: '$(build.artifactstagingdirectory)/drop/MyDatabase.dacpac'
            //    additionalArguments: '/p:BlockOnPossibleDataLoss=true'

            //Going to:
            //- uses: azure/sql-action@v1
            //  with:
            //    server-name: REPLACE_THIS_WITH_YOUR_SQL_SERVER_NAME
            //    connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
            //    dacpac-package: './yourdacpacfile.dacpac'

            return(gitHubStep);
        }
Ejemplo n.º 26
0
        public GitHubActions.Step CreateAzureLoginStep()
        {
            //Goal:
            //- name: Log into Azure
            //  uses: azure/login@v1
            //  with:
            //    creds: ${{ secrets.AZURE_SP }}
            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                name = "Azure Login",
                uses = "azure/login@v1",
                with = new Dictionary <string, string>
                {
                    { "creds", "${{ secrets.AZURE_SP }}" }
                }
            };

            //Add note that 'AZURE_SP' secret is required
            gitHubStep.step_message = @"Note that 'AZURE_SP' secret is required to be setup and added into GitHub Secrets: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets";

            return(gitHubStep);
        }
Ejemplo n.º 27
0
        //https://github.com/warrenbuckley/Setup-Nuget
        private GitHubActions.Step CreateNuGetToolInstallerStep()
        {
            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                uses         = "warrenbuckley/Setup-Nuget@v1",
                step_message = "Note: This is a third party action: https://github.com/warrenbuckley/Setup-Nuget"
            };

            //coming from:
            //# NuGet tool installer
            //# Acquires a specific version of NuGet from the internet or the tools cache and adds it to the PATH. Use this task to change the version of NuGet used in the NuGet tasks.
            //- task: NuGetToolInstaller@0
            //  inputs:
            //    #versionSpec: '4.3.0'
            //    #checkLatest: false # Optional

            //Going to:
            //- name: Setup Nuget.exe
            //  uses: warrenbuckley/Setup-Nuget@v1

            return(gitHubStep);
        }
Ejemplo n.º 28
0
        private GitHubActions.Step CreateUseDotNetStep(AzurePipelines.Step step)
        {
            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                uses = "actions/setup-dotnet@v1",
                with = new Dictionary <string, string>
                {
                    { "dotnet-version", GetStepInput(step, "version") }
                }
            };
            //Pipelines
            //- task: UseDotNet@2
            //  displayName: 'Use .NET Core sdk'
            //  inputs:
            //    packageType: sdk
            //    version: 2.2.203
            //    installationPath: $(Agent.ToolsDirectory)/dotnet

            //Actions
            //- uses: actions/setup-dotnet@v1
            //  with:
            //    dotnet-version: '2.2.103' # SDK Version to use.
            return(gitHubStep);
        }
Ejemplo n.º 29
0
        //process the steps
        private GitHubActions.Step[] ProcessSteps(AzurePipelines.Step[] steps, bool addCheckoutStep = true)
        {
            StepsProcessing stepsProcessing = new StepsProcessing();

            GitHubActions.Step[] newSteps = null;
            if (steps != null)
            {
                //Start by scanning all of the steps, to see if we need to insert additional tasks
                int    stepAdjustment     = 0;
                bool   addJavaSetupStep   = false;
                bool   addGradleSetupStep = false;
                bool   addAzureLoginStep  = false;
                bool   addMSSetupStep     = false;
                string javaVersion        = null;

                //If the code needs a Checkout step, add it first
                if (addCheckoutStep == true)
                {
                    stepAdjustment++; // we are inserting a step and need to start moving steps 1 place into the array
                }

                //Loop through the steps to see if we need other tasks inserted in for specific circumstances
                foreach (AzurePipelines.Step step in steps)
                {
                    if (step.task != null)
                    {
                        switch (step.task)
                        {
                        //If we have an Java based step, we will need to add a Java setup step
                        case "Ant@1":
                        case "Maven@3":
                            if (addJavaSetupStep == false)
                            {
                                addJavaSetupStep = true;
                                stepAdjustment++;
                                javaVersion = stepsProcessing.GetStepInput(step, "jdkVersionOption");
                            }
                            break;

                        //Needs a the Java step and an additional Gradle step
                        case "Gradle@2":

                            if (addJavaSetupStep == false)
                            {
                                addJavaSetupStep = true;
                                stepAdjustment++;
                                //Create the java step, as it doesn't exist
                                javaVersion = "1.8";
                            }
                            if (addGradleSetupStep == false)
                            {
                                addGradleSetupStep = true;
                                stepAdjustment++;
                            }
                            break;

                        //If we have an Azure step, we will need to add a Azure login step
                        case "AzureAppServiceManage@0":
                        case "AzureResourceGroupDeployment@2":
                        case "AzureRmWebAppDeployment@3":
                            if (addAzureLoginStep == false)
                            {
                                addAzureLoginStep = true;
                                stepAdjustment++;
                            }
                            break;

                        case "VSBuild@1":
                            if (addMSSetupStep == false)
                            {
                                addMSSetupStep = true;
                                stepAdjustment++;
                            }
                            break;
                        }
                    }
                }

                //Re-size the newSteps array with adjustments as needed
                newSteps = new GitHubActions.Step[steps.Length + stepAdjustment];

                int adjustmentsUsed = 0;

                //Add the steps array
                if (addCheckoutStep == true)
                {
                    //Add the check out step to get the code
                    newSteps[adjustmentsUsed] = stepsProcessing.CreateCheckoutStep();
                    adjustmentsUsed++;
                }
                if (addJavaSetupStep == true)
                {
                    //Add the JavaSetup step to the code
                    if (javaVersion != null)
                    {
                        newSteps[adjustmentsUsed] = stepsProcessing.CreateSetupJavaStep(javaVersion);
                        adjustmentsUsed++;
                    }
                }
                if (addGradleSetupStep == true)
                {
                    //Add the Gradle setup step to the code
                    newSteps[adjustmentsUsed] = stepsProcessing.CreateSetupGradleStep();
                    adjustmentsUsed++;
                }
                if (addAzureLoginStep == true)
                {
                    //Add the Azure login step to the code
                    newSteps[adjustmentsUsed] = stepsProcessing.CreateAzureLoginStep();
                    adjustmentsUsed++;
                }
                if (addMSSetupStep == true)
                {
                    //Add the Azure login step to the code
                    newSteps[adjustmentsUsed] = stepsProcessing.CreateMSBuildSetupStep();
                    //adjustmentsUsed++;
                }

                //Translate the other steps
                for (int i = stepAdjustment; i < steps.Length + stepAdjustment; i++)
                {
                    newSteps[i] = stepsProcessing.ProcessStep(steps[i - stepAdjustment]);
                }
            }

            return(newSteps);
        }
Ejemplo n.º 30
0
        private GitHubActions.Step CreateFunctionalTestingStep(AzurePipelines.Step step)
        {
            //From:
            //- task: VSTest@2
            //  displayName: 'Run functional smoke tests on website and web service'
            //  inputs:
            //    searchFolder: '$(build.artifactstagingdirectory)'
            //    testAssemblyVer2: **\MyProject.FunctionalTests\MyProject.FunctionalTests.dll
            //    uiTests: true
            //    runSettingsFile: '$(build.artifactstagingdirectory)/drop/FunctionalTests/MyProject.FunctionalTests/test.runsettings'
            //    overrideTestrunParameters: |
            //     -ServiceUrl "https://$(WebServiceName)-staging.azurewebsites.net/"
            //     -WebsiteUrl "https://$(WebsiteName)-staging.azurewebsites.net/"
            //     -TestEnvironment "$(AppSettings.Environment)"

            //To:
            //- name: Functional Tests
            //  run: |
            //    $vsTestConsoleExe = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe"
            //    $targetTestDll = "functionaltests\FeatureFlags.FunctionalTests.dll"
            //    $testRunSettings = "/Settings:`"functionaltests\test.runsettings`" "
            //    $parameters = " -- TestEnvironment=""Beta123"" ServiceUrl=""https://featureflags-data-eu-service-staging.azurewebsites.net/"" WebsiteUrl=""https://featureflags-data-eu-web-staging.azurewebsites.net/"" "
            //    #Note that the `" is an escape character to quote strings, and the `& is needed to start the command
            //    $command = "`& `"$vsTestConsoleExe`" `"$targetTestDll`" $testRunSettings $parameters "
            //    Write-Host "$command"
            //    Invoke-Expression $command

            //Defined in the github windows runner.
            //TODO: fix this hardcoded VS path
            string vsTestConsoleLocation = @"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\TestPlatform\";

            string run = "";

            run += "$vsTestConsoleExe = \"" + vsTestConsoleLocation + "vstest.console.exe\"\n";
            run += "$targetTestDll = \"" + GetStepInput(step, "testassemblyver2") + "\"\n";
            run += "$testRunSettings = \"/Settings:`\"" + GetStepInput(step, "runsettingsfile") + "`\" \"\n";

            string parametersInput = GetStepInput(step, "overridetestrunparameters");

            if (parametersInput != null)
            {
                //Split it two ways, there are 3 combinations, parameters are on each new line, parameters are all on one line, a combination of both multi and single lines.
                //1. Multiline
                string[]      multiLineParameters = parametersInput.Split("\n-");
                StringBuilder parameters          = new StringBuilder();
                foreach (string multiLineItem in multiLineParameters)
                {
                    //2. Single line
                    string[] singleLineParameters = multiLineItem.Split(" -");
                    foreach (string item in singleLineParameters)
                    {
                        string[] items = item.Replace("\n", "").Split(" ");
                        if (items.Length == 2)
                        {
                            //build the new format [var name]=[var value]
                            parameters.Append(items[0]);
                            parameters.Append("=");
                            parameters.Append(items[1]);
                            parameters.Append(" ");
                        }
                        else
                        {
                            for (int i = 0; i < items.Length - 1; i++)
                            {
                                //if it's an even number (and hence the var name):
                                if (i % 2 == 0)
                                {
                                    //Sometimes the first item has an extra -, remove this.
                                    if (items[i].ToString().StartsWith("-") == true)
                                    {
                                        items[i] = items[i].TrimStart('-');
                                    }
                                    //build the new format [var name]=[var value]
                                    parameters.Append(items[i]);
                                    parameters.Append("=");
                                }
                                else //It's an odd number (and hence the var value)
                                {
                                    //build the new format [var name]=[var value]
                                    parameters.Append(items[i]);
                                    parameters.Append(" ");
                                }
                            }
                        }
                    }
                }
                run += "$parameters = \" -- " + parameters.ToString() + "\"\n";
                //run += "$parameters = \"poop\"\n";
            }

            run += "#Note that the `\" is an escape character to quote strings, and the `& is needed to start the command\n";
            run += "$command = \"`& `\"$vsTestConsoleExe`\" `\"$targetTestDll`\" $testRunSettings $parameters \"\n";
            run += "Write-Host \"$command\"\n";
            run += "Invoke-Expression $command";

            //To PowerShell script
            step.script = run;
            GitHubActions.Step gitHubStep = CreateScriptStep("powershell", step);

            return(gitHubStep);
        }