Skip to content

Commit

Permalink
chore(ZCH-127): change_detection for django, dotnet, node, python, sp…
Browse files Browse the repository at this point in the history
…ringboot, sonar-dotnet
  • Loading branch information
luca-sartori-zupit committed Oct 22, 2024
1 parent 881a928 commit 75e0df1
Show file tree
Hide file tree
Showing 10 changed files with 380 additions and 34 deletions.
56 changes: 50 additions & 6 deletions .github/workflows/django-workflow-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ on:
RUN_ON:
required: false
type: string
default: 'zupit-agents'
default: "zupit-agents"
RUNNERS_CONTAINER_GROUP:
required: false
type: string
default: 'Container'
default: "Container"
RUN:
required: false
type: boolean
Expand All @@ -48,11 +48,46 @@ on:
required: false
type: number
default: 50
CHECK_WORKDIR_CHANGES:
required: true
type: boolean
default: false
CHECK_CUSTOM_DIR:
required: false
type: string
default: ""
CHECK_CHANGES_BY_JOBS:
required: false
type: string
default: "all"
env:
CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }}

jobs:
workdir-has-changes:
runs-on: ubuntu-latest
outputs:
changes-detected: ${{ steps.filter.outputs.changes-detected }}
steps:
- name: Set CHECK_DIR to custom directory if provided
if: ${{ inputs.CHECK_CUSTOM_DIR != '' }}
run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV
- name: Set default CHECK_DIR
if: ${{ inputs.CHECK_CUSTOM_DIR == '' }}
run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV

- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
changes-detected:
- "${{ env.CHECK_DIR }}/**"
django-lint-check:
uses:
./.github/workflows/django-step-lint-check.yml
needs: workdir-has-changes
if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))}}
uses: ./.github/workflows/django-step-lint-check.yml
with:
RUN_ON: ${{inputs.RUN_ON}}
RUNNERS_CONTAINER_GROUP: ${{inputs.RUNNERS_CONTAINER_GROUP}}
Expand All @@ -66,8 +101,9 @@ jobs:
secrets: inherit

django-tests:
uses:
./.github/workflows/django-step-tests.yml
needs: workdir-has-changes
if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))}}
uses: ./.github/workflows/django-step-tests.yml
with:
RUN_ON: ${{inputs.RUN_ON}}
RUNNERS_CONTAINER_GROUP: ${{inputs.RUNNERS_CONTAINER_GROUP}}
Expand All @@ -80,3 +116,11 @@ jobs:
LFS_REPO_PATH: ${{inputs.LFS_REPO_PATH}}
COVERAGE_THRESHOLD: ${{inputs.COVERAGE_THRESHOLD}}
secrets: inherit

jobs-succeded:
needs: ["django-lint-check", "django-tests"]
runs-on: ubuntu-latest
if: ${{ always()}}
steps:
- name: "Jobs: django-lint-check, django-tests didn't fail."
run: if [[ "${{ needs.django-lint-check.result }}" == "failure" || "${{ needs.django-tests.result }}" == "failure" ]]; then exit 1; fi
53 changes: 49 additions & 4 deletions .github/workflows/dotnet-workflow-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ on:
RUN_ON:
required: false
type: string
default: 'zupit-agents'
default: "zupit-agents"
RUNNERS_CONTAINER_GROUP:
required: false
type: string
default: 'Container'
default: "Container"
DOTNET_IMAGE_ENV_VARIABLES:
required: false
type: string
default: '{}'
default: "{}"
CSHARPIER_VERSION:
required: false
type: string
default: ''
default: ""
RUN_LINT:
required: false
type: boolean
Expand All @@ -33,10 +33,47 @@ on:
required: false
type: boolean
default: true
CHECK_WORKDIR_CHANGES:
required: true
type: boolean
default: false
CHECK_CUSTOM_DIR:
required: false
type: string
default: ""
CHECK_CHANGES_BY_JOBS:
required: false
type: string
default: "all"

env:
CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }}

jobs:
workdir-has-changes:
runs-on: ubuntu-latest
outputs:
changes-detected: ${{ steps.filter.outputs.changes-detected }}
steps:
- name: Set CHECK_DIR to custom directory if provided
if: ${{ inputs.CHECK_CUSTOM_DIR != '' }}
run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV
- name: Set default CHECK_DIR
if: ${{ inputs.CHECK_CUSTOM_DIR == '' }}
run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV

- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
changes-detected:
- "${{ env.CHECK_DIR }}/**"
dotnet-common:
needs: workdir-has-changes
name: Run .NET build, check formatting and test
if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))}}
runs-on:
labels: ${{ inputs.RUN_ON }}
group: ${{ inputs.RUNNERS_CONTAINER_GROUP }}
Expand Down Expand Up @@ -76,3 +113,11 @@ jobs:
with:
WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }}
GENERATE_CODE_COVERAGE: false

jobs-succeded:
needs: dotnet-common
runs-on: ubuntu-latest
if: ${{ always()}}
steps:
- name: "Jobs: dotnet-common didn't fail."
run: if [ "${{ needs.dotnet-common.result }}" == "failure" ]; then exit 1; fi
57 changes: 50 additions & 7 deletions .github/workflows/node-workflow-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ on:
RUN_ON:
required: false
type: string
default: 'zupit-agents'
default: "zupit-agents"
RUNNERS_CONTAINER_GROUP:
required: false
type: string
default: 'Container'
default: "Container"
RUN:
required: false
type: boolean
Expand All @@ -42,11 +42,47 @@ on:
required: false
type: string
default: ""
CHECK_WORKDIR_CHANGES:
required: true
type: boolean
default: false
CHECK_CUSTOM_DIR:
required: false
type: string
default: ""
CHECK_CHANGES_BY_JOBS:
required: false
type: string
default: "all"

