From a0efcdc9ee1431e2671841b97c837bab76cb5fa3 Mon Sep 17 00:00:00 2001 From: Denys Chura Date: Mon, 7 Oct 2024 16:11:13 +0300 Subject: [PATCH 1/3] Improve Github workflow - Update `pull_request` triggers types to only ones which correspond to code changes; - Extract jobs from `default.yml` workflow to re-usable `test.yml` to be able to split default workflow to two workflow with different set of triggers - "schedule" and "pull_request/push" --- .github/workflows/default.yml | 36 +++++++--------------------------- .github/workflows/schedule.yml | 8 ++++++++ .github/workflows/test.yml | 32 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/schedule.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 2b55d0f..ed11ed0 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -3,34 +3,12 @@ on: push: branches: - main - pull_request: {} - schedule: - - cron: '0 14 * * MON' + pull_request: + types: + - opened + - synchronize + - reopened jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Python 3.12.5 - uses: actions/setup-python@v5 - with: - python-version: 3.12.5 - - name: Install Python dependencies - run: | - python3 -m venv venv - source ./venv/bin/activate - pip install -U pip - pip install -r ./requirements.txt - - name: Run tests on hooks - run: | - source ./venv/bin/activate - inv test.hooks - - name: Run tests on building project - run: | - source ./venv/bin/activate - cookiecutter --no-input --overwrite-if-exists --output-dir build . - cd build/awesome - cp ./api/.env.example ./api/.env - make api-test + run-checks: + uses: django-stars/backend-skeleton/.github/workflows/test.yml@improve-github-workflow diff --git a/.github/workflows/schedule.yml b/.github/workflows/schedule.yml new file mode 100644 index 0000000..29fed33 --- /dev/null +++ b/.github/workflows/schedule.yml @@ -0,0 +1,8 @@ +name: Backend Skeleton Scheduled Check +on: + schedule: + - cron: '0 14 * * MON' + +jobs: + run-checks: + uses: django-stars/backend-skeleton/.github/workflows/test.yml@improve-github-workflow diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..54586c6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: Test + +on: + workflow_call: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python 3.12.5 + uses: actions/setup-python@v5 + with: + python-version: 3.12.5 + - name: Install Python dependencies + run: | + python3 -m venv venv + source ./venv/bin/activate + pip install -U pip + pip install -r ./requirements.txt + - name: Run tests on hooks + run: | + source ./venv/bin/activate + inv test.hooks + - name: Run tests on building project + run: | + source ./venv/bin/activate + cookiecutter --no-input --overwrite-if-exists --output-dir build . + cd build/awesome + cp ./api/.env.example ./api/.env + make api-test From 4003412ae150fce1fe248026ba14a0b8026789ff Mon Sep 17 00:00:00 2001 From: Denys Chura Date: Thu, 10 Oct 2024 18:02:58 +0300 Subject: [PATCH 2/3] Fix merge conflict --- .github/workflows/test.yml | 39 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54586c6..680050b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,24 +9,33 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up Python 3.12.5 + - name: Set up Python + id: setup-python uses: actions/setup-python@v5 with: - python-version: 3.12.5 - - name: Install Python dependencies - run: | - python3 -m venv venv - source ./venv/bin/activate - pip install -U pip - pip install -r ./requirements.txt - - name: Run tests on hooks - run: | - source ./venv/bin/activate - inv test.hooks - - name: Run tests on building project + python-version: 3.13 + - name: Install & configure poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + virtualenvs-path: .venv + installer-parallel: true + - name: Load cached venv if exists + id: cached-poetry-dependencies + uses: actions/cache@v4 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + - name: Install dependencies if cache doesn't exist + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction + # NOTE: there are nothing to test yet, unless we add some hooks, just check that it runs + - name: Run tests on skeleton code + run: poetry run inv test.hooks + - name: Build default project from skeleton and run tests run: | - source ./venv/bin/activate - cookiecutter --no-input --overwrite-if-exists --output-dir build . + poetry run cookiecutter --no-input --overwrite-if-exists --output-dir build . cd build/awesome cp ./api/.env.example ./api/.env make api-test From 003b7d39f9847650cd5af4d4b017cc58a6f4a174 Mon Sep 17 00:00:00 2001 From: Denys Chura Date: Wed, 23 Oct 2024 17:32:12 +0300 Subject: [PATCH 3/3] Add `concurrency` to default github workflow to ensures that only one instance of a workflow runs at a time --- .github/workflows/default.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index ed11ed0..9fb6eb1 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -9,6 +9,10 @@ on: - synchronize - reopened +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: run-checks: uses: django-stars/backend-skeleton/.github/workflows/test.yml@improve-github-workflow