Skip to content

Commit ad48853

Browse files
authored
Merge pull request roles-ansible#44 from r-pufky/latest-version-flag
Add 'latest' version to automatically download the latest gitea release.
2 parents fe715c1 + 32f0a15 commit ad48853

File tree

7 files changed

+46
-15
lines changed

7 files changed

+46
-15
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ The following code has been tested with Debian 8, it should work on Ubuntu as we
3131
-----------
3232
Here is a deeper insight into the variables of this gitea role. For the exact function of some variables and the possibility to add more options we recommend a look at the config cheat sheet. For the exact function of some variables and the possibility to add more options we recommend a look at this [config cheat sheet](https://docs.gitea.io/en-us/config-cheat-sheet/).
3333
34-
### gitea version
34+
### gitea update
35+
To determine which gitea version to install, you can choose between two variants.
36+
Either you define exactly which release you install. Or you use the option ``latest`` to always install the latest release from the [gitea releases](https://github.com/go-gitea/gitea/releases/latest).
37+
38+
### gitea update
3539
| variable name | default value | description |
3640
| ------------- | ------------- | ----------- |
37-
| `gitea_version` | *(see [defaults/main.yml](defaults/main.yml#L3))* | The gitea version this role shoud install |
41+
| `gitea_version` | **WILL CHANGE SOON** | Define either the exact release to install or use ``latest`` to install the latest release. |
3842
| `gitea_version_check` | `true` | Check if installed version != `gitea_version` before initiating binary download |
39-
| `gitea_dl_url` | *(see [defaults/main.yml](defaults/main.yml#L5))* | The path from where this role downloads the gitea binary |
4043
| `gitea_gpg_key` | `7C9E68152594688862D62AF62D9AE806EC1592E2` | the gpg key the gitea binary is signed with |
4144
| `gitea_gpg_server` | `hkps://keys.openpgp.org` | A gpg key server where this role can download the gpg key |
4245
| `gitea_backup_on_upgrade` | `false` | Optionally a backup can be created with every update of gitea. |

defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
# gitea version
3+
# Use 'latest' to auto-update; upgrading past role version may lead to errors.
34
gitea_version: '1.14.4'
45
gitea_version_check: true
5-
gitea_dl_url: "https://github.com/go-gitea/gitea/releases/download/v{{ gitea_version }}/gitea-{{ gitea_version }}-linux-{{ gitea_arch }}"
66
gitea_gpg_key: '7C9E68152594688862D62AF62D9AE806EC1592E2'
77
gitea_gpg_server: 'hkps://keys.openpgp.org'
88
gitea_backup_on_upgrade: false

tasks/backup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
when:
3131
- ansible_facts.services["gitea.service"] is defined
3232
- ansible_facts.services["gitea.service"].state == "running"
33-
- gitea_active_version.stdout != gitea_version
33+
- gitea_active_version.stdout != gitea_version_target

tasks/install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@
7171
owner: root
7272
group: root
7373
notify: "Restart gitea"
74-
when: (not gitea_version_check|bool) or (not ansible_check_mode and (gitea_active_version.stdout != gitea_version))
74+
when: (not gitea_version_check|bool) or (not ansible_check_mode and (gitea_active_version.stdout != gitea_version_target))

tasks/main.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,8 @@
1010
- name: Gather variables for each operating system
1111
ansible.builtin.include_vars: "{{ lookup('first_found', gitea_variables) }}"
1212

13-
- name: "Check gitea version"
14-
ansible.builtin.shell: "set -eo pipefail; /usr/local/bin/gitea -v | cut -d' ' -f 3"
15-
args:
16-
executable: /bin/bash
17-
register: gitea_active_version
18-
changed_when: false
19-
failed_when: false
20-
when: gitea_version_check|bool
13+
- name: Gather versioning information
14+
ansible.builtin.include_tasks: set_version.yml
2115

2216
- name: backup gitea before update
2317
ansible.builtin.include_tasks: backup.yml

tasks/set_version.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
- name: "Check gitea installed version"
3+
ansible.builtin.shell: "set -eo pipefail; /usr/local/bin/gitea -v | cut -d' ' -f 3"
4+
args:
5+
executable: /bin/bash
6+
register: gitea_active_version
7+
changed_when: false
8+
failed_when: false
9+
10+
- name: "Determine 'latest' version release"
11+
block:
12+
- name: "Get latest gitea release metadata"
13+
ansible.builtin.uri:
14+
url: https://api.github.com/repos/go-gitea/gitea/releases/latest
15+
return_content: true
16+
register: gitea_remote_metadata
17+
18+
- name: "Set fact latest gitea release"
19+
ansible.builtin.set_fact:
20+
gitea_remote_version: "{{ gitea_remote_metadata.json.tag_name[1:] }}"
21+
22+
- name: "Set gitea version target (latest)"
23+
ansible.builtin.set_fact:
24+
gitea_version_target: "{{ gitea_remote_version }}"
25+
when: gitea_version == "latest"
26+
27+
- name: "Set gitea version target ({{ gitea_version }})"
28+
ansible.builtin.set_fact:
29+
gitea_version_target: "{{ gitea_version }}"
30+
when: gitea_version != "latest"
31+
32+
- name: "Generate gitea download URL"
33+
ansible.builtin.set_fact:
34+
gitea_dl_url: "https://github.com/go-gitea/gitea/releases/download/v{{ gitea_version_target }}/gitea-{{ gitea_version_target }}-linux-{{ gitea_arch }}"

vars/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ transfer_custom_footer:
5656
- 'files/gitea_footer/extra_links_footer.tmpl'
5757
- 'files/extra_links_footer.tmpl'
5858

59-
playbook_version_number: 20 # should be int
59+
playbook_version_number: 21 # should be int
6060
playbook_version_path: 'do1jlr.gitea.version'

0 commit comments

Comments
 (0)