<commit_before>{
  "Id": "ActionTemplates-66",
  "Name": "Azure Blob Storage Upload",
  "Description": "Upload files in a directory to a specified Azure Storage blob container.",
  "ActionType": "Octopus.Script",
  "Version": 13,
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "function Find-InstallLocations {\r\n    $result = @()\r\n    $OctopusParameters.Keys | foreach {\r\n        if ($_.EndsWith('].Output.Package.InstallationDirectoryPath')) {\r\n            $result += $OctopusParameters[$_]\r\n        }\r\n    }\r\n    return $result\r\n}\r\n\r\nfunction Find-InstallLocation($stepName) {\r\n    $result = $OctopusParameters.Keys | where {\r\n        $_.Equals(\"Octopus.Action[$stepName].Output.Package.InstallationDirectoryPath\",  [System.StringComparison]::OrdinalIgnoreCase)\r\n    } | select -first 1\r\n \r\n    if ($result) {\r\n        return $OctopusParameters[$result]\r\n    }\r\n \r\n    throw \"No install location found for step: $stepName\"\r\n}\r\n\r\nfunction Find-SingleInstallLocation {\r\n    $all = @(Find-InstallLocations)\r\n    if ($all.Length -eq 1) {\r\n        return $all[0]\r\n    }\r\n    if ($all.Length -eq 0) {\r\n        throw \"No package steps found\"\r\n    }\r\n    throw \"Multiple package steps have run; please specify a single step\"\r\n}\r\n\r\n# Check if Windows Azure Powershell is avaiable \r\ntry{ \r\n    Import-Module Azure -ErrorAction Stop\r\n}catch{\r\n    throw \"Windows Azure Powershell not found! Please make sure to install them from http://www.windowsazure.com/en-us/downloads/#cmd-line-tools\" \r\n}\r\n\r\nImport-AzurePublishSettingsFile $PublishSettingsFile\r\n\r\n# The script has been tested on Powershell 3.0\r\nSet-StrictMode -Version 3\r\n\r\n$stepPath = \"\"\r\nif (-not [string]::IsNullOrEmpty($NugetPackageStepName)) {\r\n    Write-Host \"Finding path to package step: $NugetPackageStepName\"\r\n    $stepPath = Find-InstallLocation $NugetPackageStepName\r\n} else {\r\n    $stepPath = Find-SingleInstallLocation\r\n}\r\nWrite-Host \"Package was installed to: $stepPath\"\r\n\r\n$fullPath = \"$stepPath\\$CopyDirectory\"\r\n\r\n# Get a list of files from the project folder\r\n$files = (ls -Path $fullPath -File -Recurse)\r\n\r\n$context = New-AzureStorageContext `\r\n    -StorageAccountName $StorageAccount `\r\n    -StorageAccountKey $StorageAccountKey\r\n\r\nif ($files -ne $null -and $files.Count -gt 0)\r\n{\r\n    # Create the storage container.\r\n    $existingContainer = Get-AzureStorageContainer -Context $context | \r\n        Where-Object { $_.Name -like $StorageContainer }\r\n\r\n    if (-not $existingContainer)\r\n    {\r\n        $newContainer = New-AzureStorageContainer `\r\n                            -Context $context `\r\n                            -Name $StorageContainer `\r\n                            -Permission Blob\r\n        \"Storage container '\" + $newContainer.Name + \"' created.\"\r\n    }\r\n\r\n    # Upload the files to storage container.\r\n    $fileCount = $files.Count\r\n    $time = [DateTime]::UtcNow\r\n    if ($files.Count -gt 0)\r\n    {\r\n        foreach ($file in $files) \r\n        {\r\n            $blobFileName = $file.FullName.Replace($fullPath, '').TrimStart('\\')\r\n            $contentType = switch ([System.IO.Path]::GetExtension($file))\r\n\t        {\r\n\t            \".png\" {\"image/png\"}\r\n\t            \".css\" {\"text/css\"}\r\n\t            \".js\" {\"text/javascript\"}\r\n\t            default {\"application/octet-stream\"}\r\n\t        }\r\n\r\n            Set-AzureStorageBlobContent `\r\n                -Container $StorageContainer `\r\n                -Context $context `\r\n                -File $file.FullName `\r\n                -Blob $blobFileName `\r\n                -Properties @{ContentType=$contentType} `\r\n                -Force\r\n        }\r\n    }\r\n\r\n    $duration = [DateTime]::UtcNow - $time\r\n\r\n    \"Uploaded \" + $files.Count + \" files to blob container '\" + $StorageContainer + \"'.\"\r\n    \"Total upload time: \" + $duration.TotalMinutes + \" minutes.\"\r\n}\r\nelse\r\n{\r\n    Write-Warning \"No files found.\"\r\n}"
  },
  "SensitiveProperties": {},
  "Parameters": [
    {
      "Name": "CopyDirectory",
      "Label": "Copy Directory",
      "HelpText": "Replicates files and directory under the Copy Directory.\nEg. `Content/CDN` that is located at the root of the nuget package.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "PublishSettingsFile",
      "Label": "Publish Settings File",
      "HelpText": "Absolute path on the tentacle to the Azure publishsettings file to use.\nEg. `C:\\Azure\\Azure.publishsettings`",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "StorageAccount",
      "Label": "Storage Account",
      "HelpText": "The Azure Storage Account to use.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "StorageAccountKey",
      "Label": "Storage Account Key",
      "HelpText": "The primary or secondary key for the Azure Storage Account.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "StorageContainer",
      "Label": "Storage Container",
      "HelpText": "The storage container to use.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "NugetPackageStepName",
      "Label": "Nuget Package Step Name",
      "HelpText": "Name of the previously-deployed package step that contains the Copy Directory.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "LastModifiedOn": "2015-10-11T23:12:35.453+00:00",
  "LastModifiedBy": "ShawnMclean",
  "$Meta": {
    "ExportedAt": "2015-10-11T23:12:43.351Z",
    "OctopusVersion": "2.6.5.1010",
    "Type": "ActionTemplate"
  }
}<commit_msg>Fix a bug if a directory only had a single file.  Added more mime types<commit_after>{
  "Id": "ActionTemplates-66",
  "Name": "Azure Blob Storage Upload",
  "Description": "Upload files in a directory to a specified Azure Storage blob container.",
  "ActionType": "Octopus.Script",
  "Version": 14,
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "function Find-InstallLocations {\n    $result = @()\n    $OctopusParameters.Keys | foreach {\n        if ($_.EndsWith('].Output.Package.InstallationDirectoryPath')) {\n            $result += $OctopusParameters[$_]\n        }\n    }\n    return $result\n}\n\nfunction Find-InstallLocation($stepName) {\n    $result = $OctopusParameters.Keys | where {\n        $_.Equals(\"Octopus.Action[$stepName].Output.Package.InstallationDirectoryPath\",  [System.StringComparison]::OrdinalIgnoreCase)\n    } | select -first 1\n \n    if ($result) {\n        return $OctopusParameters[$result]\n    }\n \n    throw \"No install location found for step: $stepName\"\n}\n\nfunction Find-SingleInstallLocation {\n    $all = @(Find-InstallLocations)\n    if ($all.Length -eq 1) {\n        return $all[0]\n    }\n    if ($all.Length -eq 0) {\n        throw \"No package steps found\"\n    }\n    throw \"Multiple package steps have run; please specify a single step\"\n}\n\n# Check if Windows Azure Powershell is avaiable \ntry{ \n    Import-Module Azure -ErrorAction Stop\n}catch{\n    throw \"Windows Azure Powershell not found! Please make sure to install them from http://www.windowsazure.com/en-us/downloads/#cmd-line-tools\" \n}\n\nImport-AzurePublishSettingsFile $PublishSettingsFile\n\n# The script has been tested on Powershell 3.0\nSet-StrictMode -Version 3\n\n$stepPath = \"\"\nif (-not [string]::IsNullOrEmpty($NugetPackageStepName)) {\n    Write-Host \"Finding path to package step: $NugetPackageStepName\"\n    $stepPath = Find-InstallLocation $NugetPackageStepName\n} else {\n    $stepPath = Find-SingleInstallLocation\n}\nWrite-Host \"Package was installed to: $stepPath\"\n\n$fullPath = \"$stepPath\\$CopyDirectory\"\nWrite-Host \"Copying Files in: $fullPath\"\n\n# Get a list of files from the project folder\n$files = @(ls -Path $fullPath -File -Recurse)\n\n$fileCount = $files.Count\nWrite-Host \"Found $fileCount Files: $files\"\n\n$context = New-AzureStorageContext `\n    -StorageAccountName $StorageAccount `\n    -StorageAccountKey $StorageAccountKey\n\nif ($files -ne $null -and $files.Count -gt 0)\n{\n    # Create the storage container.\n    $existingContainer = Get-AzureStorageContainer -Context $context | \n        Where-Object { $_.Name -like $StorageContainer }\n\n    if (-not $existingContainer)\n    {\n        $newContainer = New-AzureStorageContainer `\n                            -Context $context `\n                            -Name $StorageContainer `\n                            -Permission Blob\n        \"Storage container '\" + $newContainer.Name + \"' created.\"\n    }\n\n    # Upload the files to storage container.\n    $fileCount = $files.Count\n    $time = [DateTime]::UtcNow\n    if ($files.Count -gt 0)\n    {\n        foreach ($file in $files) \n        {\n            $blobFileName = $file.FullName.Replace($fullPath, '').TrimStart('\\')\n            $contentType = switch ([System.IO.Path]::GetExtension($file))\n\t        {\n\t            \".css\" {\"text/css\"}\n\t            \".js\" {\"text/javascript\"}\n\t            \".json\" {\"application/json\"}\n\t            \".html\" {\"text/html\"}\n\t            \".png\" {\"image/png\"}\n\t            \".svg\" {\"image/svg+xml\"}\n\t            default {\"application/octet-stream\"}\n\t        }\n\n            Set-AzureStorageBlobContent `\n                -Container $StorageContainer `\n                -Context $context `\n                -File $file.FullName `\n                -Blob $blobFileName `\n                -Properties @{ContentType=$contentType} `\n                -Force\n        }\n    }\n\n    $duration = [DateTime]::UtcNow - $time\n\n    \"Uploaded \" + $files.Count + \" files to blob container '\" + $StorageContainer + \"'.\"\n    \"Total upload time: \" + $duration.TotalMinutes + \" minutes.\"\n}\nelse\n{\n    Write-Warning \"No files found.\"\n}",
    "Octopus.Action.Script.Syntax": "PowerShell"
  },
  "SensitiveProperties": {},
  "Parameters": [
    {
      "Name": "CopyDirectory",
      "Label": "Copy Directory",
      "HelpText": "Replicates files and directory under the Copy Directory.\nEg. `Content/CDN` that is located at the root of the nuget package.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "PublishSettingsFile",
      "Label": "Publish Settings File",
      "HelpText": "Absolute path on the tentacle to the Azure publishsettings file to use.\nEg. `C:\\Azure\\Azure.publishsettings`",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "StorageAccount",
      "Label": "Storage Account",
      "HelpText": "The Azure Storage Account to use.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "StorageAccountKey",
      "Label": "Storage Account Key",
      "HelpText": "The primary or secondary key for the Azure Storage Account.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "StorageContainer",
      "Label": "Storage Container",
      "HelpText": "The storage container to use.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "NugetPackageStepName",
      "Label": "Nuget Package Step Name",
      "HelpText": "Name of the previously-deployed package step that contains the Copy Directory.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "$Meta": {
    "ExportedAt": "2016-01-21T07:21:36.182Z",
    "OctopusVersion": "3.1.3",
    "Type": "ActionTemplate"
  }
}
{'fraction_non_alphanumeric': 0.16311827086537684, 'fraction_numerical': 0.007366631587468631, 'mean_word_length': 2.5056753688989786, 'pattern_counts': {'":': 101, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 1}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3622501', 'n_tokens_mistral': 3958, 'n_tokens_neox': 3826, 'n_words': 935}