Add canary nightly build job

Bug: twpowertools:20
Change-Id: I622c1d671ba8fc623a96ce5d92fd6edead6c90f1
diff --git a/.zuul.yaml b/.zuul.yaml
index a519e46..06f462c 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -10,8 +10,65 @@
       - "README.md"
       - "i18n-config.toml"
       - "cws/.*"
+      - "roles/cws-upload/*"
+      - "playbooks/nightly-build/*"
+
+- job:
+    name: infinitegforums-test-nightly-build
+    pre-run: playbooks/nightly-build/pre.yaml
+    run: playbooks/nightly-build/test.yaml
+    roles:
+      - zuul: zuul/jobs
+    vars:
+      credentials:
+        clientId: "testClientId"
+        refreshToken: "testRefreshToken"
+    files:
+      - "roles/cws-upload/*"
+      - "playbooks/nightly-build/*"
+
+- job:
+    name: infinitegforums-nightly-build
+    attempts: 1
+    pre-run: playbooks/nightly-build/pre.yaml
+    run: playbooks/nightly-build/run.yaml
+    roles:
+      - zuul: zuul/jobs
+    secrets:
+      - name: credentials
+        secret: credentials
 
 - project:
     check:
       jobs:
+        - infinitegforums-test-nightly-build
         - infinitegforums-lint
