-
Notifications
You must be signed in to change notification settings - Fork 400
90 lines (80 loc) · 3.51 KB
/
Copy pathpre-commit.yml
File metadata and controls
90 lines (80 loc) · 3.51 KB
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
name: pre-commit
on:
push:
branches:
- develop
- release/therock-*
pull_request:
branches: [develop]
permissions:
contents: read
concurrency:
# For PRs, group by PR number so a new commit cancels any in-progress run
# for the same PR. For postsubmits, group by commit SHA (unique per commit)
# so runs never cancel each other. The workflow name is prepended to avoid
# conflicts between different workflows.
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
cancel-in-progress: true
jobs:
pre-commit:
runs-on: ubuntu-24.04
env:
# For PRs, diff against the base branch. For pushes, diff against the
# commit that existed before the push (github.event.before).
FROM_REF: ${{ github.event.pull_request.base.ref && format('origin/{0}', github.event.pull_request.base.ref) || github.event.before }}
DEFAULT_REF: ${{ format('origin/{0}', github.event.repository.default_branch) }}
# A branch-creation push has no source ref in its event payload. It falls
# back to the default branch's merge base and can include inherited changes
# when the branch originates elsewhere. PRs use their actual base ref.
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# Blobless partial clone; the sparse-checkout below materializes only
# the projects touched by the diff instead of the full ~9 GB tree.
filter: blob:none
sparse-checkout: .github
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.12'
- name: Prepare pre-commit diff base and sparse-checkout
id: prep
env:
CURRENT_BRANCH: ${{ github.ref_name }}
run: |
python .github/scripts/pre_commit_helper.py \
--from-ref $FROM_REF \
--default-ref $DEFAULT_REF \
--pushed-branch-name $CURRENT_BRANCH
- name: Detect project changes
id: changes
env:
CHANGED_FILES: ${{ steps.prep.outputs.changed_files }}
# Add project names here (one per line) to enable conditional dependency installation
PROJECTS_WITH_OPTIONAL_DEPS: >-
hipdnn
run: |
# Check each project for changes
for project in $PROJECTS_WITH_OPTIONAL_DEPS; do
if echo "$CHANGED_FILES" | grep -qE "^(projects|shared)/$project/"; then
echo "${project}_changed=true" >> $GITHUB_OUTPUT
else
echo "${project}_changed=false" >> $GITHUB_OUTPUT
fi
done
# To install optional deps for a project:
# 1. Add project name to PROJECTS_WITH_OPTIONAL_DEPS above
# 2. Like the example below, add an install step conditional on:
# - steps.changes.outputs.<project-name>_changed == 'true'
- name: Install hipDNN dependencies
if: steps.changes.outputs.hipdnn_changed == 'true'
run: |
wget -q https://github.com/google/flatbuffers/releases/download/v25.9.23/Linux.flatc.binary.g++-13.zip
unzip -q Linux.flatc.binary.g++-13.zip
sudo mv flatc /usr/local/bin/
sudo chmod +x /usr/local/bin/flatc
rm Linux.flatc.binary.g++-13.zip
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
with:
# Only check changed files in the PR/push.
extra_args: --from-ref ${{ steps.prep.outputs.diff_ref }} --to-ref HEAD