Simplify cyberstorm community APIs implementation #3293
Workflow file for this run
This file contains 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: Build & Test | |
on: [push, pull_request] | |
jobs: | |
pre-commit: | |
name: Run pre-commit | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: false | |
- name: Setup Python 3.8 | |
id: setup-python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: "3.8" | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: "14" | |
- name: Get node version | |
id: node-version | |
run: echo "::set-output name=node-version::$(node --version)" | |
- uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-in-project: true | |
- name: Cache poetry venv | |
id: cache-poetry | |
uses: actions/cache@v2 | |
with: | |
path: django/.venv | |
key: "poetry-${{ runner.os }}-\ | |
${{ steps.setup-python.outputs.python-version }}-\ | |
${{ hashFiles('django/poetry.lock') }}" | |
restore-keys: | | |
poetry-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}- | |
- name: Install poetry dependencies | |
run: | | |
cd django/ | |
poetry install | |
- name: Cache pre-commit cache | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pre-commit | |
key: "pre-commit-${{ runner.os }}-\ | |
${{ steps.setup-python.outputs.python-version }}-\ | |
${{ steps.node-version.outputs.node-version }}-\ | |
${{ hashFiles('.pre-commit-config.yaml') }}" | |
- name: Run pre-commit | |
run: | | |
cd django/ | |
poetry run pre-commit run --show-diff-on-failure --color=always --all-files | |
build: | |
name: Build docker image | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: false | |
- name: Build Docker image | |
run: docker build --pull -t thunderstore:${GITHUB_SHA} . | |
- name: Export Docker image | |
run: docker save --output /tmp/thunderstore.tar thunderstore:${GITHUB_SHA} | |
- name: Upload Docker image | |
uses: actions/upload-artifact@v3 | |
with: | |
name: docker-image | |
path: /tmp/thunderstore.tar | |
test-pytest: | |
name: Test pytest | |
runs-on: ubuntu-latest | |
needs: build | |
strategy: | |
matrix: | |
group: [1, 2, 3] | |
env: | |
PYTEST_SPLITS: 3 | |
PYTEST_GROUP: ${{ matrix.group }} | |
PYTEST_NUM_WORKERS: auto | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: false | |
- name: Download Docker image | |
uses: actions/download-artifact@v3 | |
with: | |
name: docker-image | |
path: /tmp | |
- name: Load Docker image | |
run: docker load --input /tmp/thunderstore.tar | |
- name: Run pytest | |
run: | | |
DJANGO_IMAGE="thunderstore:${GITHUB_SHA}" docker-compose -f docker/docker-compose.pytest.yml up --exit-code-from django | |
docker-compose -f docker/docker-compose.pytest.yml down -f | |
- name: Upload coverage to Codecov | |
if: always() | |
uses: codecov/codecov-action@v1 | |
with: | |
file: ./coverage_results/coverage.xml | |
test-mypy: | |
name: Test mypy | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: false | |
- name: Download Docker image | |
uses: actions/download-artifact@v3 | |
with: | |
name: docker-image | |
path: /tmp | |
- name: Load Docker image | |
run: docker load --input /tmp/thunderstore.tar | |
- name: Run mypy | |
run: > | |
docker run --rm | |
--entrypoint mypy | |
-e SECRET_KEY=hunter2 | |
--no-healthcheck | |
thunderstore:${GITHUB_SHA} | |
/app/ | |
|| : | |
test-missing-migrations: | |
name: Test missing migrations | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: false | |
- name: Download Docker image | |
uses: actions/download-artifact@v3 | |
with: | |
name: docker-image | |
path: /tmp | |
- name: Load Docker image | |
run: docker load --input /tmp/thunderstore.tar | |
- name: Check for missing migrations | |
run: > | |
docker run --rm | |
--entrypoint python | |
-e SECRET_KEY=hunter2 | |
-e DATABASE_URL=sqlite://django.db | |
--no-healthcheck | |
thunderstore:${GITHUB_SHA} | |
manage.py makemigrations --check | |
publish-dockerhub: | |
name: Publish to Docker Hub | |
runs-on: ubuntu-latest | |
needs: [test-pytest, test-mypy, test-missing-migrations, pre-commit] | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: false | |
- name: Download Docker image | |
uses: actions/download-artifact@v3 | |
with: | |
name: docker-image | |
path: /tmp | |
- name: Load Docker image | |
run: docker load --input /tmp/thunderstore.tar | |
- name: Tag image | |
run: | | |
docker tag thunderstore:${GITHUB_SHA} thunderstore/thunderstore:${GITHUB_SHA} | |
- name: Login to Docker Hub | |
if: github.event_name != 'pull_request' | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | |
- name: Push image to Docker Hub | |
if: github.event_name != 'pull_request' | |
run: | | |
echo "Pushing thunderstore/thunderstore:${GITHUB_SHA}" | |
docker push thunderstore/thunderstore:${GITHUB_SHA} | |
publish-github: | |
name: Publish to GitHub | |
runs-on: ubuntu-latest | |
needs: [test-pytest, test-mypy, test-missing-migrations, pre-commit] | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: false | |
- name: Download Docker image | |
uses: actions/download-artifact@v3 | |
with: | |
name: docker-image | |
path: /tmp | |
- name: Load Docker image | |
run: docker load --input /tmp/thunderstore.tar | |
- name: Tag image | |
run: | | |
docker tag thunderstore:${GITHUB_SHA} ghcr.io/thunderstore-io/thunderstore:${GITHUB_SHA} | |
- name: Login to GitHub Container Registry | |
if: github.event_name != 'pull_request' | |
env: | |
DOCKER_USERNAME: ${{ secrets.GHCR_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.GHCR_PAT }} | |
run: docker login ghcr.io -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | |
- name: Push image to GitHub Container Registry | |
if: github.event_name != 'pull_request' | |
run: | | |
echo "Pushing ghcr.io/thunderstore-io/thunderstore:${GITHUB_SHA}" | |
docker push ghcr.io/thunderstore-io/thunderstore:${GITHUB_SHA} |