Merge pull request #52 from broadinstitute/deps/frontend-audit #113
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 CI/CD | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| # "**", not "*": a single star stops at a slash, so grouped branch names | |
| # (dependabot/..., deps/..., fix/...) matched nothing and ran no CI. | |
| # The deploy job below is gated on refs/heads/main, so widening this | |
| # adds runs, never deploys. | |
| - "**" | |
| paths: | |
| - 'job_server/**' | |
| - 'requirements.txt' | |
| # Tests gate the API, so changes to them must trigger CI too. | |
| - 'tests/**' | |
| # run.sh.tmpl is served live by the API per request, so deploying it | |
| # means redeploying the API. Trigger on static changes too. | |
| - 'static/**' | |
| # Trigger on changes to this workflow too, so CI/deploy fixes land | |
| # without needing an unrelated job_server/ change. (Re-running an old | |
| # run only re-runs its pinned commit, which won't have the fix.) | |
| - '.github/workflows/api-ci.yml' | |
| jobs: | |
| test: | |
| name: Run tests | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.head_ref || github.ref }} | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| - name: Start MySQL | |
| run: | | |
| sh docker_db/docker_db.sh start 3308 | |
| - name: Test with pytest with coverage | |
| env: | |
| # CI runs MySQL on :3308 (see "Start MySQL") with a dedicated test DB | |
| # created by local-mysql-init.sql. Point the suite there explicitly; | |
| # otherwise conftest falls back to :3305 (the local-dev port) and the | |
| # connection is refused. | |
| TEST_DIG_JOB_SERVER_DB: mysql+pymysql://job_server:job_server@localhost:3308/job_server_test | |
| run: | | |
| pytest --cov=. --cov-report=json | |
| - name: Stop MySQL | |
| run: | | |
| sh docker_db/docker_db.sh stop | |
| - name: Update README with coverage badge | |
| run: python .github/scripts/update_coverage_badge.py | |
| - name: Commit and push if changed | |
| run: | | |
| git config --global user.email "action@github.com" | |
| git config --global user.name "GitHub Action" | |
| git diff | |
| if git diff --exit-code --quiet; then | |
| echo "No changes in coverage" | |
| else | |
| git add README.md | |
| git commit -m "Update coverage badge" | |
| git push | |
| fi | |
| deploy: | |
| needs: [ test ] | |
| if: github.ref == 'refs/heads/main' | |
| name: Deploy API | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: ./.github/actions/deploy | |
| with: | |
| python-version: '3.12' | |
| deploy-environment: 'dev' | |
| host: ${{ secrets.DEPLOY_HOST }} | |
| private-key: ${{ secrets.SSH_PRIVATE_KEY }} |