Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change and refactor release_tag #61

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/updatecli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Updatecli

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
schedule:
# * is a special character in YAML so you have to quote this string
# Run once a day
- cron: '0 0 * * *'

jobs:
updatecli:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install updatecli
uses: updatecli/updatecli-action@v2

- name: Diff
continue-on-error: true
run: |
updatecli diff --config updatecli/updatecli.d --values updatecli/values.yaml
env:
UPDATECLI_GITHUB_TOKEN: ${{ secrets.CPP_LINTER_TOEKN }}

- name: Apply
if: github.ref == 'refs/heads/main'
run: |
updatecli apply --config updatecli/updatecli.d --values updatecli/values.yaml
env:
UPDATECLI_GITHUB_TOKEN: ${{ secrets.CPP_LINTER_TOEKN }}
3 changes: 3 additions & 0 deletions clang_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
YELLOW = "\033[93m"
install_os = check_install_os()
suffix = ".exe" if install_os == "windows" else ""

# tag of https://github.com/cpp-linter/clang-tools-static-binaries/releases
release_tag = 'master-be694ee7'
7 changes: 4 additions & 3 deletions clang_tools/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess
import sys
from typing import Optional
from . import release_tag

from . import install_os, RESET_COLOR, suffix, YELLOW
from .util import download_file, verify_sha512, get_sha_checksum
Expand Down Expand Up @@ -63,19 +64,19 @@ def is_installed(tool_name: str, version: str) -> Optional[Path]:


def clang_tools_binary_url(
tool: str, version: str, release_tag: str = "master-be694ee7"
tool: str, version: str, tag: str = release_tag
) -> str:
"""Assemble the URL to the binary.

:param tool: The name of the tool to download.
:param version: The version of the tool to download.
:param release_tag: The release tag used in the base URL.
:param tag: The release tag used in the base URL.

:returns: The URL used to download the specified tool.
"""
base_url = (
"https://github.com/cpp-linter/clang-tools-static-binaries/releases/download/"
+ release_tag
+ tag
)
download_url = f"{base_url}/{tool}-{version}_{install_os}-amd64{suffix}"
return download_url.replace(" ", "")
Expand Down
55 changes: 28 additions & 27 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"baseBranches": ["main"],
"rebaseWhen": "behind-base-branch",
"dependencyDashboard": false,
"labels": ["dependencies"],
"commitMessagePrefix": "",
"commitMessageTopic": "{{depName}}",
"regexManagers": [
{
"customType": "regex",
"matchStrings": [
"\\sappVersion: (?<currentValue>.*)\\s"
],
"datasourceTemplate": "github-releases",
"depNameTemplate": "cpp-linter/clang-tools-static-binaries",
"extractVersionTemplate": "^master-\\w*"
}
],
"packageRules": [
{
"matchDatasources": ["github-releases"],
"matchDepNames": ["cpp-linter/clang-tools-static-binaries"],
"matchUpdateTypes": ["minor", "patch"],
"automerge": true
}
]
}
"extends": ["config:base"],
"customManagers": [
{
"customType": "regex",
"fileMatch": ["**/__init__.py"],
"matchStringsStrategy": "any",
"matchStrings": [
"release_tag = \\s*\"(?<currentValue>.*)\"\\s*//"
],
"depNameTemplate": "release_tag = 'master-1234abcd'",
"datasourceTemplate": "github-releases"
}
],
"packageRules": [
{
"managers": ["regex"],
"datasources": ["github-releases"],
"updateTypes": ["major", "minor", "patch"]
}
],
"repositories": [
{
"matchDatasource": "github-releases",
"matchPackageNames": ["cpp-linter/clang-tools-static-binaries"],
"enabled": true
}
]
}
7 changes: 4 additions & 3 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from clang_tools import install_os
from clang_tools.install import clang_tools_binary_url
from clang_tools.util import check_install_os, download_file, get_sha_checksum
from clang_tools import release_tag


