diff --git a/README.md b/README.md index 34a0ebf..851baee 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,6 @@ Here is a deeper insight into the variables of this gitea role. For the exact fu | ------------- | ------------- | ----------- | | `gitea_version` | *(see [defaults/main.yml](defaults/main.yml#L3))* | The gitea version this role shoud install | | `gitea_version_check` | `true` | Check if installed version != `gitea_version` before initiating binary download | -| `gitea_dl_url` | *(see [defaults/main.yml](defaults/main.yml#L5))* | The path from where this role downloads the gitea binary | | `gitea_gpg_key` | `7C9E68152594688862D62AF62D9AE806EC1592E2` | the gpg key the gitea binary is signed with | | `gitea_gpg_server` | `hkps://keys.openpgp.org` | A gpg key server where this role can download the gpg key | | `gitea_backup_on_upgrade` | `false` | Optionally a backup can be created with every update of gitea. | diff --git a/defaults/main.yml b/defaults/main.yml index af7f080..00cff7c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,8 +1,8 @@ --- # gitea version +# Use 'latest' to auto-update; upgrading past role version may lead to errors. gitea_version: '1.14.4' gitea_version_check: true -gitea_dl_url: "https://github.com/go-gitea/gitea/releases/download/v{{ gitea_version }}/gitea-{{ gitea_version }}-linux-{{ gitea_arch }}" gitea_gpg_key: '7C9E68152594688862D62AF62D9AE806EC1592E2' gitea_gpg_server: 'hkps://keys.openpgp.org' gitea_backup_on_upgrade: false diff --git a/tasks/backup.yml b/tasks/backup.yml index 5bbf374..93c67f9 100644 --- a/tasks/backup.yml +++ b/tasks/backup.yml @@ -30,4 +30,4 @@ when: - ansible_facts.services["gitea.service"] is defined - ansible_facts.services["gitea.service"].state == "running" - - gitea_active_version.stdout != gitea_version + - gitea_active_version.stdout != gitea_version_target diff --git a/tasks/install.yml b/tasks/install.yml index 03d1836..ef325f8 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -71,4 +71,4 @@ owner: root group: root notify: "Restart gitea" - when: (not gitea_version_check|bool) or (not ansible_check_mode and (gitea_active_version.stdout != gitea_version)) + when: (not gitea_version_check|bool) or (not ansible_check_mode and (gitea_active_version.stdout != gitea_version_target)) diff --git a/tasks/main.yml b/tasks/main.yml index 5a96d87..097818f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -10,14 +10,8 @@ - name: Gather variables for each operating system ansible.builtin.include_vars: "{{ lookup('first_found', gitea_variables) }}" -- name: "Check gitea version" - ansible.builtin.shell: "set -eo pipefail; /usr/local/bin/gitea -v | cut -d' ' -f 3" - args: - executable: /bin/bash - register: gitea_active_version - changed_when: false - failed_when: false - when: gitea_version_check|bool +- name: Gather versioning information + ansible.builtin.include_tasks: set_version.yml - name: backup gitea before update ansible.builtin.include_tasks: backup.yml diff --git a/tasks/set_version.yml b/tasks/set_version.yml new file mode 100644 index 0000000..297199c --- /dev/null +++ b/tasks/set_version.yml @@ -0,0 +1,34 @@ +--- +- name: "Check gitea installed version" + ansible.builtin.shell: "set -eo pipefail; /usr/local/bin/gitea -v | cut -d' ' -f 3" + args: + executable: /bin/bash + register: gitea_active_version + changed_when: false + failed_when: false + +- name: "Determine 'latest' version release" + block: + - name: "Get latest gitea release metadata" + ansible.builtin.uri: + url: https://api.github.com/repos/go-gitea/gitea/releases/latest + return_content: true + register: gitea_remote_metadata + + - name: "Set fact latest gitea release" + ansible.builtin.set_fact: + gitea_remote_version: "{{ gitea_remote_metadata.json.tag_name[1:] }}" + + - name: "Set gitea version target (latest)" + ansible.builtin.set_fact: + gitea_version_target: "{{ gitea_remote_version }}" + when: gitea_version == "latest" + +- name: "Set gitea version target ({{ gitea_version }})" + ansible.builtin.set_fact: + gitea_version_target: "{{ gitea_version }}" + when: gitea_version != "latest" + +- name: "Generate gitea download URL" + ansible.builtin.set_fact: + gitea_dl_url: "https://github.com/go-gitea/gitea/releases/download/v{{ gitea_version_target }}/gitea-{{ gitea_version_target }}-linux-{{ gitea_arch }}"