[legacy_annotation] Make an example recipe

The cmd now emits actual @@@annotation now.

R=iannucci

Bug: 1017831
Change-Id: Idc14f9e0a266945bbf40c97f559195be3a9a401a
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/2254486
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
Auto-Submit: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
diff --git a/README.recipes.md b/README.recipes.md
index a75a86a..42a643f 100644
--- a/README.recipes.md
+++ b/README.recipes.md
@@ -112,7 +112,7 @@
   * [json:tests/add_json_log](#recipes-json_tests_add_json_log)
   * [led:tests/full](#recipes-led_tests_full)
   * [led:tests/no_exist](#recipes-led_tests_no_exist)
-  * [legacy_annotation:tests/full](#recipes-legacy_annotation_tests_full)
+  * [legacy_annotation:examples/full](#recipes-legacy_annotation_examples_full)
   * [milo:examples/full](#recipes-milo_examples_full)
   * [path:examples/full](#recipes-path_examples_full)
   * [platform:examples/full](#recipes-platform_examples_full)
@@ -3670,11 +3670,11 @@
 [DEPS](/recipe_modules/led/tests/no_exist.py#5): [led](#recipe_modules-led), [step](#recipe_modules-step)
 
 &mdash; **def [RunSteps](/recipe_modules/led/tests/no_exist.py#10)(api):**
-### *recipes* / [legacy\_annotation:tests/full](/recipe_modules/legacy_annotation/tests/full.py)
+### *recipes* / [legacy\_annotation:examples/full](/recipe_modules/legacy_annotation/examples/full.py)
 
-[DEPS](/recipe_modules/legacy_annotation/tests/full.py#5): [legacy\_annotation](#recipe_modules-legacy_annotation), [proto](#recipe_modules-proto), [step](#recipe_modules-step)
+[DEPS](/recipe_modules/legacy_annotation/examples/full.py#5): [legacy\_annotation](#recipe_modules-legacy_annotation), [raw\_io](#recipe_modules-raw_io), [step](#recipe_modules-step)
 
-&mdash; **def [RunSteps](/recipe_modules/legacy_annotation/tests/full.py#15)(api):**
+&mdash; **def [RunSteps](/recipe_modules/legacy_annotation/examples/full.py#18)(api):**
 ### *recipes* / [milo:examples/full](/recipe_modules/milo/examples/full.py)
 
 [DEPS](/recipe_modules/milo/examples/full.py#7): [milo](#recipe_modules-milo)
diff --git a/recipe_modules/legacy_annotation/tests/full.expected/basic.json b/recipe_modules/legacy_annotation/examples/full.expected/basic.json
similarity index 87%
rename from recipe_modules/legacy_annotation/tests/full.expected/basic.json
rename to recipe_modules/legacy_annotation/examples/full.expected/basic.json
index 9bba9a7..380a54d 100644
--- a/recipe_modules/legacy_annotation/tests/full.expected/basic.json
+++ b/recipe_modules/legacy_annotation/examples/full.expected/basic.json
@@ -57,8 +57,9 @@
       "--output",
       "[CLEANUP]/tmp_tmp_1/sub_build.pb",
       "--",
-      "echo",
-      "@@@BUILD_STEP@Hi Sub Annotation@@@"
+      "python",
+      "-u",
+      "RECIPE[recipe_engine::legacy_annotation:examples/full].resources/anno.py"
     ],
     "env": {
       "MAC_CHROMIUM_TMPDIR": "[CLEANUP]/tmp_tmp_2",
@@ -67,14 +68,7 @@
       "TMP": "[CLEANUP]/tmp_tmp_2",
       "TMPDIR": "[CLEANUP]/tmp_tmp_2"
     },
-    "name": "sub annotation"
-  },
-  {
-    "cmd": [
-      "echo",
-      "{\n\"id\": \"1\", \n\"status\": \"SUCCESS\", \n\"steps\": [\n{\n\"name\": \"Hi Sub Annotation\", \n\"status\": \"SUCCESS\"\n}\n]\n}"
-    ],
-    "name": "print sub build"
+    "name": "run annotation script"
   },
   {
     "name": "$result"
diff --git a/recipe_modules/legacy_annotation/tests/full.py b/recipe_modules/legacy_annotation/examples/full.py
similarity index 64%
rename from recipe_modules/legacy_annotation/tests/full.py
rename to recipe_modules/legacy_annotation/examples/full.py
index aa25e59..a4fb0c7 100644
--- a/recipe_modules/legacy_annotation/tests/full.py
+++ b/recipe_modules/legacy_annotation/examples/full.py
@@ -1,34 +1,35 @@
-# Copyright 2018 The LUCI Authors. All rights reserved.
+# Copyright 2020 The LUCI Authors. All rights reserved.
 # Use of this source code is governed under the Apache License, Version 2.0
 # that can be found in the LICENSE file.
 
 DEPS = [
   'legacy_annotation',
-  'proto',
+  'raw_io',
   'step',
 ]
 
+import textwrap
+
 from PB.go.chromium.org.luci.buildbucket.proto import build as build_pb2
 from PB.go.chromium.org.luci.buildbucket.proto import common as common_pb2
 from PB.go.chromium.org.luci.buildbucket.proto import step as step_pb2
 
+
 def RunSteps(api):
-  ret = api.legacy_annotation('sub annotation',
-                              ['echo', '@@@BUILD_STEP@Hi Sub Annotation@@@'])
-  api.step('print sub build',
-           ['echo', api.proto.encode(ret.step.sub_build, 'JSONPB')])
+  api.legacy_annotation('run annotation script', cmd=[
+      'python', '-u', api.resource('anno.py')])
 
 
 def GenTests(api):
   yield (
     api.test('basic') +
-    api.step_data('sub annotation', api.step.sub_build(
+    api.step_data('run annotation script', api.step.sub_build(
       build_pb2.Build(
         id=1,
         status=common_pb2.SUCCESS,
         steps=[
           step_pb2.Step(name='Hi Sub Annotation', status=common_pb2.SUCCESS),
-        ]
+        ],
       )
     ))
-  )
+  )
\ No newline at end of file
diff --git a/recipe_modules/legacy_annotation/examples/full.resources/anno.py b/recipe_modules/legacy_annotation/examples/full.resources/anno.py
new file mode 100644
index 0000000..3e9b708
--- /dev/null
+++ b/recipe_modules/legacy_annotation/examples/full.resources/anno.py
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+# Copyright 2020 The LUCI Authors. All rights reserved.
+# Use of this source code is governed under the Apache License, Version 2.0
+# that can be found in the LICENSE file.
+
+from __future__ import print_function
+
+import textwrap
+
+anno = textwrap.dedent('''
+  @@@SEED_STEP@Initial Step@@@
+  @@@STEP_CURSOR@Initial Step@@@
+
+  @@@STEP_STARTED@@@
+  @@@STEP_LOG_LINE@$debug@Aloha@@@
+  @@@STEP_LOG_LINE@$debug@This is the very first step!@@@
+  @@@STEP_LOG_LINE@foo@This is the log for log name foo!@@@
+  @@@STEP_LOG_END@foo@@@
+  @@@STEP_LOG_END@$debug@@@
+  @@@STEP_TEXT@Hi! This is the first step!@@@
+  @@@STEP_CLOSED@@@
+
+  @@@SEED_STEP@Step Nested@@@
+  @@@SEED_STEP@Step Nested.Child 1@@@
+  @@@STEP_CURSOR@Step Nested.Child 1@@@
+  @@@STEP_STARTED@@@
+  @@@STEP_NEST_LEVEL@1@@@
+  @@@STEP_LOG_LINE@$debug@Hey there!@@@
+  @@@STEP_LOG_LINE@$debug@You are in a child step now!@@@
+  @@@STEP_LOG_END@$debug@@@
+  @@@STEP_CLOSED@@@
+  @@@SEED_STEP@Step Nested.Child 💣@@@
+  @@@STEP_CURSOR@Step Nested.Child 💣@@@
+  @@@STEP_STARTED@@@
+  @@@STEP_NEST_LEVEL@1@@@
+  @@@STEP_LOG_LINE@$debug@Explosion!!!!@@@
+  @@@STEP_LOG_END@$debug@@@
+  @@@STEP_CLOSED@@@
+  @@@STEP_CURSOR@Step Nested@@@
+  @@@STEP_STARTED@@@
+  @@@STEP_CLOSED@@@
+
+  @@@SEED_STEP@Set Property@@@
+  @@@STEP_CURSOR@Set Property@@@
+  @@@STEP_STARTED@@@
+  @@@STEP_LOG_LINE@$debug@Try Setting property@@@
+  @@@STEP_LOG_END@$debug@@@
+  @@@SET_BUILD_PROPERTY@obj_prop@{"hi": "there"}@@@
+  @@@SET_BUILD_PROPERTY@str_prop@"hi"@@@
+  @@@STEP_CLOSED@@@
+
+  @@@SEED_STEP@Failed Step@@@
+  @@@STEP_CURSOR@Failed Step@@@
+  @@@STEP_STARTED@@@
+  @@@STEP_LOG_LINE@$debug@This step has failed@@@
+  @@@STEP_LOG_END@$debug@@@
+  @@@STEP_FAILURE@@@
+  @@@STEP_CLOSED@@@
+''').splitlines()
+
+for line in anno:
+  if line:
+    print(line)
\ No newline at end of file