+    nightly-build:
+      jobs:
+        - infinitegforums-nightly-build
+
+- secret:
+    name: credentials
+    data:
+      clientId: !encrypted/pkcs1-oaep
+        - BtqF9JhXwLcyBhV5HV3MUllsAnZIrURsinAtYOADVGZ/YvYUZZsIPz3+2fFjdXCf7N1my
+          McgklSVMCQ7R/qTtb+oogs9vJ4XUNIJ/QWRKzKb/M3v5VgJpbQXiEgVjMl+a4bntfQuB2
+          nnBJacg63yp1VQDVbJRh1acb9BJB2zsxKHusJZnSZtrdZCXxUqCzVRYkJxtVfhVJpGJjo
+          WqOCUZFc4ibFHbcI5ZOpyaxUqBMHhL33blopuwL3TVw2CLD3YZrg2V/c8NcBItX8m1aTh
+          d3jM73uKc/DP4+xk2OUfH5Mld/UcIUiolvHo5/Fm+6tNhXCZE7tm84A6FQKMQOKrYkzWN
+          4BWJS/Aoiu1JJVawu5j1yuWzm+ZSmgGaRblsXSJeIq9YgYF1Fe8TdxP7pmp+OzgedJPIX
+          KHWqH8BVyocx5wEy6cMH69IgheTt4NcWvPP1IiLNGC7w6x9RYHKTPOYDzOhy1wRPH6sKh
+          Oop5IiUPiiHSntbrGTh6gdsNXEkx7+QVh8FBo6958JSzb1DwexGMitfDarRcKLg2OKuAf
+          zgS1V6Nv63JsPY070p5rYhG1zl9Fh83a7nfhLB36aQhKi0DxOtOYRjKIzLsv1nWs7we1A
+          GQT8VFNW/KZrSM8XsvqCO6IwVP5mOIT/4PWYdCXUsUUU4Sa+Fo/pmyvITuI0E8=
+      refreshToken: !encrypted/pkcs1-oaep
+        - RknxT9FyVpZAdWhmUS7NBdhIljU6KjjbchJvwFHPfJQEgRxakX+q2/KDPnDOc7eZ8kzQD
+          Hmow1OLLBWOeRhODe2ngeQWoVvHEBuSU5AaFP9UWG1hLnsT9JrGF8qc3fFBDwy5NVNvkR
+          h6fgw9hlRgfeVVBtYZ0c+BQNflKepYupXlpE26KrzlJudxgaXhVC7vze73aQ9PMNfDF9J
+          aUrPNyZ4k04DfPHOTq4hzDLko24rgNvWYUMI79wWI3dD/QMgCd2M2V2PxxPtEzY6WnV7N
+          ILbTHv6783MioDy+19/Om5ClhNDe35v/Mlh6JOYGAdE2MuP6bG5oPbc/FBcWna6sOI79n
+          L4UCqN6LDKs5floMJ8vUafAr7dEEOxHWcbe8rcaRf2ESJBUxLDvrUYk6+lIWwhxj3ASeL
+          dmYSPKjw55knzDYiL0AYeSTM2SM3Tsu1N3pE7U2ugmxRpt3tl32BUNuRZrd2FMdRRVCLa
+          K2JV0q7qQgx3w0lNSSqu+m5KVpeCWk6RVwG9NNzNEHFWN5U7x32K1y8bvFC2Uhzx1ZfT1
+          4k2r9cE/Y1aSQCWvpnlqYRqzn9S7s9YLXTlyXovAPfBnw/ff395qF0eappfFcqVNq8gqV
+          4FjvCYgmfIJsBVgeDCkjZQ1brwwK/5isYYvhOPUojS9iqfRvltFgeyRgY9ZSnE=
diff --git a/playbooks/nightly-build/pre.yaml b/playbooks/nightly-build/pre.yaml
new file mode 100644
index 0000000..c4463a2
--- /dev/null
+++ b/playbooks/nightly-build/pre.yaml
@@ -0,0 +1,5 @@
+- hosts: all
+  roles:
+    - role: ensure-genmanifest
+    - role: ensure-cws-upload
+      version: "2.0.1"
diff --git a/playbooks/nightly-build/run.yaml b/playbooks/nightly-build/run.yaml
new file mode 100644
index 0000000..a10991c
--- /dev/null
+++ b/playbooks/nightly-build/run.yaml
@@ -0,0 +1,6 @@
+- hosts: all
+  roles:
+    - role: cws-publish
+      vars:
+        extension_id: "phefpbdhiknkamngjffpnebaemanmihf"
+        dry_run: false
diff --git a/playbooks/nightly-build/test.yaml b/playbooks/nightly-build/test.yaml
new file mode 100644
index 0000000..73777c0
--- /dev/null
+++ b/playbooks/nightly-build/test.yaml
@@ -0,0 +1,6 @@
+- hosts: all
+  roles:
+    - role: cws-publish
+      vars:
+        extension_id: "phefpbdhiknkamngjffpnebaemanmihf"
+        dry_run: true
diff --git a/roles/cws-publish/defaults/main.yaml b/roles/cws-publish/defaults/main.yaml
new file mode 100644
index 0000000..4055a80
--- /dev/null
+++ b/roles/cws-publish/defaults/main.yaml
@@ -0,0 +1 @@
+dryrun: false
diff --git a/roles/cws-publish/tasks/main.yaml b/roles/cws-publish/tasks/main.yaml
new file mode 100644
index 0000000..5ab7d8d
--- /dev/null
+++ b/roles/cws-publish/tasks/main.yaml
@@ -0,0 +1,37 @@
+- name: Check extension_id, credentials.clientId, credentials.refreshToken are set
+  when: >
+    extension_id is not defined or credentials.clientId is not defined or
+    credentials.refreshToken is not defined
+  fail:
+    msg: "extension_id, credentials.clientId and credentials.refreshToken must be set"
+
+- name: Build extension
+  include_role:
+    name: build-extension
+  vars:
+    make_target: release_chromium_canary
+
+- name: Get name of the compiled ZIP file
+  ansible.builtin.shell:
+    cmd: "ls -Art | tail -n 1"
+    chdir: "{{ zuul.project.src_dir }}/out"
+  register: zip_file
+
+- name: Check the ZIP file name is non-empty
+  when: zip_file.stdout == ""
+  fail:
+    msg: "zip_file.stdout is empty"
+
+- name: Print ZIP file name
+  when: not (zip_file.stdout == "")
+  debug:
+    msg: "zip_file.stdout is \"{{ zip_file.stdout }}\""
+
+- name: Upload and publish the ZIP file to the Chrome Web Store
+  when: not (dry_run|bool)
+  ansible.builtin.command:
+    cmd: >
+      "chrome-webstore-upload upload --auto-publish --extension-id {{ extension_id }}
+      --source {{ zuul.project.src_dir|quote }}/out/{{ zip_file.stdout|quote }}
+      --client-id {{ credentials.clientId|quote }} --refresh-token {{ credentials.refreshToken|quote }}"
+  no_log: True