ci: gitlab.com support for version updater

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>
This commit is contained in:
anviar 2024-02-27 11:36:29 +03:00
parent b780522780
commit 45595a7d65
No known key found for this signature in database
GPG key ID: 1D9496B16B0FC606
5 changed files with 15 additions and 5 deletions

View file

@ -5,7 +5,7 @@
result=$(
for defaults_file in roles/*/vars/main.yml ; do
role="$(echo "${defaults_file}" | cut -f2 -d'/')"
yq eval "[{\"repo\": ._${role}_repo, \"role\": \"${role}\"}]" "${defaults_file}"
yq eval "[{\"repo\": ._${role}_repo, \"role\": \"${role}\", \"type\": ._${role}_repo_type // \"github\"}]" "${defaults_file}"
done | yq -o json -I=0
)

View file

@ -13,6 +13,7 @@ fi
source_repo="$1"
role="$2"
type="$3"
color_red='\e[31m'
color_green='\e[32m'
@ -67,7 +68,15 @@ if [[ -z "${role}" ]]; then
fi
# Get latest version.
version="$(github_api "repos/${source_repo}/releases/latest" | jq '.tag_name' | tr -d '"v')"
if [[ ${type} == "github" ]]
then
version="$(github_api "repos/${source_repo}/releases/latest" | jq '.tag_name' | tr -d '"v')"
elif [[ ${type} == "gitlab" ]]
version="$(curl https://gitlab.com/api/v4/projects/${source_repo}/releases|jq '.[0].tag_name'| tr -d '"v')"
else
echo_red 'Unknown source type. Terminating.'
exit 128
fi
echo_green "New ${source_repo} version is: ${version}"
# Download destination repository

View file

@ -37,4 +37,4 @@ jobs:
include: ${{ fromJson(needs.discover-role-repos.outputs.role-repos) }}
steps:
- uses: actions/checkout@v3
- run: ./.github/scripts/version_updater.sh ${{ matrix.repo }} ${{ matrix.role }}
- run: ./.github/scripts/version_updater.sh ${{ matrix.repo }} ${{ matrix.role }} ${{ matrix.type }}

View file

@ -55,7 +55,7 @@
- name: Discover latest version
ansible.builtin.set_fact:
fail2ban_exporter_version: "{{ (lookup('url', 'https://gitlab.com/api/v4/projects/{{ _gitlab_projectid }}/releases',
fail2ban_exporter_version: "{{ (lookup('url', 'https://gitlab.com/api/v4/projects/{{ _fail2ban_exporter_repo }}/releases',
split_lines=False) | from_json)[0].get('tag_name') | replace('v', '') }}"
run_once: true
until: fail2ban_exporter_version is version('0.0.0', '>=')

View file

@ -7,4 +7,5 @@ go_arch_map:
armv6l: 'armv6'
go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
_gitlab_projectid: 24199687
_fail2ban_exporter_repo: 24199687
_fail2ban_exporter_repo_type: gitlab