Files
i18n/playbooks/generate_ac.yml
Ian Y. Choi 245815010a Rename extra-atcs to extra-acs on ansible
Update tox ansible environment to rename from extra-atcs
to extra-acs and work with environment.

1. Renaming to extra-acs aligns with a governance patch
: https://review.opendev.org/c/openstack/governance/+/893831

2. Update minimum ansible version since older version causes errors
: https://github.com/ansible/ansible/issues/77413

Change-Id: If5c69efddcdf4854f8db95cfa2356cda0cb6f98a
2023-09-26 00:07:39 +09:00

110 lines
4.1 KiB
YAML

---
# Ansible playbook to generate extra-ac snippets for sigs-repos.yaml in
# governance repo.
# Requires 3 source files
# - userstatsfile: generated output from zanata_stats.py
# (default: zanata_stats_output.csv)
# - userinfofile: generated output from zanata_userinfo.py
# (default: zanata_userinfo_output.csv)
# - the current sig-repos.yaml file from governance repo
# https://opendev.org/openstack/governance/raw/branch/master/reference/sigs-repos.yaml
#
# minimum translation count is to configure (default 300 words/30
# phrases)
#
# Old extra-ac list will be reviewed and refreshed with new data
#
# usage: ansible-playbook generate_ac.yml
#
# The output can be found in /tmp/ac.stats
#
# The full workflow is described in https://wiki.openstack.org/wiki/I18n_Extra-AC_collection
- hosts: localhost
gather_facts: "no"
vars:
userstatsfile: "vars/zanata_stats_output.csv"
userinfofile: "vars/zanata_userinfo_output.csv"
translatecount: 300
workingdir: "/tmp/ac.output"
tasks:
- name: create working dir
file:
path: "{{ workingdir }}"
state: directory
- name: fetch projects list
get_url:
url: https://opendev.org/openstack/governance/raw/branch/master/reference/sigs-repos.yaml
dest: vars/
force: True
- name: include sigs-repos.yaml var
include_vars: vars/sigs-repos.yaml
- name: read old ac list
vars:
extraacs: "{{ i18n[0]['extra-acs'] }}"
useremail: "{{ item.email }}"
username: "{{ item.name }}"
usercomment: "{{ item.comment }}"
userexpires: "{{ item['expires-in'] }}"
expiredate: "28 {{ userexpires[:3] }}{{ userexpires[-5:] }}"
udateuser: "{{lookup('pipe','LANG=en date -d \"' + expiredate + '\" \"+%s\"')}}"
udatecur: "{{lookup('pipe','LANG=en date -d \"+1 month\" \"+%s\"') }}"
template:
src: ac.json.j2
dest: "{{ workingdir }}/user.{{ usercomment.split(' ')[0] }}"
when: udateuser|int > udatecur|int
with_items:
- "{{ extraacs }}"
- name: read user stats
vars:
userdata: "{{ item.split(',') }}"
useremail: "{{ lookup('csvfile', userdata[0] + ' file=' + userinfofile + ' delimiter=, col=4') }}"
username: "{{ lookup('csvfile', userdata[0] + ' file=' + userinfofile + ' delimiter=, col=3') }}"
userlang: "{{ lookup('csvfile', userdata[0] + ' file=' + userinfofile + ' delimiter=, col=1') }}"
usercomment: "{{ userdata[0] }} ({{ userlang }})"
userexpires: "{{lookup('pipe','LANG=en date \"+%B %Y\" -d \"+1 year\"')}}"
template:
src: ac.json.j2
dest: "{{ workingdir }}/user.{{ userdata[0] }}"
force: "yes"
with_lines: cat "{{ userstatsfile }}"
when: userdata[4]|int + userdata[9]|int >= translatecount
- name: validate openstackid
vars:
userdata: "{{ item.split(',') }}"
useremail: "{{ lookup('csvfile', userdata[0] + ' file=' + userinfofile + ' delimiter=, col=4') }}"
zanataid: "{{ userdata[0] }}"
uri:
url: "https://openstackid-resources.openstack.org/api/public/v1/members?expand=groups&relations=all_affiliations,groups&filter[]=email=={{ useremail }}"
method: GET
return_content: yes
validate_certs: no
headers:
Content-Type: "application/json"
Accept: "application/json"
register: api
with_lines: cat "{{ userstatsfile }}"
when: userdata[4]|int + userdata[9]|int >= translatecount
- name: write wiki stats files per user
template:
src: stats.json.j2
dest: "{{ workingdir }}/stats.{{ item|hash('sha1') }} "
with_items: "{{ api|json_query('results[].{ item: item, userdata: json.data[].{email_verified: email_verified, groups: groups[?id==`5`].code|[0]}}') }}"
- name: create stats file proposal
shell: cat "{{ workingdir }}"/user.* > /tmp/ac.stats
- name: create stats file wiki
shell: cat "{{ workingdir }}"/stats.* > /tmp/ac.wiki
- name: delete working dir
file:
path: "{{ workingdir }}"
state: absent