diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml new file mode 100644 index 000000000..f65e1dd35 --- /dev/null +++ b/.github/actions/lint/action.yml @@ -0,0 +1,34 @@ +name: lint + +runs: + using: composite + steps: + - name: Install poetry + shell: bash + run: pipx install poetry + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + cache: 'poetry' + + - name: Install dependencies + shell: bash + run: poetry install --no-root --only=lint + + - name: Lint with black + shell: bash + run: poetry run black --check . + + - name: Lint with isort + shell: bash + run: poetry run isort --check . + + - name: Lint with ruff + shell: bash + run: poetry run ruff check . + + - name: Lint with flake8 + shell: bash + run: poetry run flake8 . --count --show-source --statistics \ No newline at end of file diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml new file mode 100644 index 000000000..a86712c22 --- /dev/null +++ b/.github/actions/test/action.yml @@ -0,0 +1,71 @@ +name: test +inputs: + python-version: + description: python version to use + required: true +runs: + using: composite + steps: + - name: Install poetry + shell: bash + run: pipx install poetry + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + cache: 'poetry' + + - name: Install package + shell: bash + run: poetry install -E all --only main,test + + - name: Check migrations are up to date + shell: bash + run: poetry run /usr/bin/env aap-eda-manage makemigrations --dry-run --check + + - name: Run default tests + shell: bash + run: | + poetry run python -m pytest -vv \ + --cov=./ \ + --cov-report=xml \ + --junit-xml=eda-server-default.xml + echo "GIT_SHA=$(git rev-parse "$GITHUB_SHA")" >> "$GITHUB_ENV" + + - name: Run multithreaded tests + shell: bash + run: | + poetry run python -m pytest -vv \ + --cov=./ \ + --cov-append \ + --junit-xml=eda-server-multithreaded.xml \ + -m "multithreaded" + + - name: Merge test results + shell: bash + run: | + pip install junitparser + junitparser merge eda-server-default.xml eda-server-multithreaded.xml eda-server-test-results.xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + env_vars: OS,PYTHON + fail_ci_if_error: false + files: ./coverage.xml + flags: "unit-int-tests-${{ inputs.python-version }}" + name: codecov-umbrella + verbose: true + + - name: Upload jUnit test results (APDE CI) + if: github.repository == 'ansible/eda-server' && github.ref == 'refs/heads/main' + shell: bash + run: >- + poetry run http --check-status --ignore-stdin + --auth "${{ env.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ env.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}" + -f POST "${{ env.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}/api/results/upload/" + xunit_xml@eda-server-test-results.xml + component_name=eda + git_commit_sha=${{ env.GIT_SHA }} + git_repository_url="https://github.com/${{ github.repository }}" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 05269ed74..ea1f0cd4b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,30 +21,8 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Install poetry - run: pipx install poetry - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.11' - cache: 'poetry' - - - name: Install dependencies - run: poetry install --no-root --only=lint - - - name: Lint with black - run: poetry run black --check . - - - name: Lint with isort - run: poetry run isort --check . - - - name: Lint with ruff - run: poetry run ruff check . - - - name: Lint with flake8 - run: poetry run flake8 . --count --show-source --statistics - + - name: lint + uses: ./.github/actions/lint test: runs-on: ubuntu-latest @@ -56,13 +34,16 @@ jobs: env: EDA_SECRET_KEY: 'test' EDA_DB_PASSWORD: 'secret' + PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER: ${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }} + PDE_ORG_RESULTS_UPLOAD_PASSWORD: ${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }} + PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL: ${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }} services: postgres: image: 'quay.io/sclorg/postgresql-15-c9s:latest' env: POSTGRESQL_USER: eda - POSTGRESQL_PASSWORD: secret - POSTGRESQL_ADMIN_PASSWORD: secret + POSTGRESQL_PASSWORD: ${{ env.EDA_DB_PASSWORD }} + POSTGRESQL_ADMIN_PASSWORD: ${{ env.EDA_DB_PASSWORD }} POSTGRESQL_DATABASE: eda options: >- --health-cmd pg_isready @@ -84,59 +65,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Install poetry - run: pipx install poetry - - - name: Set up Python - uses: actions/setup-python@v5 + - name: test + uses: ./.github/actions/test with: - python-version: ${{ matrix.python-version }} - cache: 'poetry' - - - name: Install package - run: poetry install -E all --only main,test - - - name: Check migrations are up to date - run: poetry run /usr/bin/env aap-eda-manage makemigrations --dry-run --check - - - name: Run default tests - run: | - poetry run python -m pytest -vv \ - --cov=./ \ - --cov-report=xml \ - --junit-xml=eda-server-default.xml - echo "GIT_SHA=$(git rev-parse "$GITHUB_SHA")" >> "$GITHUB_ENV" - - - name: Run multithreaded tests - run: | - poetry run python -m pytest -vv \ - --cov=./ \ - --cov-append \ - --junit-xml=eda-server-multithreaded.xml \ - -m "multithreaded" - - - name: Merge test results - run: | - pip install junitparser - junitparser merge eda-server-default.xml eda-server-multithreaded.xml eda-server-test-results.xml - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v5 - with: - env_vars: OS,PYTHON - fail_ci_if_error: false - files: ./coverage.xml - flags: "unit-int-tests-${{ matrix.python-version }}" - name: codecov-umbrella - verbose: true - - - name: Upload jUnit test results (APDE CI) - if: github.repository == 'ansible/eda-server' && github.ref == 'refs/heads/main' - run: >- - poetry run http --check-status --ignore-stdin - --auth "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}" - -f POST "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}/api/results/upload/" - xunit_xml@eda-server-test-results.xml - component_name=eda - git_commit_sha=${{ env.GIT_SHA }} - git_repository_url="https://github.com/${{ github.repository }}" + python-version: ${{ matrix.python-version }} \ No newline at end of file