Skip to content

add Paper_v2.0/paper_formating.py #2799

add Paper_v2.0/paper_formating.py

add Paper_v2.0/paper_formating.py #2799

Workflow file for this run

name: Build and Check
on:
push:
branches:
- main
pull_request:
env:
CONDA_ENV_NAME: clmm
jobs:
check-formatting:
name: Code formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
environment-file: environment.yml
- uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/pkgs
key: ${{ runner.os }}-conda-${{ env.CONDA_ENV_NAME }}
- name: Analysing the code formatting with black
shell: bash -l {0}
run: |
black --check --diff clmm
- name: Analysing the code import order with isort
shell: bash -l {0}
run: |
isort --check --diff clmm
- name: Analysing the code with pylint
shell: bash -l {0}
run: |
pylint clmm
doc-valid:
name: Documentation Validation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
environment-file: environment.yml
- uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/pkgs
key: ${{ runner.os }}-conda-${{ env.CONDA_ENV_NAME }}
- name: Install the package
shell: bash -l {0}
run: |
pip install . -vv --no-deps --no-build-isolation
- name: Run the docs
shell: bash -l {0}
run: |
make -C docs/ html
build-gcc-ubuntu:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
environment-file: environment.yml
- uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/pkgs
key: ${{ runner.os }}-conda-${{ env.CONDA_ENV_NAME }}
- name: Install the package
shell: bash -l {0}
run: |
pip install . -vv --no-deps --no-build-isolation
- name: Run the unit tests
shell: bash -l {0}
run: |
pytest tests/ --ignore=cluster_toolkit/tests --cov=clmm/
env:
DISPLAY: test
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash -l {0}
run: |
pip install coveralls
coveralls --service=github
check-code-version:
name: Code version number
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
# Get current version
- name: Check out the code
uses: actions/checkout@v4
- name: Get version from current branch
id: current_version
run: |
CURRENT_VERSION="$(grep -oP '__version__ = "\K[^"]+' clmm/__init__.py)"
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
# Get main version
- name: Checkout the main branch to get its version
uses: actions/checkout@v4
with:
ref: main
- name: Get version from main branch
id: main_version
run: |
if [[ "$(git show origin/main:clmm/__init__.py)" == *"__version__"* ]]; then
MAIN_VERSION="$(grep -oP '__version__ = "\K[^"]+' clmm/__init__.py)"
else
echo "No version found at main, assuming version 0.0.0"
MAIN_VERSION="0.0.0"
fi
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
# Get PR title to be updated with version
- name: Get PR title and clean version number from it
env:
TITLE: ${{ github.event.pull_request.title }}
run: |
NEW_TITLE="${TITLE% [version:*}"
echo "New title: $NEW_TITLE"
echo "NEW_TITLE=$NEW_TITLE" >> $GITHUB_ENV
- name: Get PR number
id: pr_number
run: |
# Fetch the pull request number from the GitHub context
PR_NUMBER=$(echo $GITHUB_REF | sed 's/refs\/pull\/\([0-9]*\)\/merge/\1/')
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
# Compare
- name: Check version change
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$CURRENT_VERSION" == "$MAIN_VERSION" ]; then
echo "Version at clmm/__init__.py has not been updated!"
# Use the GitHub API to update the PR title
echo "Removing version from PR title: $NEW_TITLE"
curl -s -X PATCH \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"title\":\"$NEW_TITLE\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" > /dev/null
exit 1
fi
echo "[ok] Version has changed!"
- name: Check version update
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$(printf "%s\n%s" "$CURRENT_VERSION" "$MAIN_VERSION" | sort -V | tail -n 1)" != "$CURRENT_VERSION" ]; then
echo "Current version ($CURRENT_VERSION) < Main version ($MAIN_VERSION)"
# Use the GitHub API to update the PR title
echo "Removing version from PR title: $NEW_TITLE"
curl -s -X PATCH \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"title\":\"$NEW_TITLE\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" > /dev/null
exit 1
fi
echo "[ok] Version increased changed!"
# Add version number to PR title
- name: Make new title for PR
run: |
NEW_TITLE="${NEW_TITLE} [version:$CURRENT_VERSION]"
echo "New title: $NEW_TITLE"
echo "NEW_TITLE=$NEW_TITLE" >> $GITHUB_ENV
- name: Update PR title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Use the GitHub API to update the PR title
echo "Updating PR #$PR_NUMBER with new title: $NEW_TITLE"
curl -s -X PATCH \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"title\":\"$NEW_TITLE\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" > /dev/null