From c65b0a16fab30d164871619792dcadf016410fe9 Mon Sep 17 00:00:00 2001
From: Trevor Bergeron <mal@sec.gd>
Date: Sat, 28 Aug 2021 18:45:29 -0400
Subject: [PATCH] Support 'latest' to use current release version

---
 README.md                     |  3 +--
 molecule/default/converge.yml |  1 -
 tasks/funkwhale.yml           | 17 ++++++++++++++---
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 8aa2124..4b7039b 100644
--- a/README.md
+++ b/README.md
@@ -76,7 +76,6 @@ Add the following to `playbook.yml`:
   roles:
     - role: funkwhale
       funkwhale_hostname: yourdomain.funkwhale
-      funkwhale_version: 0.18.3
       funkwhale_letsencrypt_email: contact@youremail.com
 ```
 
@@ -109,7 +108,6 @@ Role Variables
 | name                          | Example                       | Description                                   |
 | ----------------------------- | ----------------------------- | --------------------------------------------- |
 | `funkwhale_hostname`          | `yourdomain.funkwhale`        | The domain name of your Funkwhale pod         |
-| `funkwhale_version`           | `0.18.3`                      | The version to install/upgrade to. You can also use `develop` to run the development branch         |
 | `funkwhale_letsencrypt_email` | `contact@youremail.com`       | The email to associate with your Let's Encrypt certificate (not needed if you set `funkwhale_letsencrypt_enabled: false`, see below) |
 
 **Optional variables**
@@ -146,6 +144,7 @@ Role Variables
 | `funkwhale_systemd_after`               | `redis.service postgresql.service` | Configuration used for Systemd `After=` directive. Modify it if you have a database or redis server on a separate host   |
 | `funkwhale_systemd_service_name`        | `funkwhale`                   | Name of the generated Systemd service, e.g when calling `systemctl start <xxx>` |
 | `funkwhale_username`                    | `funkwhale`                   | Username of the system user and owner of Funkwhale data, files and configuration |
+| `funkwhale_version`                     | `latest`                      | The version to install/upgrade to. You can also use `develop` to run the development branch |
 | `funkwhale_custom_pip_packages`         | `[]`                          | A list of additional python packages to download |
 | `funkwhale_custom_settings`             | ``                            | Some Python code to append to `api/config/settings/production.py`. Use funkwhale_custom_settings: |` for multiline code. |
 
diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml
index 5e8a4df..a9cf145 100644
--- a/molecule/default/converge.yml
+++ b/molecule/default/converge.yml
@@ -12,7 +12,6 @@
         funkwhale_ssl_cert_path: /certs/test.crt
         funkwhale_ssl_key_path: /certs/test.key
         funkwhale_hostname: yourdomain.funkwhale
-        funkwhale_version: 0.19.0-rc2
         funkwhale_env_vars:
           - EMAIL_CONFIG=smtp+tls://user@:password@youremail.host:587
           - DEFAULT_FROM_EMAIL=noreply@yourdomain.funkwhale
diff --git a/tasks/funkwhale.yml b/tasks/funkwhale.yml
index e041675..65304c1 100644
--- a/tasks/funkwhale.yml
+++ b/tasks/funkwhale.yml
@@ -1,5 +1,16 @@
 ---
 
+- name: Check latest version
+  when: funkwhale_version is not defined or funkwhale_version == "latest"
+  uri:
+    url: https://docs.funkwhale.audio/latest.txt
+    return_content: yes
+  register: latest_version
+
+- name: Set version to install
+  set_fact:
+    funkwhale_install_version: "{{ latest_version.get('content', funkwhale_version) | trim }}"
+
 - name: Ensure home folder can be created
   become: true
   file:
@@ -82,7 +93,7 @@
   become_user: "{{ funkwhale_username }}"
   when: funkwhale_frontend_managed and not funkwhale_install_from_source
   unarchive:
-    src: https://dev.funkwhale.audio/funkwhale/funkwhale/builds/artifacts/{{ funkwhale_version }}/download?job=build_front
+    src: https://dev.funkwhale.audio/funkwhale/funkwhale/builds/artifacts/{{ funkwhale_install_version }}/download?job=build_front
     dest: "{{ funkwhale_install_path }}"
     remote_src: true
   notify:
@@ -93,7 +104,7 @@
   become_user: "{{ funkwhale_username }}"
   when: not funkwhale_install_from_source
   unarchive:
-    src: https://dev.funkwhale.audio/funkwhale/funkwhale/builds/artifacts/{{ funkwhale_version }}/download?job=build_api
+    src: https://dev.funkwhale.audio/funkwhale/funkwhale/builds/artifacts/{{ funkwhale_install_version }}/download?job=build_api
     dest: "{{ funkwhale_install_path }}"
     remote_src: true
   notify:
@@ -107,7 +118,7 @@
   git:
     repo: "{{ funkwhale_source_url }}"
     dest: "{{ funkwhale_install_path }}/src"
-    version: "{{ funkwhale_version }}"
+    version: "{{ funkwhale_install_version }}"
     force: true
   notify:
     - reload funkwhale
-- 
GitLab