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

(#979) Add support for new transifex client #981

Merged
merged 1 commit into from
Aug 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion Source/Cake.Recipe/Content/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public static class BuildParameters
AppVeyorAccountName = appVeyorAccountName ?? RepositoryOwner.Replace("-", "").ToLower();
AppVeyorProjectSlug = appVeyorProjectSlug ?? RepositoryName.Replace(".", "-").ToLower();

TransifexEnabled = transifexEnabled ?? TransifexIsConfiguredForRepository(context);
TransifexEnabled = transifexEnabled ?? context.FileExists("./.tx/config");
TransifexPullMode = transifexPullMode;
TransifexPullPercentage = transifexPullPercentage;

Expand Down
1 change: 0 additions & 1 deletion Source/Cake.Recipe/Content/tasks.cake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class BuildTasks
public CakeTaskBuilder TransifexPullTranslations { get; set; }
public CakeTaskBuilder TransifexPushSourceResource { get; set; }
public CakeTaskBuilder TransifexPushTranslations { get; set; }
public CakeTaskBuilder TransifexSetupTask { get; set; }
public CakeTaskBuilder DotNetCoreTestTask { get; set; }
public CakeTaskBuilder IntegrationTestTask { get;set; }
public CakeTaskBuilder GenerateFriendlyTestReportTask { get; set; }
Expand Down
66 changes: 35 additions & 31 deletions Source/Cake.Recipe/Content/transifex.cake
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,58 @@ public static string GetTransifexUserSettingsPath()
return path;
}

public static bool TransifexIsConfiguredForRepository(ICakeContext context)
{
return context.FileExists("./.tx/config");
}

// Before we do anything with transifex, we must make sure that it has been properly
// Initialized, this is mostly related to running on appveyor or other CI.
// Because we expect the repository to already be configured to use
// transifex, we cannot run tx init, or it would replace the repository configuration file.
BuildParameters.Tasks.TransifexSetupTask = Task("Transifex-Setup")
.WithCriteria(() => BuildParameters.TransifexEnabled, "Transifex is not enabled")
.WithCriteria(() => !TransifexUserSettingsExists(Context), "Transifex user settings already exist")
.WithCriteria(() => BuildParameters.Transifex.HasCredentials, "Missing transifex credentials")
.Does(() =>
{
var path = GetTransifexUserSettingsPath();
var encoding = new System.Text.UTF8Encoding(false);
var text = string.Format("[https://www.transifex.com]\r\nhostname = https://www.transifex.com\r\npassword = {0}\r\nusername = api", BuildParameters.Transifex.ApiToken);
System.IO.File.WriteAllText(path, text, encoding);
});

BuildParameters.Tasks.TransifexPushSourceResource = Task("Transifex-Push-SourceFiles")
.WithCriteria(() => BuildParameters.CanPushTranslations)
.IsDependentOn("Transifex-Setup")
.WithCriteria((ctx) => BuildParameters.Transifex.HasCredentials || TransifexUserSettingsExists(ctx), "No transifex credentials specified")
.Does(() =>
{
TransifexPush(new TransifexPushSettings {
var settings = new TransifexPushSettings
{
UploadSourceFiles = true,
Force = string.Equals(BuildParameters.Target, "Transifex-Push-SourceFiles", StringComparison.OrdinalIgnoreCase)
});
Force = string.Equals(BuildParameters.Target, "Transifex-Push-SourceFiles", StringComparison.OrdinalIgnoreCase)
};

if (!TransifexUserSettingsExists(Context))
{
settings.ArgumentCustomization = (args) => args.PrependSwitchQuoted("--token", BuildParameters.Transifex.ApiToken);
}

TransifexPush(settings);
});

BuildParameters.Tasks.TransifexPullTranslations = Task("Transifex-Pull-Translations")
.WithCriteria(() => BuildParameters.CanPullTranslations)
.WithCriteria((ctx) => BuildParameters.Transifex.HasCredentials || TransifexUserSettingsExists(ctx), "No transifex credentials specified")
.IsDependentOn("Transifex-Push-SourceFiles")
.Does(() =>
{
TransifexPull(new TransifexPullSettings {
All = true,
Mode = BuildParameters.TransifexPullMode,
var settings = new TransifexPullSettings
{
All = true,
Mode = BuildParameters.TransifexPullMode,
MinimumPercentage = BuildParameters.TransifexPullPercentage
});
};

if (BuildParameters.Transifex.HasCredentials)
{
settings.ArgumentCustomization = (args) => args.PrependSwitchQuoted("--token", BuildParameters.Transifex.ApiToken);
}

TransifexPull(settings);
});

BuildParameters.Tasks.TransifexPushTranslations = Task("Transifex-Push-Translations")
.Does(() =>
{
TransifexPush(new TransifexPushSettings {
var settings = new TransifexPushSettings
{
UploadTranslations = true
});
};

if (BuildParameters.Transifex.HasCredentials)
{
settings.ArgumentCustomization = (args) => args.PrependSwitchQuoted("--token", BuildParameters.Transifex.ApiToken);
}

TransifexPush(settings);
});
Loading