env:
CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }}

jobs:
workdir-has-changes:
runs-on: ubuntu-latest
outputs:
changes-detected: ${{ steps.filter.outputs.changes-detected }}
steps:
- name: Set CHECK_DIR to custom directory if provided
if: ${{ inputs.CHECK_CUSTOM_DIR != '' }}
run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV
- name: Set default CHECK_DIR
if: ${{ inputs.CHECK_CUSTOM_DIR == '' }}
run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV

- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
changes-detected:
- "${{ env.CHECK_DIR }}/**"
lint-check-build:
uses:
./.github/workflows/node-step-format-lint-build.yml
needs: workdir-has-changes
if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))}}
uses: ./.github/workflows/node-step-format-lint-build.yml
with:
RUN_ON: ${{inputs.RUN_ON}}
RUNNERS_CONTAINER_GROUP: ${{inputs.RUNNERS_CONTAINER_GROUP}}
Expand All @@ -57,9 +93,9 @@ jobs:
secrets: inherit

cypress-run:
if: ${{ inputs.ENABLE_TESTS }}
uses:
./.github/workflows/node-step-test-cypress.yml
needs: workdir-has-changes
if: ${{ inputs.ENABLE_TESTS && (!inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))) }}
uses: ./.github/workflows/node-step-test-cypress.yml
with:
RUN_ON: ${{inputs.RUN_ON}}
RUNNERS_CONTAINER_GROUP: ${{inputs.RUNNERS_CONTAINER_GROUP}}
Expand All @@ -71,3 +107,10 @@ jobs:
PROJECT: ${{ inputs.PROJECT }}
secrets: inherit

jobs-succeded:
needs: ["lint-check-build", "cypress-run"]
runs-on: ubuntu-latest
if: ${{ always()}}
steps:
- name: "Jobs: lint-check-build, cypress-run didn't fail."
run: if [[ "${{ needs.lint-check-build.result }}" == "failure" || "${{ needs.cypress-run.result }}" == "failure" ]]; then exit 1; fi
52 changes: 48 additions & 4 deletions .github/workflows/python-workflow-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ on:
RUN_ON:
required: false
type: string
default: 'zupit-agents'
default: "zupit-agents"
RUNNERS_CONTAINER_GROUP:
required: false
type: string
default: 'Container'
default: "Container"
RUN:
required: false
type: boolean
Expand All @@ -36,11 +36,47 @@ on:
required: false
type: string
default: ""
CHECK_WORKDIR_CHANGES:
required: true
type: boolean
default: false
CHECK_CUSTOM_DIR:
required: false
type: string
default: ""
CHECK_CHANGES_BY_JOBS:
required: false
type: string
default: "all"

env:
CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }}

jobs:
workdir-has-changes:
runs-on: ubuntu-latest
outputs:
changes-detected: ${{ steps.filter.outputs.changes-detected }}
steps:
- name: Set CHECK_DIR to custom directory if provided
if: ${{ inputs.CHECK_CUSTOM_DIR != '' }}
run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV
- name: Set default CHECK_DIR
if: ${{ inputs.CHECK_CUSTOM_DIR == '' }}
run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV

- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
changes-detected:
- "${{ env.CHECK_DIR }}/**"
django-lint-check:
uses:
./.github/workflows/python-step-lint-check.yml
needs: workdir-has-changes
if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))}}
uses: ./.github/workflows/python-step-lint-check.yml
with:
RUN_ON: ${{inputs.RUN_ON}}
RUNNERS_CONTAINER_GROUP: ${{inputs.RUNNERS_CONTAINER_GROUP}}
Expand All @@ -51,3 +87,11 @@ jobs:
ENABLE_LFS: ${{inputs.ENABLE_LFS}}
LFS_REPO_PATH: ${{inputs.LFS_REPO_PATH}}
secrets: inherit

jobs-succeded:
needs: ["django-lint-check"]
runs-on: ubuntu-latest
if: ${{ always()}}
steps:
- name: "Jobs: django-lint-check didn't fail."
run: if [[ "${{ needs.django-lint-check.result }}" == "failure" ]]; then exit 1; fi
45 changes: 45 additions & 0 deletions .github/workflows/sonar-step-dotnet-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,46 @@ on:
required: false
type: string
default: "**/*.trx"
CHECK_WORKDIR_CHANGES:
required: true
type: boolean
default: false
CHECK_CUSTOM_DIR:
required: false
type: string
default: ""
CHECK_CHANGES_BY_JOBS:
required: false
type: string
default: "all"

env:
CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }}

jobs:
workdir-has-changes:
runs-on: ubuntu-latest
outputs:
changes-detected: ${{ steps.filter.outputs.changes-detected }}
steps:
- name: Set CHECK_DIR to custom directory if provided
if: ${{ inputs.CHECK_CUSTOM_DIR != '' }}
run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV
- name: Set default CHECK_DIR
if: ${{ inputs.CHECK_CUSTOM_DIR == '' }}
run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV

- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
changes-detected:
- "${{ env.CHECK_DIR }}/**"
sonar-analyze:
needs: workdir-has-changes
if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job))) }}
runs-on:
labels: ${{ inputs.RUN_ON }}
group: ${{ inputs.RUNNERS_CONTAINER_GROUP }}
Expand Down Expand Up @@ -111,3 +148,11 @@ jobs:

- name: End .NET SonarScanner
run: dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

jobs-succeded:
needs: sonar-analyze
runs-on: ubuntu-latest
if: ${{ always()}}
steps:
- name: "Jobs: sonar-analyze didn't fail."
run: if [ "${{ needs.sonar-analyze.result }}" == "failure" ]; then exit 1; fi
Loading

0 comments on commit 75e0df1

Please sign in to comment.