diff --git a/.github/workflows/django-workflow-common.yml b/.github/workflows/django-workflow-common.yml index a5ce5f7..43b2a9e 100644 --- a/.github/workflows/django-workflow-common.yml +++ b/.github/workflows/django-workflow-common.yml @@ -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 @@ -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}} @@ -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}} @@ -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 diff --git a/.github/workflows/python-workflow-common.yml b/.github/workflows/python-workflow-common.yml index 5deaf5a..65b0d01 100644 --- a/.github/workflows/python-workflow-common.yml +++ b/.github/workflows/python-workflow-common.yml @@ -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 @@ -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}} @@ -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 diff --git a/.github/workflows/springboot-workflow-common.yml b/.github/workflows/springboot-workflow-common.yml index a3e2282..3682df9 100644 --- a/.github/workflows/springboot-workflow-common.yml +++ b/.github/workflows/springboot-workflow-common.yml @@ -32,15 +32,49 @@ on: DATABASE: required: false type: string - description: 'Database to use: postgres or mysql' - default: 'postgres' + description: "Database to use: postgres or mysql" + default: "postgres" + 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: "${{secrets}}" +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 }}/**" + springboot-lint-check: - uses: - ./.github/workflows/springboot-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/springboot-step-lint-check.yml with: JAVA_IMAGE: ${{inputs.JAVA_IMAGE}} WORKING_DIRECTORY: ${{inputs.WORKING_DIRECTORY}} @@ -50,9 +84,9 @@ jobs: secrets: inherit springboot-tests: - if: ${{ inputs.DATABASE == 'postgres'}} - uses: - ./.github/workflows/springboot-step-tests.yml + needs: workdir-has-changes + if: ${{ inputs.DATABASE == 'postgres' && (!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/springboot-step-tests.yml with: JAVA_IMAGE: ${{inputs.JAVA_IMAGE}} WORKING_DIRECTORY: ${{inputs.WORKING_DIRECTORY}} @@ -64,9 +98,9 @@ jobs: secrets: inherit springboot-tests-mysql: - if: ${{ inputs.DATABASE == 'mysql'}} - uses: - ./.github/workflows/springboot-step-tests-mysql.yml + needs: workdir-has-changes + if: ${{ inputs.DATABASE == 'mysql' && (!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/springboot-step-tests-mysql.yml with: JAVA_IMAGE: ${{inputs.JAVA_IMAGE}} WORKING_DIRECTORY: ${{inputs.WORKING_DIRECTORY}} @@ -75,3 +109,11 @@ jobs: COVERAGE_ARTIFACT_NAME: ${{ inputs.COVERAGE_ARTIFACT_NAME }} RUN: ${{ inputs.RUN }} secrets: inherit + + jobs-succeded: + needs: ["springboot-lint-check", "springboot-tests", "springboot-tests-mysql"] + runs-on: ubuntu-latest + if: ${{ always()}} + steps: + - name: "Jobs: springboot-lint-check, springboot-tests, springboot-tests-mysql didn't fail." + run: if [[ "${{ needs.springboot-lint-check.result }}" == "failure" || "${{ needs.springboot-tests.result }}" == "failure" || "${{ needs.springboot-tests-mysql.result }}" == "failure" ]]; then exit 1; fi diff --git a/docs/CHANGE_DETECTION.md b/docs/CHANGE_DETECTION.md index 640d0d4..021a9bb 100644 --- a/docs/CHANGE_DETECTION.md +++ b/docs/CHANGE_DETECTION.md @@ -12,13 +12,13 @@ Add the parameters `CHECK_` parameters configuration to the workflow. - `CHECK_CUSTOM_DIR`: Specifies a custom DIR to check (use as override dir when the dir to check is differnt from the `WORKING_DIRECTORY`) -- `CHECK_CHANGES_BY_JOBS`: String array that specifies the job id where this dir check is ran. Default is `'all'`. (ex: `"['dotnet-common']"`) +- `CHECK_CHANGES_BY_JOBS`: String array that specifies the job id where this dir check is ran. Default is `'all'`. (ex: `"['pr-backend']"`) ## To implement and use them on custom/local workflows: 1. Add a job (ex: `workdir-has-changes`) that checks for changes on specific directories and outputs a variable (ex: `run-backend`) which stores `true` if it has detected changes or `false` if it didn't -2. Add a job (ex: `pr-backend-success`) that fails when the child steps fails and succeeds when child jobs succeed or get skipped. +2. Add a job (ex: `jobs-succeded`) that fails when the child steps fails and succeeds when child jobs succeed or get skipped. This will be the job that will be set on the branch protection policy 3. Add a `needs` statement that refers to the check-changes job (ex: `workdir-has-changes`) @@ -29,32 +29,30 @@ Add the parameters `CHECK_` parameters configuration to the workflow. ```yml jobs: - workdir-has-changes: - runs-on: ubuntu-latest - outputs: - run-backend: ${{ steps.filter.outputs.backend }} - steps: - - uses: actions/checkout@v4 - - uses: dorny/paths-filter@v3 - id: filter - with: - filters: | - backend: - - 'Backend/**' - - pr-backend: - needs: workdir-has-changes - if: ${{ needs.workdir-has-changes.outputs.run-backend == 'true' }} - uses: ./.github/workflows/common-backend.yml - secrets: inherit - - pr-backend-success: - runs-on: ubuntu-latest - needs: pr-backend - if: ${{ always() }} - steps: - - name: Checks success of common-backend.yml. - run: if [ "${{ needs.pr-backend.result }}" == "failure" ]; then exit 1; fi + workdir-has-changes: + runs-on: ubuntu-latest + outputs: + run-backend: ${{ steps.filter.outputs.backend }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + backend: + - 'Backend/**' + + pr-backend: + needs: workdir-has-changes + if: ${{ needs.workdir-has-changes.outputs.run-backend == 'true' }} + uses: ./.github/workflows/common-backend.yml + secrets: inherit + + jobs-succeded: + needs: ["pr-backend"] + runs-on: ubuntu-latest + if: ${{ always()}} + steps: + - name: "Jobs: pr-backend didn't fail." + run: if [[ "${{ needs.pr-backend.result }}" == "failure" ]]; then exit 1; fi ``` - -Example with edits view diff --git a/docs/image.png b/docs/image.png deleted file mode 100644 index a91c3a4..0000000 Binary files a/docs/image.png and /dev/null differ