Skip to content

Commit

Permalink
ARCH-2122 - Remove the flag for conditional validation inside of the …
Browse files Browse the repository at this point in the history
…job.
  • Loading branch information
danielle-casella-adams committed Jul 17, 2024
1 parent ddad49d commit 2875295
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 67 deletions.
64 changes: 3 additions & 61 deletions .github/workflows/im-reusable-validate-catalog-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# runs-on: im-linux
# filename: catalog-info.yml
# add-pr-comment: true
# only-validate-if-file-changed: true
# fail-validation-step-if-errors: true
# have-validation-step-generate-job-summary: true

Expand All @@ -38,16 +37,6 @@ on:
type: boolean
required: false
default: true
only-validate-if-file-changed:
description: |
THIS ONLY APPLIES IF THE TRIGGER IS PULL_REQUEST OR PULL.
Flag indicating whether the validation should happen on every run or just if the catalog-info.yml file changed.
This is set to false by default, so validation will happen on every run.
If the trigger is workflow_dispatch or schedule, false is an appropriate choice because validation should always run.
For a trigger like pull_request you may want to set this to true so validation only happens if the file changed.
type: boolean
required: false
default: false
fail-validation-step-if-errors:
description: Flag indicating whether the validate-catalog-info action should fail if the catalog-info.yml file contains validation errors.
type: boolean
Expand All @@ -64,7 +53,6 @@ jobs:
runs-on: ${{ inputs.runs-on }}
env:
ADD_PR_COMMENT: ${{ github.event_name == 'pull_request' && inputs.add-pr-comment == true }}
CONTINUE_WITH_VALIDATION: '' # Set in a step

steps:
- name: Print inputs & variables
Expand All @@ -86,7 +74,6 @@ jobs:
printInput('runs-on', '${{ inputs.runs-on }}');
printInput('filename', '${{ inputs.filename }}');
printInput('add-pr-comment', '${{ inputs.add-pr-comment }}');
printInput('only-validate-if-file-changed', '${{ inputs.only-validate-if-file-changed }}');
printInput('fail-validation-step-if-errors', '${{ inputs.fail-validation-step-if-errors }}');
printInput('have-validation-step-generate-job-summary', '${{ inputs.have-validation-step-generate-job-summary }}');
Expand All @@ -96,61 +83,16 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Determine if ${{ inputs.filename }} changed
if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }}
id: catalog-info-changed
uses: im-open/identify-changes-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
patterns: |
{
"catalog-info": "${{ inputs.filename }}"
}
- name: Determine whether to validate ${{ inputs.filename }} or not
uses: actions/github-script@v7
with:
script: |
const eventName = '${{ github.event_name }}';
const filename = '${{ inputs.filename }}';
const onlyValidateIfChanged = ${{ inputs.only-validate-if-file-changed }};
const catalogInfoChanged = ${{ steps.catalog-info-changed.outputs.result }};
const applicableEvents = ['push', 'pull_request'];
let continueWithValidation;
if (applicableEvents.includes(eventName)){
if (onlyValidateIfChanged){
if (catalogInfoChanged){
core.info(`Validate ${filename} - only-validate-if-file-changed=true and the file changed.`);
continueWithValidation = true;
} else {
core.info(`Do not validate ${filename} - only-validate-if-file-changed=true but the file did not change.`);
continueWithValidation = false;
}
} else {
core.info(`Validate ${filename} - only-validate-if-file-changed=false so validation should always occur.`);
continueWithValidation = true;
}
}
else {
core.info(`Validate ${filename} - The event '${eventName}' is not push or pull_request so validation should always occur.`);
continueWithValidation = true;
}
core.exportVariable('CONTINUE_WITH_VALIDATION', continueWithValidation);
- name: If applicable, validate ${{ inputs.filename }}
- name: Validate ${{ inputs.filename }}
uses: im-open/validate-catalog-info@v1
if: env.CONTINUE_WITH_VALIDATION == 'true'
id: validate
with:
filename: ${{ inputs.filename }}
fail-if-errors: ${{ inputs.fail-validation-step-if-errors }}
generate-job-summary: ${{ inputs.have-validation-step-generate-job-summary }}

- name: If pull_request, add-pr-comment=true, and validation failed comment on PR with errors
if: always() && env.CONTINUE_WITH_VALIDATION == 'true' && env.ADD_PR_COMMENT == 'true' && steps.validate.outputs.is-valid != 'true'
- name: If event is pull_request, add-pr-comment is true, and validation has failed then comment on PR with errors
if: always() && env.ADD_PR_COMMENT == 'true' && steps.validate.outputs.is-valid != 'true'
continue-on-error: true
uses: im-open/[email protected]
with:
Expand Down
5 changes: 2 additions & 3 deletions workflow-templates/im-build-dotnet-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ jobs:
validate-catalog-info:
uses: im-practices/.github/.github/workflows/im-reusable-validate-catalog-info.yml@v3
with:
# Any of these items can be changed from their default
# Any of these items can be changed from their default values
# runs-on: im-linux
# filename: catalog-info.yml
# only-validate-if-file-changed: true # false by default, but can be set to true so validation only happens if the file changed
# add-pr-comment: true # Creates a PR comment if there are any validation errors
# fail-validation-step-if-errors: true # Can be set to false so this job does not fail if there are any validation errors
# have-validation-step-generate-job-summary: true # Adds a job summary with all validation errors to workflow summary tab but can be disabled
Expand Down Expand Up @@ -612,7 +611,7 @@ jobs:
# 3 - Check for workflow failures
finish-build:
if: always() && needs.setup-build-workflow.outputs.CONTINUE_WORKFLOW == 'true'
needs: [setup-build-workflow, validate-catalog-info, dotnet-test, jest]
needs: [setup-build-workflow, validate-catalog-info, dotnet-test, jest, build-deployment-artifacts]
uses: im-practices/.github/.github/workflows/im-reusable-finish-build-workflow.yml@v3
with:
next-version: ${{ needs.setup-build-workflow.outputs.NEXT_VERSION }}
Expand Down
5 changes: 2 additions & 3 deletions workflow-templates/im-test-catalog-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ jobs:
# If the trigger is pull_request, consider adding this reusable job to the CI workflow
add-pr-comment: false

# Any of these items can be changed from their defaults if necessary
# These items can be changed from their defaults if necessary
# runs-on: im-linux
# filename: catalog-info.yml # Most repos should have this as their catalog-info.yml filename
# filename: catalog-info.yml # Most repos should have this as their catalog info filename

# This workflow is dedicated to validating catalog-info.yml so it is best
# to leave these items as their default values
# only-validate-if-file-changed: false
# have-validation-step-generate-job-summary: true # Adds a job summary with all validation errors to workflow summary tab but can be disabled
# fail-validation-step-if-errors: true # Can be set to false so this job does not fail if there are any validation errors

0 comments on commit 2875295

Please sign in to comment.