Add typst role

This commit is contained in:
Kenneth Benzie 2025-08-18 12:52:41 +01:00
parent 77a4fdcc16
commit d41ea98da0
4 changed files with 93 additions and 0 deletions

View File

@ -30,6 +30,7 @@
- role: ripgrep - role: ripgrep
- role: tidy - role: tidy
- role: tree - role: tree
- role: typst
- role: watch - role: watch
- role: wget - role: wget
- role: yq - role: yq

View File

@ -20,6 +20,7 @@
- role: jq - role: jq
- role: ripgrep - role: ripgrep
- role: tree - role: tree
- role: typst
- role: yq - role: yq
- role: llvm - role: llvm

View File

@ -0,0 +1,76 @@
---
- name: get latest github release
uri:
url: https://api.github.com/repos/typst/typst/releases/latest
headers: '{{github_auth_headers}}'
register: latest
- set_fact:
asset_name: >-
{{
{
'amd64': 'typst-x86_64-unknown-linux-musl',
'x86_64': 'typst-x86_64-unknown-linux-musl',
'arm64': 'typst-aarch64-unknown-linux-musl',
}[ansible_architecture]
}}
- set_fact:
asset_query: '[?contains(name, `{{asset_name}}.tar.xz`)] | [0]'
assets: '{{latest.json.assets}}'
asset_archive: '{{asset_name}}.tar.xz'
latest_version: '{{latest.json.tag_name}}'
exe: '{{ansible_env.HOME}}/.local/bin/typst'
- name: check if already installed
stat:
path: '{{exe}}'
register: stat_exe
- name: get installed version
when: stat_exe.stat.exists == True
command: '{{exe}} --version'
register: version_output
changed_when: false
- when: stat_exe.stat.exists == True
set_fact:
installed_version:
'v{{version_output.stdout.strip() | regex_replace("^.*(\d+\.\d+\.\d+).*$", "\1")}}'
- set_fact:
asset: '{{assets | to_json | from_json | json_query(asset_query)}}'
- name: download archive
when: installed_version is not defined or installed_version != latest_version
get_url:
url: '{{asset.browser_download_url}}'
dest: '/tmp/{{asset_archive}}'
environment: '{{proxy_environment}}'
- name: extract archive
when: installed_version is not defined or installed_version != latest_version
unarchive:
src: '/tmp/{{asset_archive}}'
dest: '/tmp'
- name: remove archive
when: installed_version is not defined or installed_version != latest_version
file:
state: absent
path: '/tmp/{{asset_archive}}'
- name: copy executable
when: installed_version is not defined or installed_version != latest_version
copy:
src: '/tmp/{{asset_name}}/typst'
dest: '{{exe}}'
mode: +x
- name: remove extraced archive
when: installed_version is not defined or installed_version != latest_version
file:
state: absent
path: '/tmp/{{asset_archive}}'
# TODO: install zsh completions

View File

@ -0,0 +1,15 @@
---
- name: install homebrew package
when: ansible_os_family == 'Darwin'
homebrew:
state: latest
name: typst
- name: install scoop package
when: ansible_os_family == 'Windows'
community.windows.win_scoop:
state: present
name: typst
- when: ansible_os_family != 'Darwin' and ansible_os_family != 'Windows'
include_tasks: Linux.yaml