diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000000..bd7e5df6fa --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,29 @@ +### Background + +This document aims to explain the bunch of server and webapp yaml files and their functionality. + +The context behind this complexity is that we want new pushes to PR branches to cancel older in-progress and pending CI runs, _but_ we don't want that to happen in master branch. Unfortunately, there is no config knob to control pending workflows and if you set a concurrency group, then pending workflows will _always_ be canceled. Refer to https://github.com/orgs/community/discussions/5435 for discussion. + +Therefore, we have a template yaml file which is actually the main CI code. That is then imported by `{server|webapp}-ci-master.yml` and `{server|webapp}-ci-pr.yml`. The `-master.yml` files don't have any concurrency limits, but `-pr.yml` files do. + +### Folder structure + +server-ci-pr +| +---server-ci-template + | + ---server-test-template (common code for postgres and mysql tests) + +server-ci-master +| +---server-ci-template + | + ---server-test-template (common code for postgres and mysql tests) + +webapp-ci-pr +| +---webapp-ci-template + +webapp-ci-master +| +---webapp-ci-template diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 6977d1c2c1..ac36893725 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -1,7 +1,7 @@ name: Artifacts generation and upload on: workflow_run: - workflows: ["Server CI"] + workflows: ["Server CI Master", "Server CI PR"] types: - completed diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 597302f900..bb0772ab0a 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,9 +1,5 @@ name: "CodeQL" -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - on: pull_request: # The branches below must be a subset of the branches above diff --git a/.github/workflows/e2e-tests-ci.yml b/.github/workflows/e2e-tests-ci.yml index 89c7cbfeed..e526b8a79c 100644 --- a/.github/workflows/e2e-tests-ci.yml +++ b/.github/workflows/e2e-tests-ci.yml @@ -5,9 +5,7 @@ on: branches: - master - mono-repo* -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + defaults: run: shell: bash diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 685c9a4ebf..9a5a652abb 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -5,10 +5,6 @@ on: schedule: - cron: '44 6 * * *' -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} - # Declare default permissions as read only. permissions: read-all diff --git a/.github/workflows/server-ci-master.yml b/.github/workflows/server-ci-master.yml new file mode 100644 index 0000000000..c2f73b8e51 --- /dev/null +++ b/.github/workflows/server-ci-master.yml @@ -0,0 +1,14 @@ +name: Server CI Master +on: + push: + branches: + - master + - cloud + - release-* + - mono-repo* +env: + go-version: "1.19.5" + +jobs: + master-ci: + uses: ./.github/workflows/server-ci-template.yml diff --git a/.github/workflows/server-ci-pr.yml b/.github/workflows/server-ci-pr.yml new file mode 100644 index 0000000000..c8e229c11b --- /dev/null +++ b/.github/workflows/server-ci-pr.yml @@ -0,0 +1,19 @@ +name: Server CI PR +on: + pull_request: + +env: + go-version: "1.19.5" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +# This file just imports the template yml +# and runs it with concurrency. We have to do this in this way +# because the concurrency label cannot be added conditionally +# and it _always_ cancels pending workflows. So master CI builds +# always kept getting canceled. + +jobs: + pr-ci: + uses: ./.github/workflows/server-ci-template.yml diff --git a/.github/workflows/server-ci.yml b/.github/workflows/server-ci-template.yml similarity index 94% rename from .github/workflows/server-ci.yml rename to .github/workflows/server-ci-template.yml index 36e4c2bf1b..c5ae8d9398 100644 --- a/.github/workflows/server-ci.yml +++ b/.github/workflows/server-ci-template.yml @@ -1,17 +1,13 @@ -name: Server CI +# Base CI template which is called from server-ci-pr.yml +# and server-ci-master.yml + +name: Server CI Template on: - pull_request: - push: - branches: - - master - - cloud - - release-* - - mono-repo* + workflow_call: + env: go-version: "1.19.5" -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: check-mocks: name: Check mocks @@ -190,23 +186,23 @@ jobs: - name: Check generated code run: if [[ -n $(git status --porcelain) ]]; then echo "Please update the app layers using make app-layers"; exit 1; fi test-postgres-binary: - name: Run tests on postgres with binary parameters + name: Postgres with binary parameters needs: check-mattermost-vet - uses: ./.github/workflows/test.yml + uses: ./.github/workflows/server-test-template.yml with: datasource: postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10&binary_parameters=yes drivername: postgres test-postgres-normal: - name: Run tests on postgres + name: Postgres needs: check-mattermost-vet - uses: ./.github/workflows/test.yml + uses: ./.github/workflows/server-test-template.yml with: datasource: postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10 drivername: postgres test-mysql: - name: Run tests on mysql + name: MySQL needs: check-mattermost-vet - uses: ./.github/workflows/test.yml + uses: ./.github/workflows/server-test-template.yml with: datasource: mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8&multiStatements=true drivername: mysql diff --git a/.github/workflows/test.yml b/.github/workflows/server-test-template.yml similarity index 98% rename from .github/workflows/test.yml rename to .github/workflows/server-test-template.yml index ed18b802f0..624d2eb31f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/server-test-template.yml @@ -1,4 +1,4 @@ -name: Test +name: Server Test Template on: workflow_call: inputs: @@ -11,7 +11,7 @@ on: env: go-version: "1.19.5" jobs: - run-tests: + test: runs-on: ubuntu-latest-8-cores env: COMPOSE_PROJECT_NAME: ghactions diff --git a/.github/workflows/webapp-ci-master.yml b/.github/workflows/webapp-ci-master.yml new file mode 100644 index 0000000000..387663f60c --- /dev/null +++ b/.github/workflows/webapp-ci-master.yml @@ -0,0 +1,12 @@ +name: Web App CI Master +on: + push: + branches: + - master + - cloud + - release-* + - mono-repo* + +jobs: + master-ci: + uses: ./.github/workflows/webapp-ci-template.yml diff --git a/.github/workflows/webapp-ci-pr.yml b/.github/workflows/webapp-ci-pr.yml new file mode 100644 index 0000000000..9aef2ff492 --- /dev/null +++ b/.github/workflows/webapp-ci-pr.yml @@ -0,0 +1,17 @@ +name: Web App CI PR +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +# This file just imports the template yml +# and runs it with concurrency. We have to do this in this way +# because the concurrency label cannot be added conditionally +# and it _always_ cancels pending workflows. So master CI builds +# always kept getting canceled. + +jobs: + pr-ci: + uses: ./.github/workflows/webapp-ci-template.yml diff --git a/.github/workflows/webapp-ci.yml b/.github/workflows/webapp-ci-template.yml similarity index 97% rename from .github/workflows/webapp-ci.yml rename to .github/workflows/webapp-ci-template.yml index f89ee722a9..b303bcb908 100644 --- a/.github/workflows/webapp-ci.yml +++ b/.github/workflows/webapp-ci-template.yml @@ -1,13 +1,10 @@ -name: Web App CI +# Base CI template which is called from webapp-ci-pr.yml +# and webapp-ci-master.yml + +name: Web App CI Template on: - pull_request: - push: - branches: - - master - - mono-repo* -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + workflow_call: + defaults: run: shell: bash