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

Publish build artifacts as part of the build #118

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions FluentTc.Tests/LocalTcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,39 @@ public void IsPersonal_False_False()
// Assert
isPersonal.Should().BeFalse();
}

[Test]
public void PublishArtifact_FileName_Published()
{
// Arrange
var teamCityWriterFactory = A.Fake<ITeamCityWriterFactory>();
var teamCityWriter = A.Fake<ITeamCityWriter>();
A.CallTo(() => teamCityWriterFactory.CreateTeamCityWriter()).Returns(teamCityWriter);

var localTc = new LocalTc(A.Fake<IBuildParameters>(), teamCityWriterFactory);

// Act
localTc.PublishArtifact("file.txt");

// Assert
A.CallTo(()=>teamCityWriter.PublishArtifact("file.txt")).MustHaveHappened();
}

[Test]
public void PublishArtifact_FileNameAndTarget_Published()
{
// Arrange
var teamCityWriterFactory = A.Fake<ITeamCityWriterFactory>();
var teamCityWriter = A.Fake<ITeamCityWriter>();
A.CallTo(() => teamCityWriterFactory.CreateTeamCityWriter()).Returns(teamCityWriter);

var localTc = new LocalTc(A.Fake<IBuildParameters>(), teamCityWriterFactory);

// Act
localTc.PublishArtifact("file.txt", "dir");

// Assert
A.CallTo(()=>teamCityWriter.PublishArtifact("file.txt => dir")).MustHaveHappened();
}
}
}
57 changes: 57 additions & 0 deletions FluentTc/LocalTc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ public interface ILocalTc
bool IsTeamCityMode { get; }
bool IsPersonal { get; }
void SetBuildParameter(string parameterName, string parameterValue);

/// <summary>
/// Attaches new artifact publishing rules as described in
/// http://confluence.jetbrains.net/display/TCD7/Build+Artifact
/// </summary>
/// <param name="fileDirectoryName">
/// Filename to publish. The file name should be relative to the build checkout directory.
/// Directory name to publish all the files and subdirectories within the directory specified. The directory name should be a path relative to the build checkout directory. The files will be published preserving the directories structure under the directory specified (the directory itself will not be included).
/// </param>
void PublishArtifact(string fileDirectoryName);

/// <summary>
/// Attaches new artifact publishing rules as described in
/// http://confluence.jetbrains.net/display/TCD7/Build+Artifact
/// </summary>
/// <param name="fileDirectoryName">
/// Filename to publish. The file name should be relative to the build checkout directory.
/// Directory name to publish all the files and subdirectories within the directory specified. The directory name should be a path relative to the build checkout directory. The files will be published preserving the directories structure under the directory specified (the directory itself will not be included).
/// </param>
/// <param name="targetDirectoryArchive">
/// Target directory - the directory in the resulting build's artifacts that will contain the files determined by the left part of the pattern.
/// Target archive - the path to the archive to be created by TeamCity by packing build artifacts.
/// TeamCity treats <paramref name="targetDirectoryArchive"/> as archive whenever it ends with a supported archive extension, i.e. .zip, .jar, .tar.gz, or .tgz.
/// </param>
void PublishArtifact(string fileDirectoryName, string targetDirectoryArchive);
}

public class LocalTc : ILocalTc
Expand Down Expand Up @@ -173,5 +198,37 @@ public bool IsPersonal
{
get { return m_BuildParameters.IsPersonal; }
}

/// <summary>
/// Attaches new artifact publishing rules as described in
/// http://confluence.jetbrains.net/display/TCD7/Build+Artifact
/// </summary>
/// <param name="fileDirectoryName">
/// Filename to publish. The file name should be relative to the build checkout directory.
/// Directory name to publish all the files and subdirectories within the directory specified. The directory name should be a path relative to the build checkout directory. The files will be published preserving the directories structure under the directory specified (the directory itself will not be included).
/// </param>
public void PublishArtifact(string fileDirectoryName)
{
m_TeamCityWriter.PublishArtifact(fileDirectoryName);
}

/// <summary>
/// Attaches new artifact publishing rules as described in
/// http://confluence.jetbrains.net/display/TCD7/Build+Artifact
/// </summary>
/// <param name="fileDirectoryName">
/// Filename to publish. The file name should be relative to the build checkout directory.
/// Directory name to publish all the files and subdirectories within the directory specified. The directory name should be a path relative to the build checkout directory. The files will be published preserving the directories structure under the directory specified (the directory itself will not be included).
/// </param>
/// <param name="targetDirectoryArchive">
/// Target directory - the directory in the resulting build's artifacts that will contain the files determined by the left part of the pattern.
/// Target archive - the path to the archive to be created by TeamCity by packing build artifacts.
/// TeamCity treats <paramref name="targetDirectoryArchive"/> as archive whenever it ends with a supported archive extension, i.e. .zip, .jar, .tar.gz, or .tgz.
/// </param>
public void PublishArtifact(string fileDirectoryName, string targetDirectoryArchive)
{
// ReSharper disable once UseStringInterpolation
m_TeamCityWriter.PublishArtifact(string.Format("{0} => {1}", fileDirectoryName, targetDirectoryArchive));
}
}
}