diff --git a/.github/hooks-template.yaml b/.github/hooks-template.yaml deleted file mode 100644 index 28e8b1a..0000000 --- a/.github/hooks-template.yaml +++ /dev/null @@ -1,20 +0,0 @@ -- id: taplo - name: taplo-cli - description: "A TOML toolkit written in Rust" - entry: taplo format - language: rust - types: [toml] - args: [] - require_serial: false - additional_dependencies: ["cli:taplo-cli:VERSION"] - minimum_pre_commit_version: "0" - -- id: taplo-docker - name: taplo-cli-docker - description: "A TOML toolkit written in Rust" - entry: tamasfe/taplo:VERSION - language: docker_image - types: [toml] - args: [format] - require_serial: false - minimum_pre_commit_version: "0" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b1b457a..b3f1025 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,33 +1,36 @@ name: CI -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -env: - PYTHONHASHSEED: "0" - on: - push: - branches: - - main - - epic/* - - "[0-9]+.[0-9]+.x" - pull_request: - branches: - - main - - epic/* - - "[0-9]+.[0-9]+.x" + schedule: + - cron: "50 1 * * 1" workflow_dispatch: - inputs: - specific-pip-packages: - description: Run CI with specific pip packages - required: false - type: string jobs: - style: - if: inputs.specific-pip-packages == '' - secrets: - token: ${{ secrets.PAT }} - uses: ComPWA/actions/.github/workflows/pre-commit.yml@v1 + update: + name: Upgrade hook + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-python@v5 + - run: pip install pre-commit-mirror-maker + - run: git config user.name 'Github Actions' + - run: git config user.email '41898282+github-actions[bot]@users.noreply.github.com' + - run: | + pre-commit-mirror . \ + --description="A TOML toolkit written in Rust" \ + --entry="taplo format" \ + --id=taplo \ + --language=python \ + --package-name=taplo \ + --types=toml + - run: | + git remote set-url origin https://x-access-token:${{ secrets.PAT }}@github.com/${{ github.repository }} + for tag in $(git tag); do + git push origin $tag + done + git push origin HEAD:refs/heads/main + # for-loop is required to trigger CI on the tags + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/clean-caches.yml b/.github/workflows/clean-caches.yml deleted file mode 100644 index a66c407..0000000 --- a/.github/workflows/clean-caches.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Clean caches - -on: - pull_request: - types: - - closed - workflow_dispatch: - inputs: - ref: - description: Clean caches for this branch name or ref - required: false - type: string - -jobs: - cleanup: - name: Remove caches - runs-on: ubuntu-22.04 - steps: - - uses: ComPWA/actions/clean-caches@v1 - with: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ref: ${{ inputs.ref }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 843948e..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Update Docker image - -on: - push: - branches: - - main - tags: - - v* - workflow_dispatch: - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-push-image: - permissions: - contents: read - packages: write - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/pr-linting.yml b/.github/workflows/pr-linting.yml deleted file mode 100644 index cd3bb74..0000000 --- a/.github/workflows/pr-linting.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: PR linting -on: - pull_request: - types: - - edited - - labeled - - opened - - reopened - - synchronize - - unlabeled - -jobs: - check-labels: - name: Check labels - runs-on: ubuntu-22.04 - steps: - - uses: docker://agilepathway/pull-request-label-checker:latest # cspell:ignore agilepathway - with: - any_of: >- - 🐛 Bug,✨ Feature,⚙️ Enhancement,⚠️ Interface,❗ Behavior,📝 Docs,🔨 Maintenance,🖱️ DX - none_of: Epic,💫 Good first issue - repo_token: ${{ secrets.GITHUB_TOKEN }} - - check-title: - name: Check title - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - run: npm install @compwa/commitlint-config - - name: Create commitlint config - run: | - echo "module.exports = {extends: ['@compwa/commitlint-config']}" > commitlint.config.js - - uses: JulienKode/pull-request-name-linter-action@v0.5.0 # cspell:ignore kode diff --git a/.github/workflows/update-tags.yml b/.github/workflows/update-tags.yml deleted file mode 100644 index d9238ab..0000000 --- a/.github/workflows/update-tags.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: CI - -on: - schedule: - - cron: "50 1 * * 1" - workflow_dispatch: - -jobs: - update: - name: Upgrade hook - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-python@v5 - with: - python-version: "3.8" - - run: pip install -r requirements.txt - - run: git config user.name 'Github Actions' - - run: git config user.email '41898282+github-actions[bot]@users.noreply.github.com' - - run: python3 .github/workflows/update_tags.py - - run: | - git remote set-url origin https://x-access-token:${{ secrets.PAT }}@github.com/${{ github.repository }} - for tag in $(git tag); do - git push origin $tag - done - git push origin HEAD:refs/heads/main - # for-loop is required to trigger CI on the tags - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/update_tags.py b/.github/workflows/update_tags.py deleted file mode 100644 index 1939eef..0000000 --- a/.github/workflows/update_tags.py +++ /dev/null @@ -1,113 +0,0 @@ -from __future__ import annotations - -import json -import subprocess -import urllib.request -from pathlib import Path -from urllib.parse import urlencode - -from ruamel.yaml import YAML -from ruamel.yaml.comments import CommentedMap, CommentedSeq - -PRE_COMMIT_CONFIG = Path(".pre-commit-config.yaml") -PRE_COMMIT_HOOKS = Path(".pre-commit-hooks.yaml") -TEMPLATE_PATH = Path(".github/hooks-template.yaml") - - -def main() -> int: - package_versions = get_rust_package_versions("taplo-cli") - docker_tags = set(get_docker_tags("tamasfe/taplo")) - existing_versions = {tag[1:] for tag in get_local_git_tags()} - for version in package_versions: - if version in existing_versions: - print(f"Tag already exists for version {version}") - continue - yaml, config = get_hook_config(version) - if version not in docker_tags: - config.pop() - yaml.dump(config, PRE_COMMIT_HOOKS) - update_pre_commit_config(version) - commit_and_tag(version) - - -def get_rust_package_versions(package_name: str) -> list[str]: - # https://github.com/pre-commit/pre-commit-mirror-maker/blob/c99d212/pre_commit_mirror_maker/languages.py - url = f"https://crates.io/api/v1/crates/{package_name}" - response = json.load(urllib.request.urlopen(url)) - return list(reversed([version["num"] for version in response["versions"]])) - - -def get_docker_tags(repo: str) -> list[str]: - token = _get_token(repo) - request = urllib.request.Request( - url=f"https://registry-1.docker.io/v2/{repo}/tags/list", - headers={ - "Authorization": f"Bearer {token}", - "Accept": "application/json", - }, - ) - with urllib.request.urlopen(request) as response: - data = response.read() - json_data = json.loads(data) - tags: list[str] = json_data["tags"] - return tags - - -def get_local_git_tags() -> list[str]: - output = subprocess.check_output(("git", "tag")).decode("utf-8") - tags = output.split("\n") - return tags - - -def get_hook_config(tag: str) -> tuple[YAML, CommentedSeq]: - yaml = _create_round_trip_yaml() - config = yaml.load(TEMPLATE_PATH) - cli_conf, docker_conf = config - deps = cli_conf["additional_dependencies"] - deps[0] = deps[0].replace("VERSION", tag) - docker_conf["entry"] = docker_conf["entry"].replace("VERSION", tag) - return yaml, config - - -def update_pre_commit_config(version: str) -> None: - yaml = _create_round_trip_yaml() - config: CommentedMap = yaml.load(PRE_COMMIT_CONFIG) - config["repos"][0]["rev"] = f"v{version}" - yaml.dump(config, PRE_COMMIT_CONFIG) - - -def commit_and_tag(version: str) -> None: - # https://github.com/pre-commit/pre-commit-mirror-maker/blob/c99d212 - def git(*cmd: str) -> None: - subprocess.check_call(("git",) + cmd) - - git("add", "-A") - git("commit", "-m", f"Mirror: {version}") - git("tag", f"v{version}") - print(f"Created tag v{version}") - - -def _get_token(repo: str) -> str: - query = dict( - service="registry.docker.io", - scope=f"repository:{repo}:pull", - ) - url = f"https://auth.docker.io/token?{urlencode(query)}" - with urllib.request.urlopen(url) as response: - data = response.read() - json_data = json.loads(data) - token = json_data["token"] - return token - - -def _create_round_trip_yaml() -> YAML: - yaml = YAML(typ="rt") - yaml.block_seq_indent = 2 - yaml.indent = 4 - yaml.map_indent = 2 - yaml.preserve_quotes = True - return yaml - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 2057737..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -condaenv.*.requirements.txt -node_modules/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index ccf6fe3..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,56 +0,0 @@ -ci: - autoupdate_commit_msg: "MAINT: autoupdate pre-commit hooks" - autoupdate_schedule: quarterly - skip: - - prettier - - taplo - -repos: - - repo: meta - hooks: - - id: check-hooks-apply - - id: check-useless-excludes - - rev: v0.9.0 - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - - id: check-case-conflict - - id: check-json - - id: check-merge-conflict - - id: check-toml - - id: check-vcs-permalinks - - id: check-yaml - - id: end-of-file-fixer - - id: mixed-line-ending - - id: trailing-whitespace - - - repo: https://github.com/ComPWA/policy - rev: 0.2.0 - hooks: - - id: check-dev-files - args: - - --ignore-author - - --no-github-actions - - --no-gitpod - - --no-prettierrc - - --no-python - - --no-version-branches - - --repo-name=mirrors-taplo - - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v4.0.0-alpha.8 - hooks: - - id: prettier - - - repo: https://github.com/ComPWA/mirrors-taplo - rev: v0.9.0 - hooks: - - id: taplo - - - repo: https://github.com/pappasam/toml-sort - rev: v0.23.1 - hooks: - - id: toml-sort - args: - - --in-place diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 07342cf..39da6db 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,11 +1,22 @@ - - id: taplo - name: taplo-cli - description: "A TOML toolkit written in Rust" + - id: taplo-format + alias: taplo + name: taplo-format + description: Format TOML documents entry: taplo format - language: rust + language: python types: [toml] args: [] require_serial: false - additional_dependencies: ["cli:taplo-cli:0.9.0"] + additional_dependencies: [] minimum_pre_commit_version: "0" + - id: taplo-lint + name: taplo-lint + description: Lint TOML documents + entry: taplo lint + language: python + types: [toml] + args: [--default-schema-catalogs] + require_serial: false + additional_dependencies: [] + minimum_pre_commit_version: "0" diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 28e0af3..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "recommendations": [ - "esbenp.prettier-vscode", - "github.vscode-github-actions", - "ms-azuretools.vscode-docker", - "ms-python.python", - "redhat.vscode-yaml", - "Soulcode.vscode-unwanted-extensions", - "stkb.rewrap" - ], - "unwantedRecommendations": [ - "davidanson.vscode-markdownlint", - "garaioag.garaio-vscode-unwanted-recommendations", - "streetsidesoftware.code-spell-checker", - "travisillig.vscode-json-stable-stringify" - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 74d4a5a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "[git-commit]": { - "editor.rulers": [72], - "rewrap.wrappingColumn": 72 - }, - "diffEditor.experimental.showMoves": true, - "editor.formatOnSave": true, - "github-actions.workflows.pinned.workflows": [".github/workflows/ci.yml"], - "multiDiffEditor.experimental.enabled": true, - "rewrap.wrappingColumn": 88 -} diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index e7ce0ca..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[bin]] -name = "__fake_cmd" -path = "main.rs" - -[package] -name = "__fake_crate" -version = "0.0.0" diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 92c3760..0000000 --- a/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM ubuntu:22.04 - -RUN apt-get update \ - && apt-get install -y \ - curl \ - git \ - pkg-config \ - python3-pip \ - && apt-get autoclean -y \ - && apt-get autoremove -y \ - && rm -rf /var/lib/apt/lists/* - -# https://github.com/pre-commit/pre-commit/issues/2823 -RUN python3 -m pip install pre-commit!=3.2.0 - -WORKDIR /project - -COPY .pre-commit-config.yaml . -RUN git init . && pre-commit install-hooks diff --git a/README.md b/README.md index f30afbf..613d375 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ -# Taplo mirror +# Taplo TOML formatter mirror -[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) - -Mirror of [Taplo](https://github.com/tamasfe/taplo) for [pre-commit](https://pre-commit.com), created with a modified version of [`pre-commit-mirror-maker`](https://github.com/pre-commit/pre-commit-mirror-maker) (see [this workflow](./.github/workflows/update-tags.yml)). +Mirror of [ComPWA/taplo](https://github.com/ComPWA/taplo) (which is a PyPI fork of Mirror of [tamasfe/taplo](https://github.com/tamasfe/taplo)) for [pre-commit](https://pre-commit.com), created with a modified version of [`pre-commit-mirror-maker`](https://github.com/pre-commit/pre-commit-mirror-maker) (see [this workflow](./.github/workflows/update-tags.yml)). ### Using Taplo with pre-commit @@ -13,7 +11,7 @@ repos: - repo: https://github.com/ComPWA/mirrors-taplo rev: "" hooks: - - id: taplo + - id: taplo-format ``` then run @@ -22,53 +20,13 @@ then run pre-commit autoupdate --repo https://github.com/ComPWA/mirrors-taplo ``` -#### Using Taplo with pre-commit via Docker - -Add this to your `.pre-commit-config.yaml` +Optionally, you can also install the Taplo linter as a pre-commit hook: ```yaml repos: - repo: https://github.com/ComPWA/mirrors-taplo rev: "" hooks: - - id: taplo-docker -``` - -then run - -```shell -pre-commit autoupdate --repo https://github.com/ComPWA/mirrors-taplo -``` - -### Docker container - -Since it can take a several minutes to install the `taplo` hook, this repository also [provides a Docker container](https://github.com/ComPWA/mirrors-taplo/pkgs/container/mirrors-taplo) with caches for the `taplo` pre-commit hook for each tag. Here's an example of how to use this container in your GitHub Actions: - -```yaml -on: - pull_request: - branches: - - main - push: - branches: - - main - -jobs: - cleanup: - container: - image: ghcr.io/compwa/mirrors-taplo:v0.8.0 - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - name: Run taplo through pre-commit - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - run: git config --global --add safe.directory $(pwd) - - env: - PRE_COMMIT_HOME: /root/.cache/pre-commit - run: | - pre-commit run taplo -a + - id: taplo-format + - id: taplo-lint ``` - -**WARNING**: the cache is only effective if the tag of the container is the same as the tag of the pre-commit hook in your `.pre-commit-config.yaml`. diff --git a/environment.yml b/environment.yml deleted file mode 100644 index 51fe7d8..0000000 --- a/environment.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: mirrors-taplo -dependencies: - - python==3.8.* - - pip - - pip: - - -r requirements.txt -variables: - PRETTIER_LEGACY_CLI: "1" diff --git a/main.rs b/main.rs deleted file mode 100644 index f328e4d..0000000 --- a/main.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 24e470a..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pre-commit!=3.2.0 -ruamel.yaml diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0d9eff5 --- /dev/null +++ b/setup.py @@ -0,0 +1,10 @@ +from __future__ import annotations + +from setuptools import setup + + +setup( + name='pre_commit_placeholder_package', + version='0.0.0', + install_requires=['taplo==0.8.0'], +)