From a5fee04c71034baf8cdc7934da83466cc603432d Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Thu, 11 Apr 2024 09:19:51 -0700 Subject: [PATCH 1/2] Use bcgov-nr/diff-action-triggers --- action.yml | 74 ++++++++++++++---------------------------------------- 1 file changed, 19 insertions(+), 55 deletions(-) diff --git a/action.yml b/action.yml index 3eaf64c..ce21ff4 100644 --- a/action.yml +++ b/action.yml @@ -52,13 +52,6 @@ inputs: runs: using: composite steps: - # Shallow clone is faster, but SonarCloud requires a full clone - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - repository: ${{ inputs.repository }} - ref: ${{ inputs.branch }} - - name: Warnings for breaking changes shell: bash run: | @@ -85,59 +78,31 @@ runs: exit 1 fi - # Process variables and inputs - - id: vars - shell: bash - run: | - # Triggers and conditions - - # Arrays must be stored first - TRIGGERS=${{ inputs.triggers }} - T_EVENTS=${{ inputs.triggers_event }} - - # Default to triggered=true - echo "triggered=true" >> $GITHUB_OUTPUT - - # Run/trigger conditions - if [[ ! "${T_EVENTS}" =~ "${{ github.event_name }}" ]] - then - # Event doesn't match on type, so fire - echo "Event not matched, so always test" - exit 0 - elif [ -z "${TRIGGERS}" ] - then - # Triggers omitted, so fire - echo "Triggers omitted, so always test" - exit 0 - else - # Check triggers against a git diff - echo "Processing triggers" - git fetch origin "${{ inputs.diff_branch }}" - while read -r check; do - for t in "${TRIGGERS[@]}"; do - if [[ "${check}" =~ "${t}" ]]; then - echo -e "Triggered: ${t}\n --> ${check}" - exit 0 - fi - done - done < <(git diff origin/"${{ inputs.diff_branch }}" --name-only) - fi + # Send triggers to diff action + - id: diff + uses: bcgov-nr/action-diff-triggers@v0.2.0 + with: + triggers: ${{ inputs.triggers }} + diff_branch: ${{ inputs.diff_branch }} - # Conditions not met, do not fire - echo "Triggers not matched, testing skipped" - echo "triggered=false" >> $GITHUB_OUTPUT + # Shallow clone is faster, but SonarCloud requires a full clone + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + repository: ${{ inputs.repository }} + ref: ${{ inputs.branch }} # Setup node and cache dir - uses: actions/setup-node@v4 - if: steps.vars.outputs.triggered == 'true' + if: steps.diff.outputs.triggered == 'true' with: node-version: ${{ inputs.node_version }} - id: npm-cache-dir - if: steps.vars.outputs.triggered == 'true' + if: steps.diff.outputs.triggered == 'true' shell: bash run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT - uses: actions/cache@v4 - if: steps.vars.outputs.triggered == 'true' + if: steps.diff.outputs.triggered == 'true' with: path: ${{ steps.npm-cache-dir.outputs.dir }} key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} @@ -145,7 +110,7 @@ runs: # Run tests, hopefully generating coverage for SonarCloud - name: Run Tests - if: steps.vars.outputs.triggered == 'true' + if: steps.diff.outputs.triggered == 'true' shell: bash run: | cd ${{ inputs.dir }} @@ -154,8 +119,7 @@ runs: ### Optional SonarCloud # If sonar_token - - name: SonarCloud Scan - if: inputs.sonar_token && steps.vars.outputs.triggered == 'true' + - if: inputs.sonar_token && steps.diff.outputs.triggered == 'true' uses: SonarSource/sonarcloud-github-action@v2.1.1 env: SONAR_TOKEN: ${{ inputs.sonar_token }} @@ -168,13 +132,13 @@ runs: # Fix - Docker can take file ownership, causing a cleanup fail - shell: bash - if: steps.vars.outputs.triggered == 'true' + if: steps.diff.outputs.triggered == 'true' id: get_uid run: | # User for workstation ownership reset/fix echo "uid=$(id -u ${USER})" >> $GITHUB_OUTPUT - uses: peter-murray/reset-workspace-ownership-action@v1 - if: steps.vars.outputs.triggered == 'true' + if: steps.diff.outputs.triggered == 'true' with: user_id: ${{ steps.get_uid.outputs.uid }} From 6cfb768f1429c2fc1d49cc943e9837664bab5b45 Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Thu, 11 Apr 2024 09:23:19 -0700 Subject: [PATCH 2/2] Omit frontend-pr trigger --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 62d7cfc..c5ccd70 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,7 +34,6 @@ jobs: - name: frontend-pr dir: frontend token: SONAR_TOKEN_FRONTEND - triggers: ('.') triggers_event: ('push') steps: - uses: actions/checkout@v4