Finalization script, step 1.

- cleanup
- revert previous commits
- vndk + resources + sdk finalization + test
- create cls
- send to Gerrit
- (tbd) submit

Bug: 243966946
Test: run scripts locally

Change-Id: Icd4f07c64c2ef93831dc5fc7de2d5e832604e88d
diff --git a/finalize-step-1.sh b/finalize-step-1.sh
new file mode 100755
index 0000000..857b47f
--- /dev/null
+++ b/finalize-step-1.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+# Automation for finalize_branch_for_release.sh.
+# Sets up local environment, runs the finalization script and submits the results.
+# WIP:
+# - does not submit, only sends to gerrit.
+
+# set -ex
+
+function revert_local_changes() {
+    repo forall -c '\
+        git checkout . ; git clean -fdx ;\
+        git checkout @ ; git b fina-step1 -D ; git reset --hard; \
+        repo start fina-step1 ; git checkout @ ; git b fina-step1 -D ;\
+        previousHash="$(git log --format=%H --no-merges --max-count=1 --grep ^FINALIZATION_STEP_1_SCRIPT_COMMIT)" ;\
+        if [[ $previousHash ]]; then git revert --no-commit $previousHash ; fi ;'
+}
+
+function finalize_step_1_main() {
+    local top="$(dirname "$0")"/../..
+
+    repo selfupdate
+
+    revert_local_changes
+
+    # vndk etc finalization
+    source $top/build/make/finalize_branch_for_release.sh
+
+    # move all changes to fina-step1 branch and commit with a robot message
+    repo forall -c 'if [[ $(git status --short) ]]; then repo start fina-step1 ; git add -A . ; git commit -m FINALIZATION_STEP_1_SCRIPT_COMMIT -m WILL_BE_AUTOMATICALLY_REVERTED ; repo upload --cbr --no-verify -t -y . ; fi'
+}
+
+finalize_step_1_main