Fix getting latest forgejo binary when new version is a stable release

Sometimes forgejo releases stable that is version lower than a current
stable release (LTS)
This commit is contained in:
Tunui Franken 2025-03-21 09:32:36 +01:00
parent 6f8b247425
commit 15dff1571a
2 changed files with 25 additions and 24 deletions

View file

@ -9,19 +9,30 @@
- name: Download forgejo asc file - name: Download forgejo asc file
become: true become: true
ansible.builtin.get_url: ansible.builtin.get_url:
url: "https://codeberg.org/forgejo/forgejo/releases/download/{{ forgejo_latest_version }}/forgejo-{{ forgejo_latest_version | replace('v', '') }}-linux-{{ forgejo_architecture }}.asc" url: "https://codeberg.org/forgejo/forgejo/releases/download/v{{ forgejo_latest_version }}/forgejo-{{ forgejo_latest_version }}-linux-{{ forgejo_architecture }}.asc"
dest: "{{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version | replace('v', '') }}-linux-{{ forgejo_architecture }}.asc" dest: "{{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version }}-linux-{{ forgejo_architecture }}.asc"
owner: git owner: git
group: git group: git
mode: 0644 mode: 0644
- name: Verify forgejo binary with gpg - name: Verify forgejo binary with gpg
become: true become: true
ansible.builtin.command: "gpg --verify {{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version | replace('v', '') }}-linux-{{ forgejo_architecture }}.asc {{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version | replace('v', '') }}-linux-{{ forgejo_architecture }}" ansible.builtin.command: "gpg --verify {{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version }}-linux-{{ forgejo_architecture }}.asc {{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version }}-linux-{{ forgejo_architecture }}"
register: result register: result
changed_when: false changed_when: false
failed_when: '"Good signature from" not in result.stderr' failed_when: '"Good signature from" not in result.stderr'
- name: Copy binary to global location
become: true
ansible.builtin.copy:
src: "{{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version }}-linux-{{ forgejo_architecture }}"
dest: /usr/local/bin/forgejo
remote_src: true
owner: root
group: root
mode: 0755
notify: Restart forgejo service
- name: Start forgejo service - name: Start forgejo service
become: true become: true
ansible.builtin.systemd: ansible.builtin.systemd:

View file

@ -7,42 +7,32 @@
- name: Set latest available version - name: Set latest available version
ansible.builtin.set_fact: ansible.builtin.set_fact:
forgejo_latest_version: "{{ latest_http_content.url | split('/') | last }}" forgejo_latest_version: "{{ latest_http_content.url | split('/') | last | replace('v', '') }}"
- name: Define forgejo architecture - name: Define forgejo architecture
ansible.builtin.set_fact: ansible.builtin.set_fact:
forgejo_architecture: "{{ (ansible_architecture == 'x86_64') | ternary('amd64', 'arm-6') }}" forgejo_architecture: "{{ (ansible_architecture == 'x86_64') | ternary('amd64', 'arm-6') }}"
- name: Find if latest available version is installed - name: Find currently installed version
become: true ansible.builtin.shell:
ansible.builtin.stat: cmd: "(forgejo --version 2>/dev/null || echo 'forgejo version 0.0.0') | awk '{print $3}'"
path: "{{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version | replace('v', '') }}-linux-{{ forgejo_architecture }}" register: forgejo_installed_version
register: latest_installed_binary changed_when: false
- name: Get latest forgejo binary - name: Get latest forgejo binary
become: true become: true
ansible.builtin.get_url: ansible.builtin.get_url:
url: "https://codeberg.org/forgejo/forgejo/releases/download/{{ forgejo_latest_version }}/forgejo-{{ forgejo_latest_version | replace('v', '') }}-linux-{{ forgejo_architecture }}" url: "https://codeberg.org/forgejo/forgejo/releases/download/v{{ forgejo_latest_version }}/forgejo-{{ forgejo_latest_version }}-linux-{{ forgejo_architecture }}"
dest: "{{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version | replace('v', '') }}-linux-{{ forgejo_architecture }}" dest: "{{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version }}-linux-{{ forgejo_architecture }}"
owner: git owner: git
group: git group: git
mode: 0644 mode: 0644
when: not latest_installed_binary.stat.exists when: forgejo_installed_version.stdout is version(forgejo_latest_version, '<')
notify: notify:
- Receive forgejo pgp key - Receive forgejo pgp key
- Download forgejo asc file - Download forgejo asc file
- Verify forgejo binary with gpg - Verify forgejo binary with gpg
- Copy binary to global location
- name: Make sure downloaded binary has been verified - name: Make sure downloaded binary has been verified and copied to global location
ansible.builtin.meta: flush_handlers ansible.builtin.meta: flush_handlers
- name: Copy binary to global location
become: true
ansible.builtin.copy:
src: "{{ forgejo_run_dir }}/forgejo-{{ forgejo_latest_version | replace('v', '') }}-linux-{{ forgejo_architecture }}"
dest: /usr/local/bin/forgejo
remote_src: true
owner: root
group: root
mode: 0755
notify: Restart forgejo service