Skip to content

Commit

Permalink
Readme & changelog files in build folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Team-on committed Dec 26, 2020
1 parent a31a188 commit 00e8561
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
78 changes: 78 additions & 0 deletions Editor/BuildManager/BuildPipeline/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,65 @@ static void Build(BuildManagerSettings settings, BuildSequence sequence) {
}

static void PostBuild(BuildSequence sequence) {
bool isNeedChangelogFile = usedChangelog.versions.Count != 0;
bool isNeedReadmeFile = !string.IsNullOrEmpty(usedChangelog.readme);
string changelogContent = "";
string readmeContent = usedChangelog.readme;

if (isNeedChangelogFile) {
StringBuilder sb = new StringBuilder();

ChangelogData.ChangelogEntryType lastType;
ChangelogData.ChangelogEntryScope lastScope;


for (int i = usedChangelog.versions.Count - 1; i >= 0; --i) {
lastType = (ChangelogData.ChangelogEntryType)255;
lastScope = (ChangelogData.ChangelogEntryScope)255;
ChangelogData.ChangelogVersionEntry version = usedChangelog.versions[i];

if(i != usedChangelog.versions.Count - 1) {
sb.Append("---------- \n");

}
sb.Append("# ");
sb.Append(version.GetVersionHeader());
sb.Append("\n");

sb.Append(version.descriptionText);
sb.Append("\n\n");

for (int j = 0; j < version.notes.Count; ++j) {
ChangelogData.ChangelogNoteEntry note = version.notes[j];

if(lastType != note.type) {
if(lastType != (ChangelogData.ChangelogEntryType)255)
sb.Append("\n");
lastType = note.type;
lastScope = (ChangelogData.ChangelogEntryScope)255;
sb.Append("## ");
sb.Append(note.type);
sb.Append(": \n");
}

if (lastScope != note.scope) {
lastScope = note.scope;
sb.Append("### ");
sb.Append(note.scope);
sb.Append(": \n");
}

sb.Append(" * ");
sb.Append(note.text);
sb.Append("\n");
}

sb.Append("\n");
}

changelogContent = sb.ToString();
}

for (byte i = 0; i < sequence.builds.Count; ++i) {
if (!sequence.builds[i].isEnabled)
continue;
Expand Down Expand Up @@ -125,6 +184,25 @@ static void PostBuild(BuildSequence sequence) {
process.Start();
}
#endif

if(sequence.builds[i].targetGroup == BuildTargetGroup.Standalone) {
string path = Path.Combine(sequence.builds[i].outputRoot + GetPathWithVars(sequence.builds[i], sequence.builds[i].middlePath)).Replace(@"/", @"\");
path = path.Substring(0, path.LastIndexOf("\\"));

if (isNeedChangelogFile) {
File.WriteAllText(
Path.Combine(path, "Changelog.txt"),
changelogContent
);
}

if (isNeedReadmeFile) {
File.WriteAllText(
Path.Combine(path, "Readme.txt"),
readmeContent
);
}
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Editor/Changelog/ChangelogData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class ChangelogData {

public List<ChangelogVersionEntry> versions = new List<ChangelogVersionEntry>() { new ChangelogVersionEntry() };
[TextArea(3, 10)] public string readme;

public ChangelogVersionEntry GetLastVersion() {
if (versions.Count == 0)
Expand Down Expand Up @@ -68,6 +69,8 @@ public class ChangelogVersionEntry {
public string date;
public string updateName;

public string descriptionText;

public List<ChangelogNoteEntry> notes = new List<ChangelogNoteEntry>();

public string GetVersionHeader() {
Expand Down
5 changes: 4 additions & 1 deletion Editor/Window/BuildManagerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ void DrawChangelogInfo() {
scrollPosChangelog = EditorGUILayout.BeginScrollView(scrollPosChangelog/*, GUILayout.Height(800f)*/);
++EditorGUI.indentLevel;


EditorGUILayout.LabelField("Readme");
changelog.readme = EditorGUILayout.TextArea(changelog.readme);
GUILayout.Space(10f);

EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Changelog file:", GUILayout.Width(100));
if (GUILayout.Button($"Add version"))
Expand Down Expand Up @@ -178,6 +180,7 @@ void DrawChangelogInfo() {
EditorGUILayout.EndHorizontal();

version.updateName = EditorGUILayout.TextField("Update name", version.updateName);
version.descriptionText = EditorGUILayout.TextField("Description", version.descriptionText);

EditorGUILayout.LabelField("Notes: ");

Expand Down

0 comments on commit 00e8561

Please sign in to comment.