diff --git a/.github/workflows/updatecli.yml b/.github/workflows/updatecli.yml new file mode 100644 index 0000000..1ae4ee4 --- /dev/null +++ b/.github/workflows/updatecli.yml @@ -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 }} diff --git a/clang_tools/__init__.py b/clang_tools/__init__.py index f432472..504f98d 100644 --- a/clang_tools/__init__.py +++ b/clang_tools/__init__.py @@ -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' diff --git a/clang_tools/install.py b/clang_tools/install.py index b270885..0ec3157 100644 --- a/clang_tools/install.py +++ b/clang_tools/install.py @@ -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 @@ -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(" ", "") diff --git a/renovate.json b/renovate.json index 4495f95..203ef45 100644 --- a/renovate.json +++ b/renovate.json @@ -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: (?.*)\\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*\"(?.*)\"\\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 + } + ] +} diff --git a/tests/test_util.py b/tests/test_util.py index 3b72a9b..0e998cf 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -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(): @@ -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 @@ -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 diff --git a/updatecli/check-tag.sh b/updatecli/check-tag.sh new file mode 100644 index 0000000..c4a3e42 --- /dev/null +++ b/updatecli/check-tag.sh @@ -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 diff --git a/updatecli/update-tag.sh b/updatecli/update-tag.sh new file mode 100644 index 0000000..4a90352 --- /dev/null +++ b/updatecli/update-tag.sh @@ -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 diff --git a/updatecli/updatecli.d/clang-tools-static-binaries.yaml b/updatecli/updatecli.d/clang-tools-static-binaries.yaml new file mode 100644 index 0000000..bab2f4e --- /dev/null +++ b/updatecli/updatecli.d/clang-tools-static-binaries.yaml @@ -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 diff --git a/updatecli/values.yaml b/updatecli/values.yaml new file mode 100644 index 0000000..5dba1fc --- /dev/null +++ b/updatecli/values.yaml @@ -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"