diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b402624 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,13 @@ +name: Full CI +on: [push] + +jobs: + formatter: + uses: ./.github/workflows/formatter.yml + + pytest: + uses: ./.github/workflows/ophyd_tests.yml + + device-config-test: + uses: ./.github/workflows/device_config_test.yml + diff --git a/.github/workflows/device_config_test.yml b/.github/workflows/device_config_test.yml new file mode 100644 index 0000000..5338a51 --- /dev/null +++ b/.github/workflows/device_config_test.yml @@ -0,0 +1,31 @@ +name: Run Pytest with Coverage +on: [workflow_call] + +jobs: + + + device-config-test: + runs-on: ubuntu-latest + + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + pip install -e .[dev] + + - name: Device Config Tests + run: | + ophyd_test --config ./ophyd_devices/configs/ --output ./config_tests + + # - name: Upload Device Config Test Results + # uses: actions/upload-artifact@v3 + # with: + # name: device-config-test-results + # path: ./config_tests \ No newline at end of file diff --git a/.github/workflows/formatter.yml b/.github/workflows/formatter.yml new file mode 100644 index 0000000..78bd793 --- /dev/null +++ b/.github/workflows/formatter.yml @@ -0,0 +1,62 @@ +name: Formatter and Pylint jobs +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [workflow_call] +jobs: + + Formatter: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Run black and isort + run: | + pip install black isort + pip install -e .[dev] + black --check --diff --color . + isort --check --diff ./ + Pylint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint pylint-exit anybadge + + - name: Run Pylint + run: | + mkdir -p ./pylint + set +e + pylint ./${{ github.event.repository.name }} --output-format=text > ./pylint/pylint.log + pylint-exit $? + set -e + + - name: Extract Pylint Score + id: score + run: | + SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./pylint/pylint.log) + echo "score=$SCORE" >> $GITHUB_OUTPUT + + - name: Create Badge + run: | + anybadge --label=Pylint --file=./pylint/pylint.svg --value="${{ steps.score.outputs.score }}" 2=red 4=orange 8=yellow 10=green + + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: pylint-artifacts + path: | + # ./pylint/pylint.log # not sure why this isn't working + ./pylint/pylint.svg diff --git a/.github/workflows/ophyd_tests.yml b/.github/workflows/ophyd_tests.yml new file mode 100644 index 0000000..bdf1991 --- /dev/null +++ b/.github/workflows/ophyd_tests.yml @@ -0,0 +1,47 @@ +name: Run Pytest with Coverage +on: [workflow_call] + +jobs: + pytest: + runs-on: ubuntu-latest + + env: + CHILD_PIPELINE_BRANCH: main # Set the branch you want for ophyd_devices + BEC_CORE_BRANCH: main # Set the branch you want for bec + PROJECT_PATH: ${{ github.repository }} + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Clone and install dependencies + run: | + if [[ "$PROJECT_PATH" != "bec/ophyd_devices" ]]; then + echo -e "\033[35;1m Using branch $CHILD_PIPELINE_BRANCH of Ophyd Devices \033[0;m" + test -d ophyd_devices || git clone --branch "$CHILD_PIPELINE_BRANCH" https://gitlab.psi.ch/bec/ophyd_devices.git + cd ophyd_devices + fi + + pip install -e .[dev] + git clone --branch "$BEC_CORE_BRANCH" https://gitlab.psi.ch/bec/bec.git + pip install -e ./bec/bec_lib[dev] + pip install -e ./bec/bec_server[dev] + + - name: Run Pytest with Coverage + run: | + pip install coverage pytest pytest-random-order + coverage run --source=./ophyd_devices --omit=*/ophyd_devices/tests/* -m pytest -v --junitxml=report.xml --random-order --full-trace ./tests + coverage report + coverage xml + + # - name: Upload Coverage Report and Test Results + # uses: actions/upload-artifact@v3 + # with: + # name: test-artifacts + # path: | + # report.xml + # coverage.xml