Skip to content

Commit

Permalink
Add contribution guidelines, pre-commit and releasenotes (#215)
Browse files Browse the repository at this point in the history
This PR adds support for contribution guidelines, pre-commit and
releasenotes to the qe-compiler.
  • Loading branch information
taalexander authored Jan 4, 2024
1 parent b6b3404 commit cbdbeb0
Show file tree
Hide file tree
Showing 33 changed files with 884 additions and 226 deletions.
16 changes: 16 additions & 0 deletions .github/renos_updated.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# This script makes sure a reno has been updated in the PR.

reno lint

CHANGED_FILES=$(git diff --name-only origin/main $GITHUB_SHA)
for file in $CHANGED_FILES
do
root=$(echo "./$file" | awk -F/ '{print FS $2}' | cut -c2-)
if [ "$root" = "releasenotes" ]; then
exit 0;
fi
done

echo Please add or update a release note in ./releasenotes >&2
exit 1
37 changes: 37 additions & 0 deletions .github/workflows/clang_tidy_review_comments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# (C) Copyright IBM 2024.
#
# This code is part of Qiskit.
#
# This code is licensed under the Apache License, Version 2.0 with LLVM
# Exceptions. You may obtain a copy of this license in the LICENSE.txt
# file in the root directory of this source tree.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

# Workaround CI permissions for forks
# https://github.com/ZedThree/clang-tidy-review?tab=readme-ov-file#usage-in-fork-environments-split-workflow
name: Post clang-tidy review comments

on:
workflow_run:
# The name field of the lint action
# Defined in lint.yml workflow
workflows:
- Static Checks
types:
- completed

jobs:
post-clang-tidy:
name: Post clang-tidy review comments
runs-on: ubuntu-latest
steps:
- uses: ZedThree/clang-tidy-review/[email protected]
# lgtm_comment_body, max_comments, and annotations need to be set on the posting workflow in a split setup
with:
# adjust options as necessary
lgtm_comment_body: ''
annotations: false
max_comments: 10
106 changes: 106 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# (C) Copyright IBM 2024.
#
# This code is part of Qiskit.
#
# This code is licensed under the Apache License, Version 2.0 with LLVM
# Exceptions. You may obtain a copy of this license in the LICENSE.txt
# file in the root directory of this source tree.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
name: Static Checks
on: [push, pull_request]
jobs:
Build:
runs-on: ubuntu-latest
env:
CONAN_USER_HOME: ${{ github.workspace }}
steps:
- name: free-up-space
run: |
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
df -h
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10.9'
- name: Install pip packages
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Static checks
id: static_checks
if: github.event_name == 'pull_request'
run: pre-commit run --all-files --show-diff-on-failure
- name: Validate releasenotes
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'no-reno')
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: ./.github/renos_updated.sh
- name: Export QSSC_VERSION from Git version tag
run: |
version=`python -c "from setuptools_scm import get_version; print(get_version())"`
echo "QSSC_VERSION=$version" >> $GITHUB_ENV
- name: Load Conan cache
id: cache
uses: actions/cache/restore@v3
with:
path: .conan
key: conan-${{ runner.os }}
restore-keys: conan-${{ runner.os }}
- name: Create Conan default profile
run: |
conan profile new default --detect || true
conan profile update settings.compiler.libcxx=libstdc++11 default
- name: Add QASM, LLVM, and clang tools recipes to Conan cache.
run: ./conan_deps.sh
- name: Create build dir
run: mkdir build
# Check if all conan packages are within the cache. If not
# we will need to build packages (and if on main flush the cache)
- name : Check Conan dependencies are cached
id: check_conan_cache
working-directory: build
run: |
export CONAN_LLVM_GIT_CACHE="${{ runner.temp }}/llvm-project"
conan install .. -pr:h default -pr:b default
if [ $? -ne 0 ]
then
cache_hit=false
else
cache_hit=true
fi
echo "cache_hit=$cache_hit" >> $GITHUB_OUTPUT
echo "Cache was hit: $cache_hit"
- name: Conan install
id: conan_install
working-directory: build
run: |
export CONAN_LLVM_GIT_CACHE="${{ runner.temp }}/llvm-project"
conan install .. --build=outdated -pr:h default -pr:b default
- name: Configure
id: configure
working-directory: build
run: |
conan build .. --configure
# Workaround CI permissions for forks
# https://github.com/ZedThree/clang-tidy-review?tab=readme-ov-file#usage-in-fork-environments-split-workflow
# The name is sensitive make sure to also update `clang-tidy-review-comments.yml` workflow
- name: Clang tidy
uses: ZedThree/[email protected]
id: clang_tidy
if: github.event_name == 'pull_request'
with:
config_file: '.clang-tidy'
build_dir: build
split_workflow: true
- name: Clang tidy upload
uses: ZedThree/clang-tidy-review/[email protected]
70 changes: 31 additions & 39 deletions .github/workflows/ci.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) Copyright IBM 2023.
# (C) Copyright IBM 2023, 2024.
#
# This code is part of Qiskit.
#
Expand All @@ -9,7 +9,7 @@
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
name: Continuous Integration
name: Build
on: [push, pull_request]
jobs:
Build:
Expand All @@ -20,19 +20,14 @@ jobs:
- name: free-up-space
run: |
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
df -h
- uses: actions/checkout@v3
with:
fetch-depth: 0
# -- REMOVE ONCE OPEN SOURCE
# Needed until Qiskit/qss-qasm is public.
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand All @@ -45,23 +40,13 @@ jobs:
run: |
version=`python -c "from setuptools_scm import get_version; print(get_version())"`
echo "QSSC_VERSION=$version" >> $GITHUB_ENV
- name: Try load Conan cache
- name: Load Conan cache
id: cache
uses: actions/cache/restore@v3
with:
path: .conan
key: conan-${{ runner.os }}-${{ hashFiles('conandata.yml', 'conanfile.py', 'conan/**/*.py', 'conan/**/*.yml') }}
key: conan-${{ runner.os }}
restore-keys: conan-${{ runner.os }}
- name : Print cache hit/miss
run: |
echo "Cache was hit: ${{ steps.cache.outputs.cache-hit }}"
# If we have a cache miss on 'main', clear the cache.
# A dependency was updated, so we need to drop the old one
# to prevent unbounded cache growth over time.
- name : Clear Conan cache
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.cache.outputs.cache-hit != 'true'
run: |
rm -rf ./.conan
- name: Create Conan default profile
run: |
conan profile new default --detect || true
Expand All @@ -70,6 +55,30 @@ jobs:
run: ./conan_deps.sh
- name: Create build dir
run: mkdir build
# Check if all conan packages are within the cache. If not
# we will need to build packages (and if on main flush the cache)
- name : Check Conan dependencies are cached
id: check_conan_cache
working-directory: build
run: |
export CONAN_LLVM_GIT_CACHE="${{ runner.temp }}/llvm-project"
conan install .. -pr:h default -pr:b default
if [ $? -ne 0 ]
then
cache_hit=false
else
cache_hit=true
fi
echo "cache_hit=$cache_hit" >> $GITHUB_OUTPUT
echo "Cache was hit: $cache_hit"
# If we have a cache miss on 'main', clear the cache.
# A dependency was updated, so we need to drop the old one
# to prevent unbounded cache growth over time.
- name : Clear Conan cache
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.check_conan_cache.outputs.cache_hit != 'true'
run: |
echo "Cache was hit: ${{ steps.check_conan_cache.outputs.cache_hit }}"
rm -rf ./.conan
- name: Conan install
id: conan_install
working-directory: build
Expand All @@ -85,28 +94,11 @@ jobs:
id: test
working-directory: build
run: conan build .. --test

