Skip to content

Commit ce51d69

Browse files
authored
Merge pull request #7 from Unity-Technologies/ghactions
Fix building on non-windows, package with npm, reenable tests, add GitHub Actions support
2 parents ab760af + 3a8a222 commit ce51d69

File tree

16 files changed

+541
-168
lines changed

16 files changed

+541
-168
lines changed

.appveyor.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ environment:
66
# Don't report back to the mothership
77
DOTNET_CLI_TELEMETRY_OPTOUT: 1
88

9-
install:
10-
- ps: scripts\Get-Deps.ps1
11-
129
before_build:
13-
- dotnet --info
1410
- appveyor-retry dotnet restore -v Minimal
1511

1612
build_script:
17-
- dotnet build --no-restore -c %CONFIGURATION%
13+
- .\build -c %CONFIGURATION%
1814

1915
test:
2016
assemblies:
@@ -25,13 +21,10 @@ test:
2521
- DoNotRunOnAppVeyor
2622

2723
after_test:
28-
- : |
29-
dotnet pack --no-restore -c %CONFIGURATION%
30-
set OUTDIR=build\npm
31-
set SRCDIR=build\packages
32-
mkdir %OUTDIR% >nul 2>nul || ver>nul
33-
for /f "delims=" %%d in ('dir /b /a:d %SRCDIR%') do (pushd %SRCDIR%\%%d && for /f "delims=" %%f in ('call npm pack --quiet') do move %%f ..\..\npm\%%f && popd)
24+
- .\pack -c %CONFIGURATION%
3425

3526
artifacts:
36-
- path: build\npm\*.tgz
37-
name: Npm
27+
- path: upm-ci~\packages\*
28+
name: npm
29+
- path: build\nuget\**\*.nupkg
30+
name: nuget

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trim_trailing_whitespace=true
1010
indent_style=tab
1111
indent_size=tab
1212

13-
[*.{config,csproj,json,nuspec,props,resxtargets,targets,sh}]
13+
[*.{config,csproj,json,nuspec,props,resxtargets,targets,sh,cmd}]
1414
indent_style=space
1515
indent_size=2
1616
tab_width=2

.github/workflows/build.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Build, Test, Pack
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
- name: Setup .NET Core
11+
uses: actions/setup-dotnet@v1
12+
with:
13+
dotnet-version: 2.2.301
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v1.1.0
16+
- name: Build
17+
env:
18+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
19+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
20+
run: ./build.sh -r
21+
- name: Test
22+
env:
23+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
24+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
25+
run: ./test.sh -r
26+
- name: Pack
27+
env:
28+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
29+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
30+
run: ./pack.sh -r

.github/workflows/publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build, Test, Pack, Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- v[0-9]+.[0-9]+*
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v1
13+
- name: Setup .NET Core
14+
uses: actions/setup-dotnet@v1
15+
with:
16+
dotnet-version: 2.2.301
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v1.1.0
19+
- name: Build
20+
env:
21+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
22+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
23+
run: ./build.sh -r
24+
- name: Test
25+
env:
26+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
27+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
28+
run: ./test.sh -r
29+
- name: Pack
30+
env:
31+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
32+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
33+
run: ./pack.sh -r
34+
- name: Publish
35+
env:
36+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
37+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
run: ./publish.sh -r -g

