mirror of
https://gh.llkk.cc/https://github.com/WeblateOrg/scripts.git
synced 2025-10-03 15:01:00 +08:00
94 lines
3.3 KiB
YAML
94 lines
3.3 KiB
YAML
# 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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.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@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
|
|
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@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
|
|
with:
|
|
python-version: '3.13'
|
|
- uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.7.0
|
|
- 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
|
|
- 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
|
|
- 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
|
|
- 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'
|