skip_changelog(ci): gitlab.com support for version updater (#308)

* ci: gitlab.com support for version updater

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>

* ci: version updater fix syntax

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>

* test: version updater fix sanity

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>

* test: version updater add gitlab_api function

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>

* feat: version updater use case statement

Co-authored-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Oleg Klyuchkin <anviar@users.noreply.github.com>

---------

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>
Signed-off-by: Oleg Klyuchkin <anviar@users.noreply.github.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
Oleg Klyuchkin 2024-02-29 11:48:53 +03:00 committed by GitHub
parent cf2db420c2
commit ee540fe8de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 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'
@ -38,6 +39,13 @@ github_api() {
curl --retry 5 --silent --fail -u "${GIT_USER}:${GITHUB_TOKEN}" "${url}" "$@"
}
gitlab_api() {
local url
url="https://gitlab.com/api/v4/${1}"
shift 1
curl --retry 5 --silent --fail "${url}" "$@"
}
post_pull_request() {
local pr_title="$1"
local default_branch="$2"
@ -67,7 +75,18 @@ if [[ -z "${role}" ]]; then
fi
# Get latest version.
version="$(github_api "repos/${source_repo}/releases/latest" | jq '.tag_name' | tr -d '"v')"
case "${type}" in
github)
version="$(github_api "repos/${source_repo}/releases/latest" | jq '.tag_name' | tr -d '"v')"
;;
gitlab)
version="$(gitlab_api "projects/${source_repo}/releases" | jq '.[0].tag_name' | tr -d '"v')"
;;
*)
echo_red 'Unknown source type. Terminating.'
exit 128
;;
esac
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