1
1
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_gitea.git synced 2024-08-16 11:39:50 +02:00
ansible_role_gitea/tasks/set_forgejo_version.yml

118 lines
4.7 KiB
YAML
Raw Normal View History

---
- name: "Check forgejo installed version"
ansible.builtin.shell: "set -eo pipefail; {{ gitea_full_executable_path }} -v | cut -d' ' -f 3"
args:
2023-10-29 16:11:12 +01:00
executable: '/bin/bash'
register: gitea_active_version
changed_when: false
failed_when: false
- name: "Determine 'latest' version release"
when: gitea_version == "latest"
block:
- name: "Get latest forgejo release metadata"
ansible.builtin.uri:
url: 'https://{{ gitea_forgejo_repo }}/api/v1/repos/forgejo/forgejo/releases?limit=1'
return_content: true
register: gitea_forgejo_remote_metadata
become: false
when: not ansible_check_mode
- name: "Fail if running in check mode without versions set."
ansible.builtin.fail:
msg: |
"You are running this playbook in check mode:
Please set the Gitea version with the variable 'gitea_version', because the URI module cannot detect the latest version in this mode."
when: ansible_check_mode and (gitea_version == 'latest' or gitea_version == 'present')
- name: "Set fact latest forgejo release"
ansible.builtin.set_fact:
gitea_remote_version: "{{ gitea_forgejo_remote_metadata.json.0.tag_name[1:] }}"
when: not ansible_check_mode
- name: "Set forgejo version target (latest)"
ansible.builtin.set_fact:
gitea_version_target: "{{ gitea_remote_version }}"
when: not ansible_check_mode
- name: "Set forgejo version target {{ gitea_version }}"
ansible.builtin.set_fact:
gitea_version_target: "{{ gitea_version }}"
when: gitea_version != "latest"
- name: "Download forgejo version {{ gitea_version_target }}"
when: not ansible_check_mode
block:
- name: "Get specific forgejo release metadata"
ansible.builtin.uri:
url: 'https://{{ gitea_forgejo_repo }}/api/v1/repos/forgejo/forgejo/releases/tags/v{{ gitea_version_target }}'
return_content: true
register: gitea_forgejo_remote_tags_metadata
become: false
rescue:
2024-03-21 15:33:40 +01:00
- name: "Error Downloading v{{ gitea_version_target }}"
ansible.builtin.fail:
2024-03-21 15:33:40 +01:00
msg: |
We did not find the forgejo version you specified.
Are you sure that '{{ gitea_version_target }}' is a valid forgejo version?
Please verify 'https://{{ gitea_forgejo_repo }}/api/v1/repos/forgejo/forgejo/releases/tags/v{{ gitea_version_target }}' is a valid URL!
- name: "Generate forgejo download url"
ansible.builtin.set_fact:
gitea_forgejo_dl_url: "{{ gitea_forgejo_remote_tags_metadata.json | community.general.json_query(gitea_forgejo_query_download) }}"
when: not ansible_check_mode
- name: "Generate forgejo download checksum url"
ansible.builtin.set_fact:
gitea_forgejo_checksum_url: "{{ gitea_forgejo_remote_tags_metadata.json | community.general.json_query(gitea_forgejo_query_checksum) }}"
when: not ansible_check_mode
- name: Get forgejo checksum
ansible.builtin.uri:
url: "{{ gitea_forgejo_checksum_url | first }}"
return_content: true
register: _gitea_forgejo_dl_checksum
become: false
when: not ansible_check_mode
- name: Set forjeo checksum
ansible.builtin.set_fact:
gitea_forgejo_checksum: "{{ _gitea_forgejo_dl_checksum.content.split(' ')[0] }}"
when: not ansible_check_mode
- name: "Generate forgejo download signed url"
ansible.builtin.set_fact:
gitea_forgejo_signed_url: "{{ gitea_forgejo_remote_tags_metadata.json | community.general.json_query(gitea_forgejo_query_signed) }}"
when: not ansible_check_mode
- name: "Set a example forgejo download link if in check mode"
ansible.builtin.set_fact:
gitea_forgejo_dl_url: ['https://{{ gitea_forgejo_repo }}/attachments/a00333ad-250a-4d30-a764-9a37fb24f419']
when: ansible_check_mode
- name: "Set a example forgejo checksum link if in check mode"
ansible.builtin.set_fact:
gitea_forgejo_checksum: 'f8c71464d1b250bf022eaa3df270c810950904ceb71da5cefc7ec24a034a4c87'
when: ansible_check_mode
- name: "Set a example forgejo checksum link if in check mode"
ansible.builtin.set_fact:
gitea_forgejo_signed_url: ['https://{{ gitea_forgejo_repo }}/attachments/ae5e50c6-e86e-4202-b95f-f142e8138e2f']
when: ansible_check_mode
2024-01-08 16:50:45 +01:00
- name: 'Assert that remote version is higher'
ansible.builtin.assert:
that:
- gitea_active_version is version(gitea_remote_version, 'lt')
2024-01-08 16:54:10 +01:00
fail_msg: ERROR - Remote version is lower then current version!
when: gitea_version == "latest" and gitea_active_version.stderr == "" | bool
2024-01-08 16:50:45 +01:00
2023-10-29 16:11:12 +01:00
- name: Show Download URLs # noqa: H500
ansible.builtin.debug:
msg: "{{ item }}"
verbosity: 1
2023-10-29 16:11:12 +01:00
loop:
- "gitea_forgejo_dl_url: {{ gitea_forgejo_dl_url | first }}"
- "gitea_forgejo_checksum: {{ gitea_forgejo_checksum }}"
- "gitea_forgejo_signed_url: {{ gitea_forgejo_signed_url | first }}"