Skip to content

Add missing optimizations for translation to openqasm2 #9719

Add missing optimizations for translation to openqasm2

Add missing optimizations for translation to openqasm2 #9719

Workflow file for this run

on:
workflow_dispatch:
pull_request:
name: "Basic content checks"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
links:
runs-on: ubuntu-latest
name: "Check links"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Convert reStructuredText files to Markdown
run: |
pip install "rst-to-myst[sphinx]==0.4.0"
find docs/sphinx/ -type f -name "*.rst" -print0 | xargs -0 rst2myst convert --raise-on-warning
- name: Check links in Markdown files
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-verbose-mode: "yes"
config-file: ".github/workflows/config/md_link_check_config.json"
license_headers:
name: Check license headers
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: apache/skywalking-eyes/[email protected]
with:
config: .licenserc.yaml
token: '' # with the appropriate permission license eye can add comments on the PR
filters:
name: Filter files to check
runs-on: ubuntu-latest
outputs:
json: ${{ steps.files.outputs.json }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: ${{ (github.event_name == 'pull_request' && '0') || '1' }}
- id: files
run: |
if ${{ github.event_name == 'pull_request' }}; then
diff_base=${{ github.event.pull_request.base.sha }}
git rev-list HEAD..$diff_base # fails the step if something went wrong
list_files="git diff --diff-filter=d --name-only $diff_base --"
echo "## Changed Files" >> $GITHUB_STEP_SUMMARY
echo "The following files contain changes:" >> $GITHUB_STEP_SUMMARY
for file in `$list_files`; do
echo "$file" >> $GITHUB_STEP_SUMMARY
done
else
list_files="git ls-files"
fi
json="{\"files\":{}, \"patterns\":{}}"
function create_output {
json=`echo $json | jq ".patterns |= . + {"$1":[]}"`
for pattern in $2; do
pattern=\'$pattern\'
json=`echo $json | jq ".patterns.$1 |= . + [\"$pattern\"]"`
done
json=`echo $json | jq ".files |= . + {"$1":[]}"`
for file in `echo $2 | xargs $list_files`; do
file=\'$file\'
json=`echo $json | jq ".files.$1 |= . + [\"$file\"]"`
done
}
create_output cxx '*.cpp *.h *.hpp :!:test :!:targettests :!:tpls :!:**/nlopt-src/*'
create_output cxx_headers '*.h *.hpp :!:test :!:targettests :!:tpls :!:**/nlopt-src/*'
create_output cxx_examples 'docs/sphinx/examples/**/*.cpp'
create_output python '*.py :!:python/tests :!:test :!:targettests :!:tpls :!:docs/sphinx/conf.py'
create_output markdown '*.md :!:tpls'
create_output rst '*.rst :!:tpls'
echo "json=$(echo $json)" >> $GITHUB_OUTPUT
formatting:
name: Check code formatting
runs-on: ubuntu-latest
needs: filters
steps:
- uses: actions/checkout@v4
- name: C++
run: |
echo "## C++ Formatting" >> $GITHUB_STEP_SUMMARY
files=(${{ join(fromJSON(needs.filters.outputs.json).files.cxx, ' ') }})
if [ "${#files[@]}" -gt "0" ]; then
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main"
sudo apt-get update && sudo apt-get install -y --no-install-recommends clang-format-16
echo ${files[@]} | xargs clang-format-16 -i
echo ${{ join(fromJSON(needs.filters.outputs.json).patterns.cxx, ' ') }} \
| xargs git diff --diff-filter=d -- > /tmp/clang-format.patch
else
echo "No files to check." >> $GITHUB_STEP_SUMMARY
exit 0
fi
if [ -s /tmp/clang-format.patch ]; then
echo "The following formatting changes need to be applied:" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat /tmp/clang-format.patch >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "Totally checked ${#files[@]} files. All files are formatted as expected." >> $GITHUB_STEP_SUMMARY
fi
- name: Python
run: |
echo "## Python Formatting" >> $GITHUB_STEP_SUMMARY
files=(${{ join(fromJSON(needs.filters.outputs.json).files.python, ' ') }})
if [ "${#files[@]}" -gt "0" ]; then
pip install yapf
echo ${files[@]} | xargs yapf --style google --recursive -i
echo ${{ join(fromJSON(needs.filters.outputs.json).patterns.python, ' ') }} \
| xargs git diff --diff-filter=d -- > /tmp/yapf.patch
else
echo "No files to check." >> $GITHUB_STEP_SUMMARY
exit 0
fi
if [ -s /tmp/yapf.patch ]; then
echo "The following formatting changes need to be applied:" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat /tmp/yapf.patch >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "Totally checked ${#files[@]} files. All files are formatted as expected." >> $GITHUB_STEP_SUMMARY
fi
- name: Markdown
uses: nosborn/[email protected]
with:
files: .
config_file: '.github/workflows/config/md_lint_config.yml'
spelling:
name: Check spelling
runs-on: ubuntu-latest
needs: filters
steps:
- uses: actions/checkout@v4
- name: Check spelling allowlist
run: |
for file in `ls .github/workflows/config/spelling_allowlist*.txt`; do
sorted_allowlist=`cat $file | sort`
if [ "$sorted_allowlist" != "$(cat $file)" ]; then
echo "Expecting spelling allowlist in $file to be sorted."
exit 1
fi
done
- name: "Markdown files"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: markdown_spellcheck.txt
task_name: markdown
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.markdown, ' ') || '*.nonexistent' }}
- name: "reStructuredText files"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: rst_spellcheck.txt
task_name: rst
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.rst, ' ') || '*.nonexistent' }}
- name: "C++ files (headers)"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: cxx_headers_spellcheck.txt
task_name: cxx_headers
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.cxx_headers, ' ') || '*.nonexistent' }}
- name: "C++ files (examples)"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: cxx_examples_spellcheck.txt
task_name: cxx_examples
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.cxx_examples, ' ') || '*.nonexistent' }}
- name: "Python files"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: python_spellcheck.txt
task_name: python
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.python, ' ') || '*.nonexistent' }}
- name: Create summary
run: |
function create_summary {
status=`cat $2_spellcheck.txt | grep "Spelling check" | cut -d ' ' -f 3 | tr -d '!'`
if [ "$status" == "passed" ]; then echo 0; else echo 1; fi
echo "## $1 Check" >> $GITHUB_STEP_SUMMARY
echo "Spell check ${status}." >> $GITHUB_STEP_SUMMARY
echo "Output for $1 files:" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat $2_spellcheck.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
}
md_status=`create_summary Markdown markdown`
rst_status=`create_summary reStructuredText rst`
cxx_h_status=`create_summary "C++ Headers" cxx_headers`
cxx_ex_status=`create_summary "C++ Examples" cxx_examples`
py_status=`create_summary Python python`
if [ ! "$md_status" -eq 0 ]; then exit 1; fi
if [ ! "$rst_status" -eq 0 ]; then exit 2; fi
if [ ! "$cxx_h_status" -eq 0 ]; then exit 3; fi
if [ ! "$cxx_ex_status" -eq 0 ]; then exit 4; fi
if [ ! "$py_status" -eq 0 ]; then exit 5; fi