diff --git a/.github/scripts/discover_role_repos.sh b/.github/scripts/discover_role_repos.sh index a91f9564..0eb249c8 100755 --- a/.github/scripts/discover_role_repos.sh +++ b/.github/scripts/discover_role_repos.sh @@ -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 ) diff --git a/.github/scripts/version_updater.sh b/.github/scripts/version_updater.sh index a857d209..867c9922 100755 --- a/.github/scripts/version_updater.sh +++ b/.github/scripts/version_updater.sh @@ -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 diff --git a/.github/workflows/version_bumper.yml b/.github/workflows/version_bumper.yml index 422fd90f..19f009be 100644 --- a/.github/workflows/version_bumper.yml +++ b/.github/workflows/version_bumper.yml @@ -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 }} diff --git a/roles/fail2ban_exporter/tasks/preflight.yml b/roles/fail2ban_exporter/tasks/preflight.yml index b24e059d..714505ea 100644 --- a/roles/fail2ban_exporter/tasks/preflight.yml +++ b/roles/fail2ban_exporter/tasks/preflight.yml @@ -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', '>=') diff --git a/roles/fail2ban_exporter/vars/main.yml b/roles/fail2ban_exporter/vars/main.yml index 9e463555..978c1eba 100644 --- a/roles/fail2ban_exporter/vars/main.yml +++ b/roles/fail2ban_exporter/vars/main.yml @@ -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