README.md

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,96 @@
1+
![](https://github.com/unity-technologies/com.unity.editor.tasks/workflows/Build,%20Test,%20Pack/badge.svg)
2+
13
# About the Tasks package
24

3-
Unity.Editor.Tasks is a TPL-based (Task Parallel Library, or System.Threading.Tasks) task management library.
5+
Unity.Editor.Tasks is a TPL-based task management library.
46

5-
This repository is a subset of the functionality in [Git for Unity](https://github.com/Unity-Technologies/Git-for-Unity) repository, specifically the `Threading`, `OutputProcessors`, `Tasks`, `Process` and `IO` directories, as well as various helper classes found in [](https://github.com/Unity-Technologies/Git-for-Unity/tree/master/src/com.unity.git.api/Api).
7+
This repository is a subset of the functionality in the [Git for Unity](https://github.com/Unity-Technologies/Git-for-Unity) repository, specifically the `Threading`, `OutputProcessors`, `Tasks`, `Process` and `IO` directories, as well as various helper classes found in the [Api](https://github.com/Unity-Technologies/Git-for-Unity/tree/master/src/com.unity.git.api/Api) source directory.
68

79
It's been split up for easier testing and consumption by the Git package and any other packages, libraries or apps that wish to use it.
810

11+
It is essentially a wrapper of `System.Threading.Tasks.Task` objects, with custom schedulers providing easy execution of tasks in a variety of scenarios:
12+
13+
- UI: tasks can be scheduled to the UI thread, which uses `EditorApplication.delayCall`
14+
15+
- Exclusive/Concurrent: A pair of synchronized schedulers allow for a one writer/many readers scenario, where any task with an Exclusive affinity is guaranteed to run on its own without any other Exclusive or Concurrent affinity tasks executing at the same time. Concurrent affinity tasks can run with other tasks any affinity except Exclusive.
16+
17+
This allows tasks to safely execute code that requires locking resources without worrying about other threads touching the same resources.
18+
19+
- None: tasks run on the default scheduler (threadpool) without constraints.
20+
- LongRunning: tasks run on the default scheduler (threadpool), but the task management system doesn't expect them to finish in a short time and doesn't impose task timeouts (if the task supports such a thing);
21+
22+
It provides easy chaining of tasks with a rx.net-like API that allows data flow from one task to the other, progress reporting, catch and finally handlers, support for wrapping async/await methods and for ensuring they run outside of play mode, and ready-made tasks for running processes and processing/streaming their output.
23+
24+
Standard .NET async methods can be integrated into this library and executed with specific affinities using the `TPLTask` class. Similarly, going from an Editor Task to the async/await model is just a matter of awaiting the underlying `Task` property.
25+
26+
27+
## Usage examples
28+
29+
There are a number of tests in `src/com.unity.editor.tasks/Tests/Editor` that can provide useful guidance.
30+
31+
### Downloading a bunch of things in the background
32+
33+
```
34+
// you'll want to keep one instance of this around.
35+
// Initialization must happen on the UI thread so it knows how to schedule things to it
36+
var taskManager = new TaskManager.Initialize();
37+
38+
// the Downloader is a TaskQueue-type task which handles firing up a series of concurrent tasks,
39+
// aggregating all of the data from each of the tasks and returning it all together
40+
var downloader = new Downloader(taskManager);
41+
downloader.QueueDownload("http://something", "directory/to/store/file", retryCount: 2);
42+
43+
downloader.Progress(progress => { ShowProgress(progress.Message, progress.InnerProgress?.Message, progress.Percentage); });
44+
45+
downloader.OnStart += __ => logger.Info("Downloading assets...");
46+
downloader.OnEnd += (___, __, success, ex) => logger.Info($"Downloader is done with result: {success}");
47+
48+
downloader.FinallyInUI((success, exception, results) => {
49+
// do something with all the things that were downloaded
50+
});
951
52+
downloader.Start();
53+
54+
```
55+
56+
57+
### Chaining tasks
58+
59+
```
60+
void ShowProgress(string title, string message, float pct) => TaskManager.RunInUI(() => EditorUtility.DisplayProgressBar(title, message, pct), "Updating progress");
61+
62+
// you'll want to keep one instance of this around.
63+
// Initialization must happen on the UI thread so it knows how to schedule things to it
64+
var taskManager = new TaskManager.Initialize();
65+
66+
EditorUtility.DisplayProgressBar("Starting", "", 0);
67+
var chainOfTasks = new FuncTask(taskManager, () => "Do something critical and return a string.", affinity: TaskAffinity.Exclusive)
68+
69+
// each task has its own progress event/handler.
70+
.Progress(progress => ShowProgress(progress.Message, progress.InnerProgress?.Message, progress.Percentage))
71+
72+
// do something with the value the previous task produced, with Concurrent affinity.
73+
// This won't run if the previous one failed
74+
.Then(str => str.ToUpper())
75+
76+
.Progress(progress => ShowProgress(progress.Message, progress.InnerProgress?.Message, progress.Percentage))
77+
78+
// finally handlers will always be called. Always end a chain with a Finally* handler!
79+
.FinallyInUI((success, exception, value) => {
80+
EditorUtility.ClearProgressBar();
81+
82+
if (success) {
83+
// do something on success
84+
EditorUtility.DisplayDialog("All done", value);
85+
} else {
86+
Debug.LogException(exception);
87+
}
88+
});
89+
90+
// start executing the whole thing
91+
chainOfTasks.Start();
92+
93+
```
1094

1195
## The History
1296

@@ -21,5 +105,7 @@ These days, Unity supports modern .NET and can compile all this code just fine,
21105
**[MIT](LICENSE)**
22106

23107
Copyright (c) 2019 Unity Technologies
108+
24109
Copyright (c) 2016-2019 Andreia Gaita
110+
25111
Copyright (c) 2016-2018 GitHub

build.cmd

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,51 @@ SET CONFIGURATION=Release
99
SET PUBLIC=""
1010
SET BUILD=0
1111
set UPM=0
12+
set UNITYVERSION=2019.2
1213

1314
:loop
1415
IF NOT "%1"=="" (
15-
IF "%1"=="-p" (
16-
SET PUBLIC=/p:PublicRelease=true
17-
)
18-
IF "%1"=="--public" (
19-
SET PUBLIC=/p:PublicRelease=true
20-
)
21-
IF "%1"=="-b" (
22-
SET BUILD=1
23-
)
24-
IF "%1"=="--build" (
25-
SET BUILD=1
26-
)
27-
IF "%1"=="-d" (
28-
SET CONFIGURATION=Debug
29-
)
30-
IF "%1"=="--debug" (
31-
SET CONFIGURATION=Debug
32-
)
33-
IF "%1"=="-r" (
34-
SET CONFIGURATION=Release
35-
)
36-
IF "%1"=="--release" (
37-
SET CONFIGURATION=Release
38-
)
39-
IF "%1"=="-u" (
40-
SET UPM=1
41-
)
42-
IF "%1"=="--upm" (
43-
SET UPM=1
44-
)
16+
IF "%1"=="-p" (
17+
SET PUBLIC=-p:PublicRelease=true
18+
)
19+
IF "%1"=="--public" (
20+
SET PUBLIC=-p:PublicRelease=true
21+
)
22+
IF "%1"=="-b" (
23+
SET BUILD=1
24+
)
25+
IF "%1"=="--build" (
26+
SET BUILD=1
27+
)
28+
IF "%1"=="-d" (
29+
SET CONFIGURATION=Debug
30+
)
31+
IF "%1"=="--debug" (
32+
SET CONFIGURATION=Debug
33+
)
34+
IF "%1"=="-r" (
35+
SET CONFIGURATION=Release
36+
)
37+
IF "%1"=="--release" (
38+
SET CONFIGURATION=Release
39+
)
40+
IF "%1"=="-u" (
41+
SET UPM=1
42+
)
43+
IF "%1"=="--upm" (
44+
SET UPM=1
45+
)
46+
IF "%1"=="-c" (
47+
SET CONFIGURATION=%2
4548
SHIFT
46-
GOTO :loop
49+
)
50+
SHIFT
51+
GOTO :loop
52+
)
53+
54+
if "%APPVEYOR%" == "" (
55+
dotnet restore
4756
)
4857

49-
dotnet restore
5058
dotnet build --no-restore -c %CONFIGURATION% %PUBLIC%
59+

build.sh

100644100755
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/bin/sh -eu
1+
#!/bin/bash -eu
22
{ set +x; } 2>/dev/null
3-
SOURCE="${BASH_SOURCE[0]}"
3+
SOURCE=$0
44
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
55

66
OS="Mac"
@@ -12,45 +12,50 @@ CONFIGURATION=Release
1212
PUBLIC=""
1313
BUILD=0
1414
UPM=0
15+
UNITYVERSION=2019.2
16+
YAMATO=0
1517

1618
while (( "$#" )); do
1719
case "$1" in
1820
-d|--debug)
1921
CONFIGURATION="Debug"
20-
shift
2122
;;
2223
-r|--release)
2324
CONFIGURATION="Release"
24-
shift
2525
;;
2626
-p|--public)
27-
PUBLIC="/p:PublicRelease=true"
28-
shift
27+
PUBLIC="-p:PublicRelease=true"
2928
;;
3029
-b|--build)
3130
BUILD=1
32-
shift
3331
;;
3432
-u|--upm)
3533
UPM=1
34+
;;
35+
-c)
3636
shift
37+
CONFIGURATION=$1
3738
;;
3839
-*|--*=) # unsupported flags
3940
echo "Error: Unsupported flag $1" >&2
4041
exit 1
41-
;;
42-
*)
43-
shift
4442
;;
4543
esac
44+
shift
4645
done
4746

48-
if [[ x"$OS" == x"Windows" && x"$PUBLIC" != x"" ]]; then
49-
PUBLIC="/$PUBLIC"
47+
if [[ x"${YAMATO_JOB_ID:-}" != x"" ]]; then
48+
YAMATO=1
49+
export GITLAB_CI=1
50+
export CI_COMMIT_TAG="${GIT_TAG:-}"
51+
export CI_COMMIT_REF_NAME="${GIT_BRANCH:-}"
5052
fi
5153

5254
pushd $DIR >/dev/null 2>&1
53-
dotnet build-server shutdown >/dev/null 2>&1 || true
54-
dotnet restore
55+
56+
if [[ x"${APPVEYOR:-}" == x"" ]]; then
57+
dotnet restore
58+
fi
5559
dotnet build --no-restore -c $CONFIGURATION $PUBLIC
60+
5661
popd >/dev/null 2>&1

clean.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh -eu
1+
#!/bin/bash -eu
22
{ set +x; } 2>/dev/null
33
SOURCE="${BASH_SOURCE[0]}"
44
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

0 commit comments

Comments
 (0)