From 291a8df6d0b09cfccf442b7b7f425684c6505edf Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.uk>
Date: Tue, 5 Apr 2022 18:58:02 +0100
Subject: [PATCH] feat(role): add GitHub CLI (gh)

Based on https:
//github.com/cli/cli/blob/19427d8819e36021c877b6e4cd855e060433f6ef/docs/install_linux.md.

Fixes: #28
---
 main.yaml                        |  1 +
 roles/github-cli/tasks/main.yaml | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 roles/github-cli/tasks/main.yaml

diff --git a/main.yaml b/main.yaml
index afaf025d..2ab786e4 100644
--- a/main.yaml
+++ b/main.yaml
@@ -8,6 +8,7 @@
     - role: dconf
     - role: docker
     - role: fzf
+    - role: github-cli
     - role: gnome-tweak-tools
     - role: git
     - role: htop
diff --git a/roles/github-cli/tasks/main.yaml b/roles/github-cli/tasks/main.yaml
new file mode 100644
index 00000000..07eccffd
--- /dev/null
+++ b/roles/github-cli/tasks/main.yaml
@@ -0,0 +1,26 @@
+---
+- name: Existing install
+  ansible.builtin.stat:
+    path: /usr/bin/gh
+  register: install
+
+- name: Keyring
+  ansible.builtin.get_url:
+    dest: /usr/share/keyrings/githubcli-archive-keyring.gpg
+    mode: 644
+    url: https://cli.github.com/packages/githubcli-archive-keyring.gpg
+  when: not install.stat.exists
+  become: true
+
+- name: Repository
+  ansible.builtin.apt_repository:
+    repo: "deb [arch=amd64 signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main"
+  when: not install.stat.exists
+  become: true
+
+- name: Install
+  ansible.builtin.package:
+    name:
+      - gh
+    state: latest
+  become: true