Skip to content

Commit cbdbeb0

Browse files
authored
Add contribution guidelines, pre-commit and releasenotes (#215)
This PR adds support for contribution guidelines, pre-commit and releasenotes to the qe-compiler.
1 parent b6b3404 commit cbdbeb0

33 files changed

+884
-226
lines changed

.github/renos_updated.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# This script makes sure a reno has been updated in the PR.
3+
4+
reno lint
5+
6+
CHANGED_FILES=$(git diff --name-only origin/main $GITHUB_SHA)
7+
for file in $CHANGED_FILES
8+
do
9+
root=$(echo "./$file" | awk -F/ '{print FS $2}' | cut -c2-)
10+
if [ "$root" = "releasenotes" ]; then
11+
exit 0;
12+
fi
13+
done
14+
15+
echo Please add or update a release note in ./releasenotes >&2
16+
exit 1
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# (C) Copyright IBM 2024.
2+
#
3+
# This code is part of Qiskit.
4+
#
5+
# This code is licensed under the Apache License, Version 2.0 with LLVM
6+
# Exceptions. You may obtain a copy of this license in the LICENSE.txt
7+
# file in the root directory of this source tree.
8+
#
9+
# Any modifications or derivative works of this code must retain this
10+
# copyright notice, and modified files need to carry a notice indicating
11+
# that they have been altered from the originals.
12+
13+
# Workaround CI permissions for forks
14+
# https://github.com/ZedThree/clang-tidy-review?tab=readme-ov-file#usage-in-fork-environments-split-workflow
15+
name: Post clang-tidy review comments
16+
17+
on:
18+
workflow_run:
19+
# The name field of the lint action
20+
# Defined in lint.yml workflow
21+
workflows:
22+
- Static Checks
23+
types:
24+
- completed
25+
26+
jobs:
27+
post-clang-tidy:
28+
name: Post clang-tidy review comments
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: ZedThree/clang-tidy-review/[email protected]
32+
# lgtm_comment_body, max_comments, and annotations need to be set on the posting workflow in a split setup
33+
with:
34+
# adjust options as necessary
35+
lgtm_comment_body: ''
36+
annotations: false
37+
max_comments: 10

.github/workflows/lint.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# (C) Copyright IBM 2024.
2+
#
3+
# This code is part of Qiskit.
4+
#
5+
# This code is licensed under the Apache License, Version 2.0 with LLVM
6+
# Exceptions. You may obtain a copy of this license in the LICENSE.txt
7+
# file in the root directory of this source tree.
8+
#
9+
# Any modifications or derivative works of this code must retain this
10+
# copyright notice, and modified files need to carry a notice indicating
11+
# that they have been altered from the originals.
12+
name: Static Checks
13+
on: [push, pull_request]
14+
jobs:
15+
Build:
16+
runs-on: ubuntu-latest
17+
env:
18+
CONAN_USER_HOME: ${{ github.workspace }}
19+
steps:
20+
- name: free-up-space
21+
run: |
22+
df -h
23+
sudo rm -rf /usr/share/dotnet
24+
sudo rm -rf /opt/ghc
25+
sudo rm -rf "/usr/local/share/boost"
26+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
27+
df -h
28+
- uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
- name: Set up Python
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: '3.10.9'
35+
- name: Install pip packages
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install -r requirements-dev.txt
39+
- name: Static checks
40+
id: static_checks
41+
if: github.event_name == 'pull_request'
42+
run: pre-commit run --all-files --show-diff-on-failure
43+
- name: Validate releasenotes
44+
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'no-reno')
45+
env:
46+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
47+
run: ./.github/renos_updated.sh
48+
- name: Export QSSC_VERSION from Git version tag
49+
run: |
50+
version=`python -c "from setuptools_scm import get_version; print(get_version())"`
51+
echo "QSSC_VERSION=$version" >> $GITHUB_ENV
52+
- name: Load Conan cache
53+
id: cache
54+
uses: actions/cache/restore@v3
55+
with:
56+
path: .conan
57+
key: conan-${{ runner.os }}
58+
restore-keys: conan-${{ runner.os }}
59+
- name: Create Conan default profile
60+
run: |
61+
conan profile new default --detect || true
62+
conan profile update settings.compiler.libcxx=libstdc++11 default
63+
- name: Add QASM, LLVM, and clang tools recipes to Conan cache.
64+
run: ./conan_deps.sh
65+
- name: Create build dir
66+
run: mkdir build
67+
# Check if all conan packages are within the cache. If not
68+
# we will need to build packages (and if on main flush the cache)
69+
- name : Check Conan dependencies are cached
70+
id: check_conan_cache
71+
working-directory: build
72+
run: |
73+
export CONAN_LLVM_GIT_CACHE="${{ runner.temp }}/llvm-project"
74+
conan install .. -pr:h default -pr:b default
75+
if [ $? -ne 0 ]
76+
then
77+
cache_hit=false
78+
else
79+
cache_hit=true
80+
fi
81+
echo "cache_hit=$cache_hit" >> $GITHUB_OUTPUT
82+
echo "Cache was hit: $cache_hit"
83+
- name: Conan install
84+
id: conan_install
85+
working-directory: build
86+
run: |
87+
export CONAN_LLVM_GIT_CACHE="${{ runner.temp }}/llvm-project"
88+
conan install .. --build=outdated -pr:h default -pr:b default
89+
- name: Configure
90+
id: configure
91+
working-directory: build
92+
run: |
93+
conan build .. --configure
94+
# Workaround CI permissions for forks
95+
# https://github.com/ZedThree/clang-tidy-review?tab=readme-ov-file#usage-in-fork-environments-split-workflow
96+
# The name is sensitive make sure to also update `clang-tidy-review-comments.yml` workflow
97+
- name: Clang tidy
98+
uses: ZedThree/[email protected]
99+
id: clang_tidy
100+
if: github.event_name == 'pull_request'
101+
with:
102+
config_file: '.clang-tidy'
103+
build_dir: build
104+
split_workflow: true
105+
- name: Clang tidy upload
106+
uses: ZedThree/clang-tidy-review/[email protected]
Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) Copyright IBM 2023.
1+
# (C) Copyright IBM 2023, 2024.
22
#
33
# This code is part of Qiskit.
44
#
@@ -9,7 +9,7 @@
99
# Any modifications or derivative works of this code must retain this
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
12-
name: Continuous Integration
12+
name: Build
1313
on: [push, pull_request]
1414
jobs:
1515
Build:
@@ -20,19 +20,14 @@ jobs:
2020
- name: free-up-space
2121
run: |
2222
df -h
23-
sudo rm -rf /usr/share/dotnet
23+
sudo rm -rf /usr/share/dotnet
2424
sudo rm -rf /opt/ghc
2525
sudo rm -rf "/usr/local/share/boost"
2626
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
2727
df -h
2828
- uses: actions/checkout@v3
2929
with:
3030
fetch-depth: 0
31-
# -- REMOVE ONCE OPEN SOURCE
32-
# Needed until Qiskit/qss-qasm is public.
33-
- uses: webfactory/[email protected]
34-
with:
35-
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
3631
- name: Set up Python
3732
uses: actions/setup-python@v4
3833
with:
@@ -45,23 +40,13 @@ jobs:
4540
run: |
4641
version=`python -c "from setuptools_scm import get_version; print(get_version())"`
4742
echo "QSSC_VERSION=$version" >> $GITHUB_ENV
48-
- name: Try load Conan cache
43+
- name: Load Conan cache
4944
id: cache
5045
uses: actions/cache/restore@v3
5146
with:
5247
path: .conan
53-
key: conan-${{ runner.os }}-${{ hashFiles('conandata.yml', 'conanfile.py', 'conan/**/*.py', 'conan/**/*.yml') }}
48+
key: conan-${{ runner.os }}
5449
restore-keys: conan-${{ runner.os }}
55-
- name : Print cache hit/miss
56-
run: |
57-
echo "Cache was hit: ${{ steps.cache.outputs.cache-hit }}"
58-
# If we have a cache miss on 'main', clear the cache.
59-
# A dependency was updated, so we need to drop the old one
60-
# to prevent unbounded cache growth over time.
61-
- name : Clear Conan cache
62-
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.cache.outputs.cache-hit != 'true'
63-
run: |
64-
rm -rf ./.conan
6550
- name: Create Conan default profile
6651
run: |
6752
conan profile new default --detect || true
@@ -70,6 +55,30 @@ jobs:
7055
run: ./conan_deps.sh
7156
- name: Create build dir
7257
run: mkdir build
58+
# Check if all conan packages are within the cache. If not
59+
# we will need to build packages (and if on main flush the cache)
60+
- name : Check Conan dependencies are cached
61+
id: check_conan_cache
62+
working-directory: build
63+
run: |
64+
export CONAN_LLVM_GIT_CACHE="${{ runner.temp }}/llvm-project"
65+
conan install .. -pr:h default -pr:b default
66+
if [ $? -ne 0 ]
67+
then
68+
cache_hit=false
69+
else
70+
cache_hit=true
71+
fi
72+
echo "cache_hit=$cache_hit" >> $GITHUB_OUTPUT
73+
echo "Cache was hit: $cache_hit"
74+
# If we have a cache miss on 'main', clear the cache.
75+
# A dependency was updated, so we need to drop the old one
76+
# to prevent unbounded cache growth over time.
77+
- name : Clear Conan cache
78+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.check_conan_cache.outputs.cache_hit != 'true'
79+
run: |
80+
echo "Cache was hit: ${{ steps.check_conan_cache.outputs.cache_hit }}"
81+
rm -rf ./.conan
7382
- name: Conan install
7483
id: conan_install
7584
working-directory: build
@@ -85,28 +94,11 @@ jobs:
8594
id: test
8695
working-directory: build
8796
run: conan build .. --test
88-
89-
# On 'pull_request' run Clang tidy
90-
- name: Clang tidy
91-
uses: ZedThree/[email protected]
92-
id: clang_tidy
93-
if: github.event_name == 'pull_request'
94-
with:
95-
config_file: '.clang-tidy'
96-
build_dir: build
97-
98-
# On 'pull_request' run Clang format and commit the changes
99-
- name: Clang format
100-
id: clang_format
101-
if: github.event_name == 'pull_request'
102-
working-directory: build
103-
run: ninja check-format
104-
10597
# On 'main' branch, always save the cache if Conan install succeeded.
10698
# Note: we only update the cache from 'main' to avoid "cache thrashing", which would result in the 'main'
10799
# cache getting LRU-evicted for every PR, since a single run uses most of the 10GB repo limit.
108100
- uses: actions/cache/save@v3
109-
if: always() && (github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.conan_install.outcome == 'success' && steps.cache.outputs.cache-hit != 'true')
101+
if: always() && (github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.conan_install.outcome == 'success' && steps.check_conan_cache.outputs.cache_hit != 'true')
110102
with:
111103
path: .conan
112-
key: conan-${{ runner.os }}-${{ hashFiles('conandata.yml', 'conanfile.py', 'conan/**/*.py', 'conan/**/*.yml') }}
104+
key: conan-${{ runner.os }}

