Fix for occasional CI/CD failures (k8s-related) #18
Workflow file for this run
This file contains hidden or 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
| name: API PR Validation | |
| on: | |
| pull_request: | |
| branches: ["main"] | |
| paths: | |
| - "api/**" | |
| - ".github/workflows/api-pr-validation.yml" | |
| env: | |
| REGISTRY: cerit.io | |
| IMAGE_NAME: mol-view-stories/mvs-api | |
| jobs: | |
| lint-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| cd api | |
| pip install -r requirements.txt | |
| pip install flake8 black isort pytest | |
| - name: Run linting (flake8) | |
| run: | | |
| cd api | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - name: Run code formatting check (black) | |
| run: | | |
| cd api | |
| python -m black --check --diff . | |
| - name: Run import sorting check (isort) | |
| run: | | |
| cd api | |
| python -m isort --check-only --diff . | |
| - name: Run tests | |
| run: | | |
| cd api | |
| python -m pytest tests/ -v --cov=. --cov-report=xml --cov-report=html | |
| - name: Upload coverage reports | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./api/coverage.xml | |
| flags: api | |
| name: api-coverage | |
| docker-build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image (without pushing) | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./api | |
| push: false | |
| load: true | |
| tags: mol-view-stories-api:pr-test | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Verify Docker image | |
| run: | | |
| docker images mol-view-stories-api:pr-test | |
| docker run --rm mol-view-stories-api:pr-test python --version | |
| docker-push-pr: | |
| needs: lint-and-test | |
| runs-on: ubuntu-latest | |
| # Only run for PRs from this repository (secrets are not available for forks) | |
| if: github.event.pull_request.head.repo.fork == false | |
| outputs: | |
| image_digest: ${{ steps.build_and_push_pr.outputs.digest }} | |
| image_tag: pr-${{ github.event.number }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ secrets.CERIT_REGISTRY_USERNAME }} | |
| password: ${{ secrets.CERIT_REGISTRY_PASSWORD }} | |
| - name: Build and push PR image | |
| id: build_and_push_pr | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./api | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.number }} | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}-${{ github.sha }} | |
| platforms: linux/amd64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |