Exemple #1
0
    public void PerformRelease(BuildState state, AbsolutePath changeLogFile, Action <BuildType, string> buildAction)
    {
        var releaseId        = Guid.NewGuid();
        var releaseBranchTag = "_release-state-" + releaseId;
        var stagingBranchTag = "_staging-state-" + releaseId;

        EnsureOnReleaseStagingBranch(state);

        GitTools.Tag(stagingBranchTag, state.ReleaseStagingBranch);

        try
        {
            if (ChangeLogGenerator.TryPrepareChangeLogForRelease(state, changeLogFile, out var sectionFile))
            {
                GitTools.Commit($"Updated change log for release {state.Version.MajorMinorPatch}");
            }


            // record the current master branch state.
            // We will use that later to potentially undo any changes we made during that build.
            GitTools.Tag(releaseBranchTag, state.ReleaseTargetBranch);

            try
            {
                // this takes the current staging branch state and merges it into
                // the release branch (usually master). This changes the active
                // branch of the working copy.
                GitTools.MergeRelease(state.ReleaseTargetBranch, state.ReleaseStagingBranch);

                // attempt to build the release again.
                ValidateBuild(buildAction, BuildType.Release, sectionFile);
            }
            catch
            {
                Logger.Error("Error: Unable to build the release on the release branch. Attempting to roll back changes on release branch.");
                GitTools.Reset(GitTools.ResetType.Hard, releaseBranchTag);
                GitTools.Checkout(stagingBranchTag);
                GitTools.ResetBranch(state.ReleaseStagingBranch, stagingBranchTag);
                throw;
            }
            finally
            {
                GitTools.DeleteTag(releaseBranchTag);
            }
        }
        catch
        {
            // In case of errors, roll back all commits and restore the current state
            // to be back on the release-staging branch.
            GitTools.Checkout(stagingBranchTag);
            GitTools.ResetBranch(state.ReleaseStagingBranch, stagingBranchTag);
            throw;
        }
        finally
        {
            GitTools.DeleteTag(stagingBranchTag);
        }
    }
Exemple #2
0
    public static bool TryPrepareChangeLogForRelease(BuildState state, AbsolutePath changeLogFile, out string sectionFile)
    {
        if (!File.Exists(changeLogFile))
        {
            sectionFile = default;
            return(false);
        }

        var(cl, section) = ChangeLogGenerator.UpdateChangeLogFile(changeLogFile, state.VersionTag, state.ReleaseTargetBranch);
        File.WriteAllText(changeLogFile, cl);
        sectionFile = Path.GetTempFileName();
        File.WriteAllText(sectionFile, section);
        return(true);
    }