# On 'pull_request' run Clang tidy
- name: Clang tidy
uses: ZedThree/[email protected]
id: clang_tidy
if: github.event_name == 'pull_request'
with:
config_file: '.clang-tidy'
build_dir: build

# On 'pull_request' run Clang format and commit the changes
- name: Clang format
id: clang_format
if: github.event_name == 'pull_request'
working-directory: build
run: ninja check-format

# On 'main' branch, always save the cache if Conan install succeeded.
# Note: we only update the cache from 'main' to avoid "cache thrashing", which would result in the 'main'
# cache getting LRU-evicted for every PR, since a single run uses most of the 10GB repo limit.
- uses: actions/cache/save@v3
if: always() && (github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.conan_install.outcome == 'success' && steps.cache.outputs.cache-hit != 'true')
if: always() && (github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.conan_install.outcome == 'success' && steps.check_conan_cache.outputs.cache_hit != 'true')
with:
path: .conan
key: conan-${{ runner.os }}-${{ hashFiles('conandata.yml', 'conanfile.py', 'conan/**/*.py', 'conan/**/*.yml') }}
key: conan-${{ runner.os }}
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: no-commit-to-branch
stages: [commit]
args: [--branch, main, --pattern, release/.*, --pattern, .*/release/.*]
- id: check-json
stages: [commit]
- id: end-of-file-fixer
stages: [commit]
exclude: '.+(\.s[ql][23])$'
- id: trailing-whitespace
stages: [commit]
args: [--markdown-linebreak-ext=md]
exclude: '.+(\.s[ql][23])$'
- id: check-merge-conflict
stages: [commit]
- id: debug-statements
stages: [commit]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
stages: [commit]
args:
- "-l 100"
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.5
hooks:
- id: clang-format
stages: [commit]
args:
- "--style=file:.clang-format"
- repo: https://github.com/PyCQA/flake8.git
rev: 4.0.1
hooks:
- id: flake8
stages: [commit]
args:
- "--max-line-length=100"
- "--extend-ignore=W503"
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ list(APPEND RUN_CLANG_TIDY_BIN_ARGS
-clang-tidy-binary ${CLANG_TIDY_BIN}
-clang-apply-replacements-binary ${CLANG_AR_BIN}
-style=file
# Limit clang-tidy to project headers
-header-filter="${CMAKE_SOURCE_DIR}/*.h"
-quiet
)

Expand Down
Loading

0 comments on commit cbdbeb0

Please sign in to comment.