File: pre-commit.yml

package info (click to toggle)
unicode-segmentation-rs 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 228 kB
  • sloc: python: 338; makefile: 18
file content (99 lines) | stat: -rw-r--r-- 3,591 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: CC0-1.0

# This file is maintained in https://github.com/WeblateOrg/meta/
name: Pre-commit check

on:
  push:
    branches-ignore:
    - renovate/**
    - weblate
  pull_request:

permissions:
  contents: read

jobs:
  pre-commit:
    runs-on: ubuntu-24.04

    steps:
    - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      with:
        persist-credentials: false
    - name: Get cache tag
      id: get-date
      run: |
        echo "cache_tag=$(/bin/date --utc '+%Y%m')" >> "$GITHUB_OUTPUT"
        echo "previous_cache_tag=$(/bin/date --date='1 month ago' --utc '+%Y%m')" >> "$GITHUB_OUTPUT"
      shell: bash
    - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
      id: pre-commit-cache
      with:
        path: ~/.cache/pre-commit
        key: ${{ runner.os }}-pre-commit-${{ steps.get-date.outputs.cache_tag }}-${{ hashFiles('.pre-commit-config.yaml') }}
        restore-keys: |
          ${{ runner.os }}-pre-commit-${{ steps.get-date.outputs.cache_tag }}
          ${{ runner.os }}-pre-commit-${{ steps.get-date.outputs.previous_cache_tag }}
          ${{ runner.os }}-pre-commit-
    - name: Setup Python
      uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
      with:
        python-version: '3.14'
    - uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
      with:
        enable-cache: false
    - name: detect method
      id: detect
      run: |
        if test -f requirements-lint.txt ; then
          echo "method=requirements" >> "$GITHUB_OUTPUT"
        elif test -f pyproject.toml && grep -q dependency-groups pyproject.toml ; then
          echo "method=pep735" >> "$GITHUB_OUTPUT"
        elif test -f pyproject.toml && grep -q dependency-groups pyproject.toml ; then
          echo "method=pyproject" >> "$GITHUB_OUTPUT"
        else
          echo "method=uvx" >> "$GITHUB_OUTPUT"
        fi
    - name: pre-commit (PEP 735)
      if: steps.detect.outputs.method == 'pep735'
      run: |
        uv run --only-group pre-commit pre-commit run --all --show-diff-on-failure
        uv run --only-group pre-commit pre-commit gc
      env:
        RUFF_OUTPUT_FORMAT: github
        REUSE_OUTPUT_FORMAT: github
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    - name: pre-commit (uvx)
      if: steps.detect.outputs.method == 'uvx'
      run: |
        uvx pre-commit run --all --show-diff-on-failure
        uvx pre-commit gc
      env:
        RUFF_OUTPUT_FORMAT: github
        REUSE_OUTPUT_FORMAT: github
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    - name: Install dependencies
      if: steps.detect.outputs.method == 'requirements'
      run: uv pip install --system -r requirements-lint.txt
    - name: Install dependencies
      if: steps.detect.outputs.method == 'pyproject'
      run: uv pip install --system "$(sed -n 's/.*"\(pre-commit==\([^"]*\)\)".*/\1/p' pyproject.toml)"
    - name: pre-commit (installed)
      if: steps.detect.outputs.method == 'requirements' || steps.detect.outputs.method == 'pyproject'
      run: |
        pre-commit run --all --show-diff-on-failure
        pre-commit gc
      env:
        RUFF_OUTPUT_FORMAT: github
        REUSE_OUTPUT_FORMAT: github
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    - name: diff
      run: git diff
      if: always()
    - uses: pre-commit-ci/lite-action@5d6cc0eb514c891a40562a58a8e71576c5c7fb43 # v1.1.0
      if: always()
      with:
        msg: 'chore(pre-commit): apply code formatting'