From 0d193029efd26c76aeacaa84aba3328de8198370 Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Mon, 26 Feb 2024 23:44:39 -0800 Subject: [PATCH] feat: omit triggers for true (#7) --- .github/workflows/pr-open.yml | 25 +++++++++++++++++++------ action.yml | 15 ++++++++++++--- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index e294b3b..b667403 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -32,15 +32,28 @@ jobs: with: triggers: ('path/to/nowhere') + test-omitted: + name: Test for Omitted + outputs: + triggered: ${{ steps.test.outputs.triggered }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: ./ + id: test + results: name: Results - needs: [test-true, test-false] + needs: [test-true, test-false, test-omitted] runs-on: ubuntu-22.04 steps: - - run: | - echo "needs.test-true.outputs.triggered: ${{ needs.test-true.outputs.triggered }}" - echo "needs.test-false.outputs.triggered: ${{ needs.test-false.outputs.triggered }}" - - - if: needs.test-true.outputs.triggered != 'true' || needs.test-false.outputs.triggered != 'false' + - if: + needs.test-true.outputs.triggered != 'true' || + needs.test-false.outputs.triggered != 'false' || + needs.test-omitted.outputs.triggered != 'true' run: | + # Explain any errors + echo "needs.test-true.outputs.triggered: ${{ needs.test-true.outputs.triggered }} - expected: true" + echo "needs.test-false.outputs.triggered: ${{ needs.test-false.outputs.triggered }} - expected: false" + echo "needs.test-omitted.outputs.triggered: ${{ needs.test-false.outputs.triggered }} - expected: true" exit 1 diff --git a/action.yml b/action.yml index 61f50e9..273e874 100644 --- a/action.yml +++ b/action.yml @@ -6,9 +6,11 @@ branding: inputs: ### Required + # Nothing! + + ### Typical / recommended triggers: - description: Paths used to trigger an event; e.g. ('./backend/' './frontend/) - required: true + description: Paths used to trigger an event; e.g. ('./backend/' './frontend/); always trigger if omitted ### Usually a bad idea / not recommended diff_branch: @@ -29,6 +31,13 @@ runs: shell: bash id: diff run: | + # Always fire if triggers are omitted + if [ -z "${{ inputs.triggers }}" ]; then + echo "Always fire when triggers are omitted!" + echo "triggered=true" >> $GITHUB_OUTPUT + exit 0 + fi + # Build if changed files (git diff) match triggers TRIGGERS=${{ inputs.triggers }} git fetch origin ${{ inputs.diff_branch }} @@ -45,5 +54,5 @@ runs: done < <(git diff origin/${{ inputs.diff_branch }} --name-only) # If at this point, no trigger has fired - echo "Container build not required" + echo "Triggers have not fired" echo "triggered=false" >> $GITHUB_OUTPUT