Skip to content

Commit f57cf4a

Browse files
committed
[CI] Create reusable pre-commit workflows
1 parent 3bd5410 commit f57cf4a

File tree

4 files changed

+97
-20
lines changed

4 files changed

+97
-20
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: pre-commit
19+
20+
on: [pull_request]
21+
22+
permissions:
23+
contents: read
24+
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
27+
cancel-in-progress: true
28+
29+
jobs:
30+
run:
31+
name: Run manual hooks
32+
uses: ./.github/workflows/pre-commit-reusable.yml
33+
with:
34+
job_id: 'manual'
35+
extra_args: '--hook-stage manual'
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: _pre-commit-base
19+
20+
on:
21+
workflow_call:
22+
inputs:
23+
extra_args:
24+
required: false
25+
type: string
26+
default: ''
27+
job_id:
28+
required: true
29+
type: string
30+
31+
permissions:
32+
contents: read
33+
34+
jobs:
35+
run-hooks:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: 'Checkout ${{ github.ref }} ( ${{ github.sha }} )'
39+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
40+
with:
41+
persist-credentials: false
42+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
43+
with:
44+
python-version: '3.10'
45+
architecture: 'x64'
46+
- name: Install dependencies
47+
run: |
48+
python -m pip install --upgrade pip
49+
pip install pre-commit
50+
- name: set PY
51+
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> "$GITHUB_ENV"
52+
- uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
53+
with:
54+
path: ~/.cache/pre-commit
55+
key: pre-commit|${{ inputs.job_id }}|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
56+
- name: Run pre-commit
57+
run: pre-commit run --color=always --all-files --show-diff-on-failure ${{ inputs.extra_args }}

.github/workflows/pre-commit.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,7 @@ concurrency:
2828

2929
jobs:
3030
pre-commit:
31-
name: Run pre-commit
32-
runs-on: ubuntu-22.04
33-
steps:
34-
- name: Check Out
35-
uses: actions/checkout@v5
36-
- name: Install
37-
run: |
38-
python -m pip install --upgrade pip
39-
pip install pre-commit
40-
- name: Set PY
41-
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
42-
- uses: actions/cache@v5
43-
with:
44-
path: ~/.cache/pre-commit
45-
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
46-
- name: Run pre-commit
47-
run: pre-commit run --color=always --all-files
48-
- name: Run manual pre-commit hooks
49-
run: pre-commit run --color=always --all-files --hook-stage manual
31+
name: Run pre-commit standard
32+
uses: ./.github/workflows/pre-commit-reusable.yml
33+
with:
34+
job_id: 'standard'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[![codecov](https://codecov.io/gh/apache/cloudstack/branch/main/graph/badge.svg)](https://codecov.io/gh/apache/cloudstack)
2424
[![Docker CloudStack Simulator Status](https://github.com/apache/cloudstack/actions/workflows/docker-cloudstack-simulator.yml/badge.svg?branch=main)](https://github.com/apache/cloudstack/actions/workflows/docker-cloudstack-simulator.yml)
2525
[![License Check](https://github.com/apache/cloudstack/actions/workflows/rat.yml/badge.svg?branch=main)](https://github.com/apache/cloudstack/actions/workflows/rat.yml)
26-
[![Linter Status](https://github.com/apache/cloudstack/actions/workflows/linter.yml/badge.svg)](https://github.com/apache/cloudstack/actions/workflows/linter.yml)
26+
[![Linter Status](https://github.com/apache/cloudstack/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/apache/cloudstack/actions/workflows/pre-commit.yml)
2727
[![Merge Conflict Checker Status](https://github.com/apache/cloudstack/actions/workflows/merge-conflict-checker.yml/badge.svg?branch=main)](https://github.com/apache/cloudstack/actions/workflows/merge-conflict-checker.yml)
2828
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=apache_cloudstack&metric=alert_status)](https://sonarcloud.io/dashboard?id=apache_cloudstack)
2929
[![Simulator CI](https://github.com/apache/cloudstack/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/apache/cloudstack/actions/workflows/ci.yml)

0 commit comments

Comments
 (0)