Skip to content

Commit

Permalink
Finish Advanced usage part
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibault Gouala committed Mar 1, 2018
1 parent 6a80017 commit b8b6cec
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 1 deletion.
120 changes: 120 additions & 0 deletions sphinx/source/advanced/continuous-integration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
Continuous Integration
======================

.Peek was designed to provide a quick feedback to Unity users about the status of their project, but also to be nicely integrated
on any Continuous Integration pipeline.

Through the :ref:`doc_advanced_programmatic-control` of DotPeek, you can ensure that your CI run .DotPeek with consistant settings.

Hereunder are more ways of optimizing .Peek usage on a CI machine.

Getting informed when build report is ready
-------------------------------------------

For optimized performances, .Peek generate your build report on threads. It means that when you call Unity on the command line,
you should not do it with the parameter `-quit`. This would quit the editor as soon as the Unity editor main thread finished
the task it was assigned on the command line.

To allow you to quit unity after the report was generated, .Peek provides you the interface `IDotPeekListener`. You first need
to implement it :

.. code-block:: c#
private class DotPeekListener : IDotPeekListener
{
public void DoBuildReportGenerated(string reportAbsolutePath)
{
//do here what you want after the build is generated
}
}
And then to provide this listener to .Peek :

.. code-block:: c#
DotPeek.Instance.Listener = new DotPeekListener();
Below is a whole functional usage example :

.. code-block:: c#
using UnityEditor;
using WellFired.Peek.Application.Unity.Editor;
[InitializeOnLoad]
public static class DotPeekInitializer
{
static DotPeekInitializer()
{
DotPeek.Instance.Listener = new DotPeekListener();
}
private class DotPeekListener : IDotPeekListener
{
public void DoBuildReportGenerated(string reportAbsolutePath)
{
//Will quit Unity with error code 0, indicating no error happened.
EditorApplication.Exit(0);
}
}
}
The parameter ``reportAbsolutePath`` is the path to your freshly generated report. It can be useful if you want to send the report
to an other machine for example (website server, NAS, ...)

VCS Version
-----------

If .Peek option is enabled and your project versions are tracked through GIT or SVN, the commid id at build time will be
automatically saved with your generated report. This is done through the terminal of your machine.

If for any reason .Peek cannot access the terminal of the machine it is running on, you can provide an implementation of
``IVCS`` and return to .Peek the value you want :

.. code-block:: c#
private interface IVCS
{
string GetCommitId();
}
This can be useful for example if the access to the commit id can be done only through the parameters passed to Unity through
the command line. Here an illustration :

The command being called :

.. code-block:: c#
/Applications/Unity/Unity.app/Contents/MacOS/Unity -VCS aa2e32w -batchmode -executeMethod MyEditorScript.PerformBuild
The implementation of the static function being called in Unity :

.. code-block:: c#
using UnityEditor;
class MyEditorScript
{
static void PerformBuild ()
{
DotPeek.Instance.CustomVCS = new DotPeekVCS();
string[] scenes = { "Assets/MyScene.unity" };
BuildPipeline.BuildPlayer(scenes, ...);
}
}
with ``DotPeekVCS`` implemented this way :

.. code-block:: c#
private class DotPeekVCS : IVCS
{
public string GetCommitId()
{
var args = Environment.GetCommandLineArgs().ToList();
var optionPosition = Environment.GetCommandLineArgs().ToList().IndexOf("-VCS");
var vcsCommitId = args[optionPosition + 1];
return vcsCommitId;
}
}
85 changes: 85 additions & 0 deletions sphinx/source/advanced/programmatic-control.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.. _doc_advanced_programmatic-control:

Programmatic Control
====================

Settings
--------

All the settings you can access through .Peek UI are available through code and can be read or overwritten.

To do so :

1. Add the required using :

.. code-block:: c#
using WellFired.Peek.Application.Unity.Editor;
2. Access and modify your .Peek personal options (stored on your computer only, see :ref:`doc_ui-overview_settings-page` for more information) :

.. code-block:: c#
DotPeek.Instance.Storage.PersonalOptions.BuildReportPath = "../DotPeekReports";
DotPeek.Instance.Storage.PersonalOptions.AutomaticallyShowReportAfterBuild = false;
3. Access and modify your .Peek team-shared options :

.. code-block:: c#
DotPeek.Instance.Storage.TeamOptions.TrackVCSVersion = false;
4. Save your changes to ensure .Peek can access updated settings :

.. code-block:: c#
DotPeek.Instance.Storage.Save();
.. warning:: Saving step cannot be ommited. Indeed, it will ensure settings that were modified are written to the disk and
are accessible to the whole .Peek application.

.. tip:: .Peek Storage is thread safe, so the thread you are accessing it from does not matter.

Callbacks Order
---------------

DotPeek build generation is driven by two callbacks automatically called by Unity when building :

* `IPreprocessBuild.OnPreprocessBuild <https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuild.html>`_ which happens just
before the build starts.

When it is called, .Peek will start counting the time used to build and get the VCS commit ID of your project.
Note that if beforehand some files were not commited, .Peek will add *-unsync* behind the commit ID.

|
* `IPostprocessBuild.OnPostprocessBuild <https://docs.unity3d.com/ScriptReference/Build.IPostprocessBuild.html>`_ which is
called once the build is done.

When it is called, the time elapsed to make the build is saved and the report generated. Note that at that moment,
all the files that are in the project, but were not added to the build are considered as unused assets.

Different modules in your project may use these callbacks, and Unity will decide which one to call first based on
`IPreprocessBuild.callbackOrder and IPostprocessBuild.callbackOrder <https://docs.unity3d.com/ScriptReference/Build.IOrderedCallback.html>`_

.Peek by default try to be called as early as possible and as late as possible, but you can programmatically change this
behaviour by :

1. Adding the required using :

.. code-block:: c#
using WellFired.Peek.Application.Unity.Editor;
2. Modifying the callback order :

.. code-block:: c#
DotPeek.Instance.Storage.TeamOptions.PrebuildCallbackOrder = int.MinValue + 1;
DotPeek.Instance.Storage.TeamOptions.PostbuildCallbackOrder = int.MaxValue - 1;
4. Saving your changes to ensure .Peek can access updated settings :

.. code-block:: c#
DotPeek.Instance.Storage.Save();
8 changes: 8 additions & 0 deletions sphinx/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ The main documentation for the site is organized into the following sections:
ui-overview/build-report-panels
ui-overview/settings-page

.. toctree::
:maxdepth: 2
:caption: Advanced
:name: sec-advanced

advanced/programmatic-control
advanced/continuous-integration

.. toctree::
:maxdepth: 2
:caption: Class API reference
Expand Down
2 changes: 1 addition & 1 deletion sphinx/source/ui-overview/settings-page.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Build reports location
Track VCS version |team|
If enable and SVN or GIT is installed on your computer, the version of the commit you are building will appear in the report.

If your workspace differed with the VCS version, then *-unsync* will be added to the version (such as : **Commit Id** *4baa424-unsync*).
If not all your modification are committed, then *-unsync* will be added to the version (such as : **Commit Id** *4baa424-unsync*).

Windows users may need to ensure these VCS are installed on the command line. Computers not supporting it will simply display
**Commit Id** *unknow* no matter this option is enabled or not.
Expand Down

0 comments on commit b8b6cec

Please sign in to comment.