From 81d8c04ec41e2abbaf31922971f225cf3956120a Mon Sep 17 00:00:00 2001 From: Paule <44635962+V3lop5@users.noreply.github.com> Date: Wed, 8 Dec 2021 22:17:55 +0100 Subject: [PATCH 1/4] Allow only one ssh connection at a time #24 --- .github/workflows/main.yml | 1 + .github/workflows/pull-request-done.yml | 2 ++ .github/workflows/pull-request.yml | 41 +++++++++++++------------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 36ff909..e34d296 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -221,6 +221,7 @@ jobs: deploy_dev: needs: [ build_dev_image ] runs-on: ubuntu-latest + concurrency: ssh-${{ secrets.SSH_URL }}-${{ secrets.SSH_USER }} # only one ssh connection at a time name: "Deploy dev image" if: ${{ success() && github.actor != 'dependabot[bot]' }} steps: diff --git a/.github/workflows/pull-request-done.yml b/.github/workflows/pull-request-done.yml index 64d9522..dd7cf68 100644 --- a/.github/workflows/pull-request-done.yml +++ b/.github/workflows/pull-request-done.yml @@ -38,6 +38,7 @@ jobs: preview_delete: runs-on: ubuntu-latest + concurrency: ssh-${{ secrets.SSH_URL }}-${{ secrets.SSH_USER }} # only one ssh connection at a time name: "Delete preview" if: ${{ github.actor != 'dependabot[bot]' }} steps: @@ -179,6 +180,7 @@ jobs: deploy_prod: needs: [ build_prod_image ] runs-on: ubuntu-latest + concurrency: ssh-${{ secrets.SSH_URL }}-${{ secrets.SSH_USER }} # only one ssh connection at a time name: "Deploy production image" if: ${{ success() && github.actor != 'dependabot[bot]' }} steps: diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index eb823b1..aa34db1 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -2,8 +2,8 @@ name: CI/CD Pull Requests on: pull_request: - types: [opened, synchronize, reopened] - + types: [ opened, synchronize, reopened ] + jobs: # Inspect the information that is accessible in each context # https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log-file @@ -35,7 +35,7 @@ jobs: env: MATRIX_CONTEXT: ${{ toJSON(matrix) }} run: echo "$MATRIX_CONTEXT" - + # Check linting lint: runs-on: ubuntu-latest @@ -43,29 +43,29 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2.4.0 - + - name: Setup Python uses: actions/setup-python@v2 with: - python-version: '3.x' - architecture: 'x64' - + python-version: '3.x' + architecture: 'x64' + - name: Cache pip uses: actions/cache@v2 with: path: ~/.cache/pip key: lint-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements**.txt') }} - + - name: Install requirements run: | pip install --upgrade --upgrade-strategy eager -r requirements-dev.txt -e . - + - name: flake8 Lint uses: reviewdog/action-flake8@v3 with: - github_token: ${{ github.token }} - - + github_token: ${{ github.token }} + + # Checks if all tests pass test: runs-on: ubuntu-latest @@ -73,19 +73,19 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2.4.0 - + - name: Setup Python uses: actions/setup-python@v2 with: - python-version: '3.x' - architecture: 'x64' - + python-version: '3.x' + architecture: 'x64' + - name: Cache pip uses: actions/cache@v2 with: path: ~/.cache/pip key: test-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements**.txt') }} - + - name: Install requirements run: | pip install --upgrade --upgrade-strategy eager -r requirements-dev.txt -e . @@ -138,14 +138,14 @@ jobs: uses: actions/download-artifact@v2 with: name: test-results - + - name: Publish Unit Test Results uses: EnricoMi/publish-unit-test-result-action@v1 with: files: result.xml - report_individual_runs: true + report_individual_runs: true comment_mode: "create new" - + build_pr_image: needs: [ test, lint ] @@ -184,6 +184,7 @@ jobs: deploy_pr: needs: [ build_pr_image ] runs-on: ubuntu-latest + concurrency: ssh-${{ secrets.SSH_URL }}-${{ secrets.SSH_USER }} # only one ssh connection at a time name: "Deploy preview image" if: ${{ success() && github.actor != 'dependabot[bot]' }} steps: From 6a4b1d3705e5e37c25f43139a7652620e338fbf2 Mon Sep 17 00:00:00 2001 From: Paule <44635962+V3lop5@users.noreply.github.com> Date: Wed, 8 Dec 2021 22:27:03 +0100 Subject: [PATCH 2/4] Cancel pull-request ci/cd if pull-request-done starts #24 --- .github/workflows/pull-request-done.yml | 10 +++++++--- .github/workflows/pull-request.yml | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-request-done.yml b/.github/workflows/pull-request-done.yml index dd7cf68..5c45954 100644 --- a/.github/workflows/pull-request-done.yml +++ b/.github/workflows/pull-request-done.yml @@ -2,8 +2,12 @@ name: CI/CD Pull Requests Close on: pull_request: - types: [closed] - + types: [ closed ] + +concurrency: + group: ${{ github.head_ref }} + cancel-in-progress: true + jobs: # Inspect the information that is accessible in each context # https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log-file @@ -74,7 +78,7 @@ jobs: if: ${{ always() }} run: | sudo pkill openconnect - + create_release: runs-on: "ubuntu-latest" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index aa34db1..74e40d0 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -4,6 +4,9 @@ on: pull_request: types: [ opened, synchronize, reopened ] +concurrency: + group: ${{ github.head_ref }} + jobs: # Inspect the information that is accessible in each context # https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log-file From 4bbc573cc6033885cd299f7efa779a8d538b38a9 Mon Sep 17 00:00:00 2001 From: Paule <44635962+V3lop5@users.noreply.github.com> Date: Wed, 8 Dec 2021 22:27:52 +0100 Subject: [PATCH 3/4] Removed secrets from concurrency name --- .github/workflows/main.yml | 2 +- .github/workflows/pull-request-done.yml | 4 ++-- .github/workflows/pull-request.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e34d296..2e96809 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -221,7 +221,7 @@ jobs: deploy_dev: needs: [ build_dev_image ] runs-on: ubuntu-latest - concurrency: ssh-${{ secrets.SSH_URL }}-${{ secrets.SSH_USER }} # only one ssh connection at a time + concurrency: ssh-connection # only one ssh connection at a time name: "Deploy dev image" if: ${{ success() && github.actor != 'dependabot[bot]' }} steps: diff --git a/.github/workflows/pull-request-done.yml b/.github/workflows/pull-request-done.yml index 5c45954..023e0df 100644 --- a/.github/workflows/pull-request-done.yml +++ b/.github/workflows/pull-request-done.yml @@ -42,7 +42,7 @@ jobs: preview_delete: runs-on: ubuntu-latest - concurrency: ssh-${{ secrets.SSH_URL }}-${{ secrets.SSH_USER }} # only one ssh connection at a time + concurrency: ssh-connection # only one ssh connection at a time name: "Delete preview" if: ${{ github.actor != 'dependabot[bot]' }} steps: @@ -184,7 +184,7 @@ jobs: deploy_prod: needs: [ build_prod_image ] runs-on: ubuntu-latest - concurrency: ssh-${{ secrets.SSH_URL }}-${{ secrets.SSH_USER }} # only one ssh connection at a time + concurrency: ssh-connection # only one ssh connection at a time name: "Deploy production image" if: ${{ success() && github.actor != 'dependabot[bot]' }} steps: diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 74e40d0..91e8531 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -187,7 +187,7 @@ jobs: deploy_pr: needs: [ build_pr_image ] runs-on: ubuntu-latest - concurrency: ssh-${{ secrets.SSH_URL }}-${{ secrets.SSH_USER }} # only one ssh connection at a time + concurrency: ssh-connection # only one ssh connection at a time name: "Deploy preview image" if: ${{ success() && github.actor != 'dependabot[bot]' }} steps: From 089db0ff3fe6497d768468b5107218f25ac1e104 Mon Sep 17 00:00:00 2001 From: Paule <44635962+V3lop5@users.noreply.github.com> Date: Wed, 8 Dec 2021 22:41:07 +0100 Subject: [PATCH 4/4] Fixed ci/cd failure if preview_delete does not find any running container #24 --- .github/workflows/pull-request-done.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-done.yml b/.github/workflows/pull-request-done.yml index 023e0df..6cfd637 100644 --- a/.github/workflows/pull-request-done.yml +++ b/.github/workflows/pull-request-done.yml @@ -72,7 +72,7 @@ jobs: password: ${{ secrets.SSH_PASS }} script: | docker ps --filter publish=$((9000 + ${{ github.event.number }})) - docker rm -f $(docker ps --filter publish=$((9000 + ${{ github.event.number }})) -aq) + docker rm -f $(docker ps --filter publish=$((9000 + ${{ github.event.number }})) -aq) > /dev/null || true - name: Disconnect VPN if: ${{ always() }}