Skip to content

more changes

more changes #12

Workflow file for this run

name: pre-commit
on:
push:
branches:
- main
- release-*
pull_request:
branches:
- main
- release-*
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true
env:
# renovate: datasource=pypi depName=pre-commit versioning=pep440
PRE_COMMIT_VERSION: ==3.3.1
# renovate: datasource=go depName=github.com/golangci/golangci-lint
GOLANGCI_LINT_VERSION: v1.52.2
jobs:
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Check if pre-commit should run on all files
id: run-all-files
uses: fkirc/skip-duplicate-actions@12aca0a884f6137d619d6a8a09fcc3406ced5281 # v5.3.0
continue-on-error: true
with:
do_not_skip: '["schedule", "workflow_dispatch"]'
paths: |-
[
".github/workflows/pre-commit.yml",
".go-version",
".pre-commit-config.yaml"
]
skip_after_successful_duplicate: false
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
with:
go-version-file: .go-version
cache: true
- name: Set up Clang
uses: KyleMayes/install-llvm-action@13d5d77cbf0bd7e35cb02a8f9ed4bb85bed3393b # v1.8.0
with:
version: "14"
- name: Install golangci-lint
run: go install "github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}"
- name: Set golangci-lint cache key parts
run: |
echo "INTERVAL_KEY=$(( $(date +%s) / (7 * 86400) ))" >> $GITHUB_ENV
# GH Actions hashFiles() function uses SHA512
echo "GO_MOD_SHA1=$(sha1sum go.mod | cut -d' ' -f1)" >> $GITHUB_ENV
# Same as https://github.com/golangci/golangci-lint-action#caching-internals
- name: Set up golangci-lint cache
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: |
~/.cache/golangci-lint
~/.cache/go-build
~/go/pkg
# https://github.com/golangci/golangci-lint-action/blob/v3.2.0/src/cache.ts#L53-L69
key: golangci-lint.cache-${{ env.INTERVAL_KEY }}-${{ env.GO_MOD_SHA1 }}
restore-keys: |
golangci-lint.cache-${{ env.INTERVAL_KEY }}-
golangci-lint.cache-
- name: Set up pre-commit
run: pipx install "pre-commit${PRE_COMMIT_VERSION}"
- name: Set pre-commit cache key parts
run: |
echo "GO_VERSION=$(<.go-version)" >> $GITHUB_ENV
echo "PY_HASH=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- name: Set up pre-commit cache
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/.cache/pre-commit
key: pre-commit-go${{ env.GO_VERSION }}-${{ env.PY_HASH }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install libbpf dependencies
run: |
sudo apt-get update -y
sudo apt-get install -yq libelf-dev zlib1g-dev
- name: Initialize and update git submodules
run: git submodule init && git submodule update
- name: Build libbpf
run: make libbpf
- name: Run pre-commit
run: |
declare -a EXTRA_ARGS=()
if [[ '${{ steps.run-all-files.outputs.should_skip }}' != 'true' ]]; then
EXTRA_ARGS=(--all-files)
elif [[ "${GITHUB_EVENT_NAME}" == 'pull_request' ]]; then
EXTRA_ARGS=(--from-ref "origin/${GITHUB_BASE_REF}" --to-ref "${GITHUB_SHA}")
else
EXTRA_ARGS=(--from-ref "${GITHUB_SHA}^" --to-ref "${GITHUB_SHA}")
fi
pre-commit run --show-diff-on-failure --color=always "${EXTRA_ARGS[@]}"
- name: 'pre-commit-ci-lite: Apply automatic fixes'
uses: pre-commit-ci/lite-action@2529d76d2c5ffdf2a85aa090c38949eada94d39d # v1.0.1
if: always()