def test_check_install_os():
Expand All @@ -13,12 +14,12 @@ def test_check_install_os():


@pytest.mark.parametrize(
"tag", ["master-be694ee7", pytest.param("latest", marks=pytest.mark.xfail)]
"tag", [release_tag, pytest.param("latest", marks=pytest.mark.xfail)]
)
def test_download_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, tag: str):
"""Test that deliberately fails to download a file."""
monkeypatch.chdir(str(tmp_path))
url = clang_tools_binary_url("clang-format", "12", release_tag=tag)
url = clang_tools_binary_url("clang-format", "12", tag=release_tag)
file_name = download_file(url, "file.tar.gz", True)
assert file_name is not None

Expand All @@ -30,5 +31,5 @@ def test_get_sha(monkeypatch: pytest.MonkeyPatch):
expected = Path(f"clang-format-12_{install_os}-amd64.sha512sum").read_text(
encoding="utf-8"
)
url = clang_tools_binary_url("clang-format", "12", release_tag="master-be694ee7")
url = clang_tools_binary_url("clang-format", "12", tag=release_tag)
assert get_sha_checksum(url) == expected
10 changes: 10 additions & 0 deletions updatecli/check-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

lastest_tag=`curl -s https://api.github.com/repos/cpp-linter/clang-tools-static-binaries/releases/latest | jq -r '.tag_name'`
current_tag=`grep -oP "^release_tag = '\K[^']+" ../clang_tools/__init__.py`

if [[ $lastest_tag = $current_tag ]]; then
exit 0;
else
eixt 1;
fi
20 changes: 20 additions & 0 deletions updatecli/update-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

new_release_tag=$1
file_path="clang_tools/__init__.py"
regex="^release_tag = 'master-\\w*'"

script_dir=`pwd`
cd "$script_dir/.."

# Check if the file exists
if [ -f "$file_path" ]; then
# Use sed to replace the regex with the desired string
sed -i "s/$regex/release_tag = '$new_release_tag'/g" "$file_path"
echo "release_tag updated successfully."
else
echo "File $file_path not found."
fi

# Return to the original directory
cd - >/dev/null
54 changes: 54 additions & 0 deletions updatecli/updatecli.d/clang-tools-static-binaries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
name: Bump clang-tools static binaries version

scms:
default:
kind: github
spec:
user: "{{ .github.user }}"
email: "{{ .github.email }}"
owner: "{{ .github.owner }}"
repository: "{{ .github.repository }}"
token: "{{ requiredEnv .github.token }}"
username: "{{ .github.username }}"
branch: "{{ .github.branch }}"

sources:
lastVersion:
kind: githubrelease
name: Get the latest clang-tools static binaries version
spec:
owner: "cpp-linter"
repository: "clang-tools-static-binaries"
token: "{{ requiredEnv .github.token }}"
username: "{{ .github.username }}"
versionfilter:
kind: latest
transformers:
- addprefix: "master-"

conditions:
checkIfReleaseIsAvailable:
sourceid: lastVersion
kind: shell
spec:
command: bash ./updatecli/check-tag.sh # source input value passed as argument

targets:
updateVersion:
name: "Update clang-tools-pip"
sourceid: lastVersion
scmid: github
kind: shell
spec:
command: bash {{ "GITHUB_WORKSPACE" }}/updatecli/update-tag.sh

actions:
default:
kind: github/pullrequest
scmid: default
title: Bump clang-tools-static-binaries version to {{ source "lastVersion" }}
spec:
labels:
- dependencies
- clang-tools-static-binaries
8 changes: 8 additions & 0 deletions updatecli/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github:
user: "Cpp Linter Bot (updatecli)"
email: "60776566+cpp-linter-bot@users.noreply.github.com"
username: "cpp-linter-bot"
token: "CPP_LINTER_TOKEN"
branch: "main"
owner: "cpp-linter"
repository: "clang-tools-pip"