From 4d19d0f2b9a9ddf64877331085a8f643b4164c2c Mon Sep 17 00:00:00 2001 From: Dima Tisnek Date: Thu, 6 Jun 2024 12:32:17 +0900 Subject: [PATCH] ci: only run tests once on push to pr (#1242) I've noticed that when a new commit is pushed to a PR, the same tests are run twice: once triggered by `on: push` and another by `on: pull_request: synchronize` --- Note that the two runs are not exactly same, if the target (main) branch has received updates in the meantime, because: ### on: push Trigger: This workflow runs the tests on the new commit in the feature branch as it stands alone. It doesn't consider any changes that might have been merged into the main branch since the feature branch was last updated. ### on: pull_request: synchronize Trigger: This workflow runs the tests on the combined state of the feature branch and the main branch. It effectively simulates a merge between the feature branch and the main branch to see if the combined state would pass the tests. --- to do - [x] agree on approach - [x] apply to other workflows --- .github/workflows/charmcraft-pack.yaml | 6 +++++- .github/workflows/db-charm-tests.yaml | 7 ++++++- .github/workflows/framework-tests.yaml | 7 ++++++- .github/workflows/hello-charm-tests.yaml | 7 ++++++- .github/workflows/observability-charm-tests.yaml | 7 ++++++- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/charmcraft-pack.yaml b/.github/workflows/charmcraft-pack.yaml index 09781a3a6..1e9da1db5 100644 --- a/.github/workflows/charmcraft-pack.yaml +++ b/.github/workflows/charmcraft-pack.yaml @@ -1,6 +1,10 @@ name: Charmcraft Pack Test -on: [push, pull_request, workflow_call] +on: + push: + branches: + - main + pull_request: jobs: charmcraft-pack: diff --git a/.github/workflows/db-charm-tests.yaml b/.github/workflows/db-charm-tests.yaml index 81aa3ff2a..9f5d3a698 100644 --- a/.github/workflows/db-charm-tests.yaml +++ b/.github/workflows/db-charm-tests.yaml @@ -1,6 +1,11 @@ name: Data Charm Tests -on: [push, pull_request, workflow_call] +on: + push: + branches: + - main + pull_request: + workflow_call: jobs: db-charm-tests: diff --git a/.github/workflows/framework-tests.yaml b/.github/workflows/framework-tests.yaml index 0979b03b6..820c04ce0 100644 --- a/.github/workflows/framework-tests.yaml +++ b/.github/workflows/framework-tests.yaml @@ -1,6 +1,11 @@ name: ops Tests -on: [push, pull_request, workflow_call] +on: + push: + branches: + - main + pull_request: + workflow_call: jobs: lint: diff --git a/.github/workflows/hello-charm-tests.yaml b/.github/workflows/hello-charm-tests.yaml index 3a756af3c..3bd163463 100644 --- a/.github/workflows/hello-charm-tests.yaml +++ b/.github/workflows/hello-charm-tests.yaml @@ -1,6 +1,11 @@ name: Hello Charm Tests -on: [push, pull_request, workflow_call] +on: + push: + branches: + - main + pull_request: + workflow_call: jobs: hello-charm-tests: diff --git a/.github/workflows/observability-charm-tests.yaml b/.github/workflows/observability-charm-tests.yaml index b3e4bd2c2..e70e16e5d 100644 --- a/.github/workflows/observability-charm-tests.yaml +++ b/.github/workflows/observability-charm-tests.yaml @@ -1,6 +1,11 @@ name: Observability Charm Tests -on: [push, pull_request, workflow_call] +on: + push: + branches: + - main + pull_request: + workflow_call: jobs: o11y-charm-tests: