From 2b53a94c4dad8ccf48fe112b0b17b90e980fb875 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 30 Jan 2023 16:03:48 +0100 Subject: [PATCH] Add update-depedencies workflow --- .../.github/workflows/publish.yaml | 1 + .../.github/workflows/test.yaml | 1 + .../workflows/update-dependencies.yaml | 39 +++++++++++++++++++ {{cookiecutter.project_slug}}/tasks.py | 15 +++++-- 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/.github/workflows/update-dependencies.yaml diff --git a/{{cookiecutter.project_slug}}/.github/workflows/publish.yaml b/{{cookiecutter.project_slug}}/.github/workflows/publish.yaml index fe9e320..f057ebd 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/publish.yaml +++ b/{{cookiecutter.project_slug}}/.github/workflows/publish.yaml @@ -1,6 +1,7 @@ name: Build, publish & deploy on: + workflow_dispatch: push: branches: - master diff --git a/{{cookiecutter.project_slug}}/.github/workflows/test.yaml b/{{cookiecutter.project_slug}}/.github/workflows/test.yaml index 9632a20..2e3c768 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/test.yaml +++ b/{{cookiecutter.project_slug}}/.github/workflows/test.yaml @@ -1,6 +1,7 @@ name: Test on: + workflow_dispatch: workflow_call: pull_request: branches: [ "master" ] diff --git a/{{cookiecutter.project_slug}}/.github/workflows/update-dependencies.yaml b/{{cookiecutter.project_slug}}/.github/workflows/update-dependencies.yaml new file mode 100644 index 0000000..27bb996 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.github/workflows/update-dependencies.yaml @@ -0,0 +1,39 @@ +name: Update dependencies + +on: + workflow_dispatch: + schedule: + - cron: '0 18 * * TUE' + +permissions: + pull-requests: write + contents: write + +jobs: + update: + name: Update dependencies + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: master + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + cache: pip + - name: Update dependencies + run: | + pip install pip-tools invoke + invoke update-dependencies --no-sync + - name: Create Pull Request + uses: peter-evans/create-pull-request@v4 + id: create-pull-request + with: + token: ${{ secrets.PERSONAL_TOKEN_PR }} + commit-message: Update dependencies + base: master + branch: update-dependencies + title: Update dependencies + delete-branch: true diff --git a/{{cookiecutter.project_slug}}/tasks.py b/{{cookiecutter.project_slug}}/tasks.py index 6d2129e..a9b5acf 100644 --- a/{{cookiecutter.project_slug}}/tasks.py +++ b/{{cookiecutter.project_slug}}/tasks.py @@ -10,7 +10,12 @@ TEST_ENV = {"ENV_FILE": BASE_DIR / "envs" / "test-envs.env"} @task -def sync_dependencies(ctx: Context, *, update: bool = False): +def update_dependencies(ctx: Context, *, sync: bool = True): + return compile_dependencies(ctx, update=True, sync=sync) + + +@task +def compile_dependencies(ctx: Context, *, update: bool = False, sync: bool = False): common_args = "-q --allow-unsafe --resolver=backtracking" if update: common_args += " --upgrade" @@ -30,12 +35,14 @@ def sync_dependencies(ctx: Context, *, update: bool = False): pty=True, echo=True, ) - ctx.run("pip-sync requirements.txt requirements-dev.txt", pty=True, echo=True) + if sync: + sync_dependencies(ctx) @task -def update_dependencies(ctx: Context): - return sync_dependencies(ctx, update=True) +def sync_dependencies(ctx: Context): + with ctx.cd(BASE_DIR): + ctx.run("pip-sync requirements.txt requirements-dev.txt", pty=True, echo=True) @task