Skip to content

Instantly share code, notes, and snippets.

@dima117
Last active July 7, 2021 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dima117/b6c10f60f55ee202028046630771605a to your computer and use it in GitHub Desktop.
Save dima117/b6c10f60f55ee202028046630771605a to your computer and use it in GitHub Desktop.
namespace ShriAccount.Sync.Synchronizers
{
[Command("autotest")]
public class AutotestSynchronizer
{
public async Task OnExecute()
{
var solutions = db.Solutions
.Where(s => s.Status == SolutionStatus.AutoCheckInProgress)
.Include(s => s.Candidate)
.Include(s => s.Exercise)
.ToArray();
logger.LogInformation($"{solutions.Length} solutions was found");
foreach (var solution in solutions)
{
var solutionDisplayName = $"{solution.Candidate.GithubLogin}@{solution.Exercise.Key}";
logger.LogInformation($"process solution: {solutionDisplayName} ({solution.Id})");
if (solution.AutocheckBuildId.HasValue)
{
logger.LogInformation(
$"autocheck has already been launched (id: {solution.AutocheckBuildId.Value}) → trying to get build info");
// auto check has started
var info = await client.GetBuildInfo(solution.AutocheckBuildId.Value);
if (info.state == BuildState.finished)
{
logger.LogInformation($"build is successful ({info.webUrl}) → geting result");
// load test result & set new status
var json = await client.GetBuildArtifactContent(solution.AutocheckBuildId.Value);
var result = JsonConvert.DeserializeObject<AutocheckExerciseResult>(json);
solution.AutocheckIsSuccessful = result.isSuccess;
solution.ApplyStatus(result.isSuccess
? SolutionStatus.AutoCheckCompleted
: SolutionStatus.Initial);
logger.LogInformation($"new solution status is {solution.Status}");
}
else
{
logger.LogInformation("build is not finished");
}
}
else
{
logger.LogInformation("run autotests");
var args = new {
EXERCISE = solution.Exercise.Key,
REPO = solution.RepoName,
GITHUB_LOGIN = solution.Candidate.GithubLogin
};
var info = await client.RunBuild(config.TeamcityAutotestBuildId, args);
solution.AutocheckBuildId = info.id;
logger.LogInformation($"build id: #{info.id} ({info.webUrl})");
}
db.SaveChanges();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment