-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from AMReX-Astro/add_actions
add some github actions
- Loading branch information
Showing
18 changed files
with
408 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Checks: > | ||
-*, | ||
bugprone-*, | ||
-bugprone-easily-swappable-parameters, | ||
clang-analyzer-*, | ||
clang-diagnostic-*, | ||
cppcoreguidelines-*, | ||
-cppcoreguidelines-avoid-c-arrays, | ||
-cppcoreguidelines-avoid-magic-numbers, | ||
-cppcoreguidelines-avoid-non-const-global-variables, | ||
-cppcoreguidelines-init-variables, | ||
-cppcoreguidelines-interfaces-global-init, | ||
-cppcoreguidelines-macro-usage, | ||
-cppcoreguidelines-non-private-member-variables-in-classes, | ||
-cppcoreguidelines-owning-memory, | ||
-cppcoreguidelines-pro-*, | ||
misc-*, | ||
-misc-const-correctness, | ||
-misc-include-cleaner, | ||
-misc-non-private-member-variables-in-classes, | ||
-misc-use-anonymous-namespace, | ||
modernize-*, | ||
-modernize-avoid-c-arrays, | ||
-modernize-use-trailing-return-type, | ||
performance-*, | ||
-performance-avoid-endl, | ||
portability-*, | ||
readability-*, | ||
-readability-avoid-const-params-in-decls, | ||
-readability-braces-around-statements, | ||
-readability-else-after-return, | ||
-readability-function-cognitive-complexity, | ||
-readability-function-size, | ||
-readability-identifier-length, | ||
-readability-implicit-bool-conversion, | ||
-readability-isolate-declaration, | ||
-readability-magic-numbers, | ||
-readability-named-parameter, | ||
-readability-simplify-boolean-expr, | ||
mpi-*, | ||
openmp-* | ||
HeaderFilterRegex: '(/source/*/|^\./|^./tmp_build_dir/microphysics_sources/*/).*\.H$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
blocs | ||
bloc | ||
inout | ||
pres | ||
bion | ||
tye | ||
delt | ||
thi | ||
daa | ||
numer | ||
clen | ||
coul | ||
dum | ||
crate | ||
vie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[codespell] | ||
skip = .git,*.ipynb,*.bib,*.ps,*~ | ||
ignore-words = .codespell-ignore-words | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import subprocess | ||
import sys | ||
import os | ||
import re | ||
|
||
|
||
def pow_to_powi(text): | ||
# Finds all possible std::pow(x, n) or gcem::pow(x, n) | ||
# where n is a potential integer to amrex::Math::powi<n>(x) | ||
|
||
# Check for all positive and negative integer, whole float numbers | ||
# with and without _rt | ||
match_pattern = r"([^,]+),\s*(-?(?:\d+\.0*_rt?|\d))" | ||
|
||
# Match fails when there is a nested pow, so only inner most pow is matched | ||
negate_pattern = r"(?![\s\S]*(?:std|gcem)::pow\((?:[^,]+),\s*(?:-?(?:\d+\.0*_rt?|\d))\))" | ||
|
||
# Final pattern | ||
pattern = rf"(?:std|gcem)::pow\({negate_pattern}{match_pattern}\)" | ||
# pattern = rf"(?:std|gcem)::pow\((?![\s\S]*(?:std|gcem)::pow\((?:[^,]+),\s*(?:-?(?:\d+\.0*_rt?|\d))\))([^,]+),\s*(-?(?:\d+\.0*_rt?|\d))\)" | ||
|
||
def replacement(match): | ||
x = match.group(1) | ||
n = match.group(2) | ||
|
||
# Only extracts out the integer part before decimal point | ||
n = n.split('.')[0] if '.' in n else n | ||
return f"amrex::Math::powi<{n}>({x})" | ||
|
||
text = re.sub(pattern, replacement, text) | ||
return text | ||
|
||
def process_content(dir_path): | ||
# This function processes all text in the given directory | ||
for root, dirs, filenames in os.walk(dir_path): | ||
for filename in filenames: | ||
if filename.endswith(".H") or filename.endswith(".cpp"): | ||
filepath = os.path.join(root, filename) | ||
|
||
with open(filepath, 'r') as file: | ||
old_content = file.read() | ||
|
||
# Iterate over content until content is the same | ||
# This is used to get rid of potential nested pow | ||
new_content = pow_to_powi(old_content) | ||
while new_content != old_content: | ||
old_content = new_content | ||
new_content = pow_to_powi(old_content) | ||
|
||
with open(filepath, 'w') as file: | ||
file.write(new_content) | ||
|
||
def git_diff(): | ||
# Run git diff to see if there are any changes made | ||
|
||
git_diff_output = subprocess.run(['git', 'diff', '--color=always'], | ||
capture_output=True, text=True) | ||
|
||
# Print out suggested change and raise error after detecting modification | ||
if git_diff_output.stdout: | ||
print("Detected potential usage to replace std::pow" + | ||
"with integer powers via amrex::Math::powi\n") | ||
print("Below are the suggested change:\n") | ||
print(git_diff_output.stdout) | ||
|
||
raise RuntimeError("Changes detected after modification") | ||
|
||
if __name__ == '__main__': | ||
|
||
# Get directory paths | ||
directory_paths = sys.argv[1:] | ||
|
||
# Modify the std::pow -> amrex::Math::powi if needed | ||
for dir_path in directory_paths: | ||
process_content(dir_path) | ||
|
||
# Give suggested change if there are any modifications made | ||
git_diff() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: check powi | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
check-ifdefs: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
cache: "pip" | ||
|
||
- name: Run check_powi | ||
run: | | ||
python .github/workflows/check_powi.py . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: "clang-tidy" | ||
|
||
on: [pull_request] | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.head_ref }}-${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
clang_tidy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Get AMReX | ||
run: | | ||
mkdir external | ||
cd external | ||
git clone https://github.com/AMReX-Codes/amrex.git | ||
cd amrex | ||
git checkout development | ||
echo 'AMREX_HOME=$(GITHUB_WORKSPACE)/external/amrex' >> $GITHUB_ENV | ||
echo $AMREX_HOME | ||
if [[ -n "${AMREX_HOME}" ]]; then exit 1; fi | ||
cd ../.. | ||
- name: Get Microphysics | ||
run: | | ||
cd external | ||
git clone https://github.com/AMReX-Astro/Microphysics.git | ||
cd Microphysics | ||
git checkout development | ||
echo 'MICROPHYSICS_HOME=$(GITHUB_WORKSPACE)/external/Microphysics' >> $GITHUB_ENV | ||
echo $MICROPHYSICS_HOME | ||
if [[ -n "${MICROPHYSICS_HOME}" ]]; then exit 1; fi | ||
cd ../.. | ||
- name: Install dependencies | ||
run: | | ||
.github/workflows/dependencies_clang-tidy-apt-llvm.sh 17 | ||
- name: Compile convective_grad | ||
run: | | ||
cd source/convective_grad | ||
make USE_MPI=FALSE USE_CLANG_TIDY=TRUE CLANG_TIDY=clang-tidy-17 CLANG_TIDY_WARN_ERROR=TRUE -j 4 | ||
- name: Compile eos_demo | ||
run: | | ||
cd source/eos_demo | ||
make USE_MPI=FALSE USE_CLANG_TIDY=TRUE CLANG_TIDY=clang-tidy-17 CLANG_TIDY_WARN_ERROR=TRUE -j 4 | ||
- name: Compile fluxes | ||
run: | | ||
cd source/fluxes | ||
make USE_MPI=FALSE USE_CLANG_TIDY=TRUE CLANG_TIDY=clang-tidy-17 CLANG_TIDY_WARN_ERROR=TRUE -j 4 | ||
- name: Compile max_enuc | ||
run: | | ||
cd source/max_enuc | ||
make USE_MPI=FALSE USE_CLANG_TIDY=TRUE CLANG_TIDY=clang-tidy-17 CLANG_TIDY_WARN_ERROR=TRUE -j 4 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: codespell | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
codespell: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
cache: "pip" | ||
|
||
- name: Install dependencies | ||
run: pip install codespell | ||
|
||
- name: Run codespell | ||
run: | | ||
codespell | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
# `man apt.conf`: | ||
# Number of retries to perform. If this is non-zero APT will retry | ||
# failed files the given number of times. | ||
echo 'Acquire::Retries "3";' | sudo tee /etc/apt/apt.conf.d/80-retries | ||
|
||
if [[ ! -f /etc/apt/trusted.gpg.d/apt.llvm.org.asc ]]; then | ||
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc | ||
fi | ||
|
||
source /etc/os-release # set UBUNTU_CODENAME | ||
|
||
sudo add-apt-repository "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME} main" | ||
sudo add-apt-repository "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-$1 main" | ||
|
||
sudo apt-get update | ||
|
||
sudo apt-get install -y --no-install-recommends \ | ||
clang-tidy-$1 libomp-$1-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Style | ||
|
||
on: [push, pull_request] | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.head_ref }}-style | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
tabs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Tabs | ||
run: .github/workflows/style/check_tabs.sh | ||
|
||
trailing_whitespaces: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Trailing Whitespaces | ||
run: .github/workflows/style/check_trailing_whitespaces.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
find . -type d \( -name .git \ | ||
-o -path ./paper \ | ||
-o -name build -o -name install \ | ||
-o -name tmp_build_dir -o -name tmp_install_dir \ | ||
\) -prune -o \ | ||
-type f \( \( -name "*.H" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" \ | ||
-o -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.cxx" \ | ||
-o -name "*.f" -o -name "*.F" -o -name "*.f90" -o -name "*.F90" \ | ||
-o -name "*.py" \ | ||
-o -name "*.md" -o -name "*.rst" \ | ||
-o -name "*.sh" \ | ||
-o -name "*.tex" \ | ||
-o -name "*.txt" \ | ||
-o -name "*.yml" \) \ | ||
-a \( ! -name "*.tab.h" -a ! -name "*.tab.nolint.H" \ | ||
-a ! -name "*.lex.h" -a ! -name "*.lex.nolint.H" \) \ | ||
\) \ | ||
-exec grep -Iq . {} \; \ | ||
-exec sed -i 's/\t/\ \ \ \ /g' {} + | ||
|
||
gitdiff=`git diff` | ||
|
||
if [ -z "$gitdiff" ] | ||
then | ||
exit 0 | ||
else | ||
echo -e "\nTabs are not allowed. Changes suggested by" | ||
echo -e " ${0}\n" | ||
git --no-pager diff | ||
echo "" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
find . -type d \( -name .git \ | ||
-o -path ./paper \ | ||
-o -name build -o -name install \ | ||
-o -name tmp_build_dir -o -name tmp_install_dir \ | ||
-o -path ./util/gcem \ | ||
\) -prune -o \ | ||
-type f \( \( -name "*.H" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" \ | ||
-o -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.cxx" \ | ||
-o -name "*.f" -o -name "*.F" -o -name "*.f90" -o -name "*.F90" \ | ||
-o -name "*.py" \ | ||
-o -name "*.rst" \ | ||
-o -name "*.sh" \ | ||
-o -name "*.tex" \ | ||
-o -name "*.txt" \ | ||
-o -name "*.yml" \) \ | ||
-a \( ! -name "*.tab.h" -a ! -name "*.tab.nolint.H" \ | ||
-a ! -name "*.lex.h" -a ! -name "*.lex.nolint.H" \ | ||
-a ! -path "./networks/*/reaclib_rates.H" \) \ | ||
\) \ | ||
-exec grep -Iq . {} \; \ | ||
-exec sed -i 's/[[:blank:]]\+$//g' {} + | ||
|
||
gitdiff=`git diff` | ||
|
||
if [ -z "$gitdiff" ] | ||
then | ||
exit 0 | ||
else | ||
echo -e "\nTrailing whitespaces at the end of a line are not allowed. Changes suggested by" | ||
echo -e " ${0}\n" | ||
git --no-pager diff | ||
echo "" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.