.pre-commit-config.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: no-commit-to-branch
6+
stages: [commit]
7+
args: [--branch, main, --pattern, release/.*, --pattern, .*/release/.*]
8+
- id: check-json
9+
stages: [commit]
10+
- id: end-of-file-fixer
11+
stages: [commit]
12+
exclude: '.+(\.s[ql][23])$'
13+
- id: trailing-whitespace
14+
stages: [commit]
15+
args: [--markdown-linebreak-ext=md]
16+
exclude: '.+(\.s[ql][23])$'
17+
- id: check-merge-conflict
18+
stages: [commit]
19+
- id: debug-statements
20+
stages: [commit]
21+
- repo: https://github.com/psf/black
22+
rev: 22.3.0
23+
hooks:
24+
- id: black
25+
stages: [commit]
26+
args:
27+
- "-l 100"
28+
- repo: https://github.com/pre-commit/mirrors-clang-format
29+
rev: v17.0.5
30+
hooks:
31+
- id: clang-format
32+
stages: [commit]
33+
args:
34+
- "--style=file:.clang-format"
35+
- repo: https://github.com/PyCQA/flake8.git
36+
rev: 4.0.1
37+
hooks:
38+
- id: flake8
39+
stages: [commit]
40+
args:
41+
- "--max-line-length=100"
42+
- "--extend-ignore=W503"

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ list(APPEND RUN_CLANG_TIDY_BIN_ARGS
245245
-clang-tidy-binary ${CLANG_TIDY_BIN}
246246
-clang-apply-replacements-binary ${CLANG_AR_BIN}
247247
-style=file
248+
# Limit clang-tidy to project headers
249+
-header-filter="${CMAKE_SOURCE_DIR}/*.h"
248250
-quiet
249251
)
250252

0 commit comments

Comments
 (0)