Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Microsoft/azure-pipelines-tasks i…
Browse files Browse the repository at this point in the history
…nto app-center-distribute-v3
  • Loading branch information
evkhramkov committed Mar 11, 2019
2 parents 60aa06e + b260810 commit 5f78666
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 129 deletions.
28 changes: 28 additions & 0 deletions Tasks/Common/packaging-common/bump-task-version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Bumps the version of all of the tasks that are technically modified when packaging-common is changed.
# Please validate the updated versions to confirm that nothing went horribly wrong.
Param(
[parameter(Mandatory=$true)]
# The current sprint, find at https://whatsprintis.it/
[int] $currentSprint,
# The path to the Tasks folder
[parameter()]
[string] $taskRoot = (Join-Path $PSScriptRoot "..\..")
)

"DotNetCoreCLIV2","DownloadPackageV0","DownloadPackageV1","MavenV2","MavenV3","NpmV1","NpmAuthenticateV0","NuGetV0","NuGetCommandV2","NuGetPublisherV0","NuGetToolInstallerV0","NuGetToolInstallerV1","PipAuthenticateV0","TwineAuthenticateV0","UniversalPackagesV0" | % {
$taskLocation = Join-Path "$taskRoot/$_" "task.json"
$taskContent = Get-Content $taskLocation
$task = $taskContent | ConvertFrom-Json
$v = $task.version
$newPatch = 0
if ($v.Minor -eq $currentSprint) {
$newPatch = $v.Patch + 1
}
Write-Output "${_}: $($v.Major).$($v.Minor).$($v.Patch) to $($v.Major).$currentSprint.$newPatch"
# Doing an awkward string replace to not interfere with any custom task.json formatting
$versionMatch = $taskContent | Select-String '"version":'
$versionLine = $versionMatch.LineNumber
$taskContent[$versionLine+1] = $taskContent[$versionLine+1].Replace(" $($v.Minor),", " $currentSprint,")
$taskContent[$versionLine+2] = $taskContent[$versionLine+2].Replace(" $($v.Patch)", " $newPatch")
$taskContent | Set-Content $taskLocation
}
10 changes: 10 additions & 0 deletions Tasks/Common/packaging-common/make.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"rm": [
{
"items": [
"bump-task-version.ps1"
],
"options": "-f"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
"loc.messages.NoReleaseFoundToDelete": "No release was found for tag: %s. Deleting the release failed.",
"loc.messages.FetchReleaseForTag": "Fetching the release for tag: %s",
"loc.messages.FetchReleaseForTagSuccess": "Found a release for tag: %s",
"loc.messages.FetchTagForTarget": "Fetching the tag for target: %s",
"loc.messages.FetchTagForTargetSuccess": "Found a tag for target: %s",
"loc.messages.FetchTagForTarget": "Searching for tags associated with target commit: %s",
"loc.messages.FetchTagForTargetSuccess": "Found a tag for target commit: %s",
"loc.messages.MissingAssetError": "File not found: %s",
"loc.messages.MultipleReleasesFoundError": "Only 1 release was expected but more than 1 release was found for tag: %s. Unable to perform the action.",
"loc.messages.MultipleTagFound": "Only 1 tag was expected but more than 1 tag was found for the given commit: %s. Unable to perform the action.",
"loc.messages.NoTagFound": "No tag was found for the provided target: %s. Skipping further steps...",
"loc.messages.NoTagFound": "Release will not be created as no tags could be found for the target commit. For more details check out the ‘Tag Source’ section in documentation: https://aka.ms/AA4f03a.",
"loc.messages.DeleteAllExistingAssets": "Deleting all existing assets...",
"loc.messages.DuplicateAssetFound": "Duplicate asset found: %s",
"loc.messages.AssetsDeletedSuccessfully": "Assets deleted successfully.",
Expand All @@ -68,9 +68,9 @@
"loc.messages.DeletingAsset": "Deleting asset: %s",
"loc.messages.NoAssetFoundToDelete": "No assets were found to delete.",
"loc.messages.UploadingAssets": "Uploading assets...",
"loc.messages.UploadingAsset": "Uploading asset: %s",
"loc.messages.UploadAssetError": "An unexpected error occurred while uploading the asset: %s",
"loc.messages.UploadAssetSuccess": "Uploaded asset successfully: %s",
"loc.messages.UploadingAsset": "Uploading file: '%s'.",
"loc.messages.UploadAssetError": "An unexpected error occurred while uploading the file: %s",
"loc.messages.UploadAssetSuccess": "Uploaded file successfully: '%s'",
"loc.messages.NoAssetFoundToUpload": "No assets were found to upload.",
"loc.messages.ReleaseNotesFileIsDirectoryError": "Release notes file: %s is a directory and not a file.",
"loc.messages.AssetIsDirectoryError": "The asset is a directory and not a file. Skipping uploading directory: %s",
Expand All @@ -79,7 +79,7 @@
"loc.messages.CommitDiffBehind": "Cannot compute the changes as the provided target commit is older than the commit of the last published release.",
"loc.messages.CommitDiffEqual": "No changes were found. The provided target commit is the same as the commit of the last published release.",
"loc.messages.FetchLatestPublishRelease": "Fetching the latest published release...",
"loc.messages.FetchLatestPublishReleaseSuccess": "Found the latest published release.",
"loc.messages.FetchLatestPublishReleaseSuccess": "Found the latest published release: %s",
"loc.messages.GetLatestReleaseError": "An unexpected error occurred while fetching the latest published release.",
"loc.messages.NoLatestPublishRelease": "No releases are published yet in the repository.",
"loc.messages.FetchCommitDiff": "Fetching the list of commits since the last published release...",
Expand All @@ -90,5 +90,13 @@
"loc.messages.InvalidGitHubEndpoint": "Invalid GitHub service endpoint: %s.",
"loc.messages.InvalidEndpointAuthScheme": "Invalid GitHub service connection scheme: %s. Only OAuth and GitHub personal access token connections are allowed.",
"loc.messages.FetchInitialCommitError": "An unexpected error occurred while fetching the initial commit.",
"loc.messages.InvalidActionSet": "Invalid action: %s. Only 'create', 'edit', or 'delete' actions are allowed."
"loc.messages.InvalidActionSet": "Invalid action: %s. Only 'create', 'edit', or 'delete' actions are allowed. For yaml syntax see: https://aka.ms/AA3m1bq",
"loc.messages.InvalidTagSource": "Invalid tag source: %s. Only 'auto', or 'manual' options are allowed. For yaml syntax see: https://aka.ms/AA3m1bq",
"loc.messages.InvalidReleaseNotesSource": "Invalid release notes source: %s. Only 'file', or 'input' options are allowed. For yaml syntax see: https://aka.ms/AA3m1bq",
"loc.messages.InvalidAssetUploadMode": "Invalid asset upload mode: %s. Only 'delete', or 'replace' options are allowed. For yaml syntax see: https://aka.ms/AA3m1bq",
"loc.messages.TagRequiredEditDeleteAction": "For '%s' action, a tag is required. Please specify a tag in the step. For yaml syntax see: https://aka.ms/AA3m1bq",
"loc.messages.TagRequiredCreateAction": "Tag source is set to manual- please specify a tag for create action. For yaml syntax see: https://aka.ms/AA3m1bq",
"loc.messages.NoFileFoundMatchingPattern": "No files found matching '%s'. Nothing to upload.",
"loc.messages.PatternIsADirectory": "'%s' cannot be uploaded as it is a directory. Please specify a file.",
"loc.messages.SearchingFileMatchingPattern": "Searching for file(s) matching '%s'."
}
3 changes: 3 additions & 0 deletions Tasks/GitHubReleaseV0/Tests/ActionTests.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import tmrm = require('vsts-task-lib/mock-run');
import * as path from 'path';
import * as sinon from 'sinon';
import { Inputs } from '../operations/Constants';

export class ActionTests {

public static startTest() {
let tp = path.join(__dirname, 'ActionL0Tests.js');
let tr : tmrm.TaskMockRunner = new tmrm.TaskMockRunner(tp);

tr.setInput(Inputs.assetUploadMode, "replace");

this.stub(tr);

tr.run();
Expand Down
4 changes: 3 additions & 1 deletion Tasks/GitHubReleaseV0/Tests/CreateAction2L0Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export class CreateAction2L0Tests {
tr.setInput(Inputs.gitHubConnection, "connection");
tr.setInput(Inputs.repositoryName, "repo");
tr.setInput(Inputs.action, "create");
tr.setInput(Inputs.tagSource, "auto");
tr.setInput(Inputs.target, "master");
tr.setInput(Inputs.releaseNotesSource, "input");

this.stub(tr);
tr.run();
Expand All @@ -29,7 +31,7 @@ export class CreateAction2L0Tests {
tr.registerMock("./operations/Helper", {
Helper: function () {
return {
getTagForCreateAction: function() {
getTagForCommitTarget: function() {
return null;
},
publishTelemetry: function() {
Expand Down
3 changes: 3 additions & 0 deletions Tasks/GitHubReleaseV0/Tests/CreateActionL0Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export class CreateActionL0Tests {
tr.setInput(Inputs.gitHubConnection, "connection");
tr.setInput(Inputs.repositoryName, "repo");
tr.setInput(Inputs.action, "create");
tr.setInput(Inputs.tagSource, "manual");
tr.setInput(Inputs.tag, "tag");
tr.setInput(Inputs.target, "master");
tr.setInput(Inputs.releaseNotesSource, "input");

this.stub(tr);
tr.run();
Expand Down
1 change: 1 addition & 0 deletions Tasks/GitHubReleaseV0/Tests/DeleteAction2L0Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class DeleteAction2L0Tests {
tr.setInput(Inputs.gitHubConnection, "connection");
tr.setInput(Inputs.repositoryName, "repo");
tr.setInput(Inputs.action, "Delete");
tr.setInput(Inputs.tag, "tag");

// Stub methods
this.stub();
Expand Down
1 change: 1 addition & 0 deletions Tasks/GitHubReleaseV0/Tests/DeleteActionL0Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class DeleteActionL0Tests {
tr.setInput(Inputs.gitHubConnection, "connection");
tr.setInput(Inputs.repositoryName, "repo");
tr.setInput(Inputs.action, "delete");
tr.setInput(Inputs.tag, "tag");

// Stub methods
this.stub();
Expand Down
1 change: 1 addition & 0 deletions Tasks/GitHubReleaseV0/Tests/EditAction2L0Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class EditAction2L0Tests {
tr.setInput(Inputs.target, "master");
tr.setInput(Inputs.tagSource, "manual");
tr.setInput(Inputs.tag, "v1.0.0");
tr.setInput(Inputs.releaseNotesSource, "input");

this.stub(tr);
tr.run();
Expand Down
1 change: 1 addition & 0 deletions Tasks/GitHubReleaseV0/Tests/EditActionL0Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class EditActionL0Tests {
tr.setInput(Inputs.target, "master");
tr.setInput(Inputs.tagSource, "manual");
tr.setInput(Inputs.tag, "v1.0.0");
tr.setInput(Inputs.releaseNotesSource, "input");

this.stub(tr);
tr.run();
Expand Down
2 changes: 1 addition & 1 deletion Tasks/GitHubReleaseV0/Tests/HelperL0Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class HelperL0Tests {
}

public static async validateGetTagForCreateAction() {
let tag = await new Helper().getTagForCreateAction("endpoint", "repo", "target", "tagName");
let tag = await new Helper().getTagForCommitTarget("endpoint", "repo", "abc");

if (tag === "tagName") {
console.log(TestString.getTagForCreateActionKeyword);
Expand Down
12 changes: 12 additions & 0 deletions Tasks/GitHubReleaseV0/Tests/HelperTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export class HelperTests {
tr.registerMock("./Release", {
Release: function () {
return {
getTags: function() {
return {
statusCode: 200,
headers: { "link": ""},
body: [
{
"commit": { "sha": "abc" },
"name": "tagName"
}
]
}
},
getBranch: function() {
return {
statusCode: 200,
Expand Down
2 changes: 1 addition & 1 deletion Tasks/GitHubReleaseV0/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('GitHubReleaseTaskTests Suite', function() {
done();
});

it('Validate task fails with correct error when action = create and not tag is present.', (done: MochaDone) => {
it('Validate task fails with correct error when action = create and no tag is present.', (done: MochaDone) => {
let tp = path.join(__dirname, 'CreateAction2L0Tests.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();
Expand Down
35 changes: 22 additions & 13 deletions Tasks/GitHubReleaseV0/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tl = require("vsts-task-lib/task");
import path = require("path");
import { Action } from "./operations/Action";
import { Utility, ActionType, Delimiters} from "./operations/Utility";
import { Utility, ActionType, Delimiters, TagSelectionMode} from "./operations/Utility";
import { Inputs} from "./operations/Constants";
import { ChangeLog } from "./operations/ChangeLog";
import { Helper } from "./operations/Helper";
Expand All @@ -17,16 +17,23 @@ class Main {
let actions = new Action();
let helper = new Helper()

helper.publishTelemetry();

// Get basic task inputs
const githubEndpoint = tl.getInput(Inputs.gitHubConnection, true);
const githubEndpointToken = Utility.getGithubEndPointToken(githubEndpoint);
const repositoryName = tl.getInput(Inputs.repositoryName, true);

const repositoryName = tl.getInput(Inputs.repositoryName, true);

const action = tl.getInput(Inputs.action, true).toLowerCase();
Utility.validateAction(action);

let tagSource = tl.getInput(Inputs.tagSource);
Utility.validateTagSource(tagSource, action);

let tag = tl.getInput(Inputs.tag);
Utility.validateTag(tag, tagSource, action);

if (action === ActionType.delete) {
helper.publishTelemetry();
await actions.deleteReleaseAction(githubEndpointToken, repositoryName, tag);
}
else {
Expand All @@ -39,22 +46,26 @@ class Main {
const githubReleaseAssetInputPatterns = tl.getDelimitedInput(Inputs.assets, Delimiters.newLine);

if (action === ActionType.create) {
// Get tag to create release
tag = await helper.getTagForCreateAction(githubEndpointToken, repositoryName, target, tag);
// Get tag to create release if tag source is gitTag/auto
if (Utility.isTagSourceAuto(tagSource)) {
tag = await helper.getTagForCommitTarget(githubEndpointToken, repositoryName, target);
}

if (!!tag) {
helper.publishTelemetry();
const releaseNote: string = await this._getReleaseNote(githubEndpointToken, repositoryName, target);
await actions.createReleaseAction(githubEndpointToken, repositoryName, target, tag, releaseTitle, releaseNote, isDraft, isPrerelease, githubReleaseAssetInputPatterns);
}
else {
// If no tag found, then give warning.
// Doing this because commits without associated tag will fail continuosly if we throw error.
// Other option is to have some task condition, which user can specify in task.
tl.warning(tl.loc("NoTagFound", target));
tl.warning(tl.loc("NoTagFound"));
tl.debug("No tag found"); // for purpose of L0 test only.
}
}
else if (action === ActionType.edit) {
helper.publishTelemetry();
const releaseNote: string = await this._getReleaseNote(githubEndpointToken, repositoryName, target);
// Get the release id of the release to edit.
console.log(tl.loc("FetchReleaseForTag", tag));
Expand All @@ -71,10 +82,6 @@ class Main {
await actions.createReleaseAction(githubEndpointToken, repositoryName, target, tag, releaseTitle, releaseNote, isDraft, isPrerelease, githubReleaseAssetInputPatterns);
}
}
else {
tl.debug("Invalid action input"); // for purpose of L0 test only.
throw new Error(tl.loc("InvalidActionSet", action));
}
}

tl.setResult(tl.TaskResult.Succeeded, "");
Expand All @@ -85,7 +92,9 @@ class Main {
}

private static async _getReleaseNote(githubEndpointToken: string, repositoryName: string, target: string): Promise<string> {
const releaseNotesSelection = tl.getInput(Inputs.releaseNotesSource);
const releaseNotesSource = tl.getInput(Inputs.releaseNotesSource, true);
Utility.validateReleaseNotesSource(releaseNotesSource);

const releaseNotesFile = tl.getPathInput(Inputs.releaseNotesFile, false, true);
const releaseNoteInput = tl.getInput(Inputs.releaseNotes);
const showChangeLog: boolean = tl.getBoolInput(Inputs.addChangeLog);
Expand All @@ -95,7 +104,7 @@ class Main {
const changeLog: string = showChangeLog ? await new ChangeLog().getChangeLog(githubEndpointToken, repositoryName, target, 250) : "";

// Append change log to release note
const releaseNote: string = Utility.getReleaseNote(releaseNotesSelection, releaseNotesFile, releaseNoteInput, changeLog) || undefined;
const releaseNote: string = Utility.getReleaseNote(releaseNotesSource, releaseNotesFile, releaseNoteInput, changeLog) || undefined;

return releaseNote;
}
Expand Down
Loading

0 comments on commit 5f78666

Please sign in to comment.