diff --git a/.github/workflows/action_tests.yaml b/.github/workflows/action_tests.yaml index 2ef8606e..88f8876f 100644 --- a/.github/workflows/action_tests.yaml +++ b/.github/workflows/action_tests.yaml @@ -419,6 +419,49 @@ jobs: npm install ./action_tests/assert.js all-hold-the-line-no-upload-id + pull_request_expect_trunk_check_timeout: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + path: local-action + + - name: Set up test + shell: bash + run: | + ./local-action/action_tests/setup.sh src-repo repo-under-test + cd repo-under-test + git checkout feature-branch + echo "EXPECTED_UPSTREAM=$(git rev-parse feature-branch^1)" >>$GITHUB_ENV + + - name: Run trunk-action + shell: bash + id: trunk-action + run: | + cd repo-under-test + git checkout feature-branch + ../local-action/pull_request.sh + env: + INPUT_ARGUMENTS: "" + INPUT_CHECK_RUN_ID: 12345678 + INPUT_DEBUG: "" + INPUT_LABEL: "" + TRUNK_PATH: ../local-action/action_tests/stub.js + INPUT_GITHUB_REF_NAME: feature-branch + GITHUB_EVENT_PULL_REQUEST_NUMBER: "" + GITHUB_EVENT_PULL_REQUEST_BASE_SHA: ${{ env.EXPECTED_UPSTREAM }} + GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: "" + GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FORK: "" + INPUT_SAVE_ANNOTATIONS: "" + INPUT_AUTOFIX_AND_PUSH: true + INPUT_TIMEOUT_SECONDS: 1 + + - name: Assert trunk-action check has failed + shell: bash + if: steps.trunk-action.outcome == 'success' + run: exit 1 + pull_request_autofix: runs-on: ubuntu-latest steps: diff --git a/action.yaml b/action.yaml index 1e74710c..1c57b68c 100644 --- a/action.yaml +++ b/action.yaml @@ -102,6 +102,18 @@ inputs: required: false default: "false" + timeout-seconds: + description: + Timeout seconds before we kill the long running trunk check process via unix timeout command. + Default setting of 0 seconds disables the timeout. + required: false + default: 0 + + cat-trunk-debug-logs: + description: Option to cat .trunk/logs/cli.log && .trunk/logs/daemon.log + required: false + default: false + runs: using: composite steps: @@ -179,6 +191,7 @@ runs: INPUT_CACHE=${{ inputs.cache }} INPUT_CACHE_KEY=trunk-${{ inputs.cache-key }}-${{ runner.os }}-${{ hashFiles('.trunk/trunk.yaml') }} INPUT_CACHE_PATH=~/.cache/trunk + INPUT_CAT_TRUNK_DEBUG_LOGS=${{ inputs.cat-trunk-debug-logs }} INPUT_CHECK_ALL_MODE=${{ inputs.check-all-mode }} INPUT_CHECK_MODE=${{ inputs.check-mode }} INPUT_CHECK_RUN_ID=${{ inputs.check-run-id }} @@ -189,6 +202,7 @@ runs: INPUT_SETUP_DEPS=${{ inputs.setup-deps }} INPUT_TARGET_CHECKOUT= INPUT_TARGET_CHECKOUT_REF= + INPUT_TIMEOUT_SECONDS=${{ inputs.timeout-seconds }} INPUT_TRUNK_PATH=${{ inputs.trunk-path }} INPUT_UPLOAD_LANDING_STATE=false INPUT_UPLOAD_SERIES=${{ inputs.upload-series }} @@ -260,7 +274,11 @@ runs: shell: bash run: | # Run 'trunk check' on pull request - ${GITHUB_ACTION_PATH}/pull_request.sh + if [[ "${{ inputs.timeout-seconds }}" != "0" ]]; then + timeout ${{ inputs.timeout-seconds }} ${GITHUB_ACTION_PATH}/pull_request.sh + else + ${GITHUB_ACTION_PATH}/pull_request.sh + fi env: INPUT_SAVE_ANNOTATIONS: ${{ inputs.save-annotations }} @@ -269,7 +287,11 @@ runs: shell: bash run: | # Run 'trunk check' on push - ${GITHUB_ACTION_PATH}/push.sh + if [[ "${{ inputs.timeout-seconds }}" != "0" ]]; then + timeout ${{ inputs.timeout-seconds }} ${GITHUB_ACTION_PATH}/push.sh + else + ${GITHUB_ACTION_PATH}/push.sh + fi env: GITHUB_EVENT_AFTER: ${{ env.GITHUB_EVENT_AFTER || github.event.after }} GITHUB_EVENT_BEFORE: ${{ env.GITHUB_EVENT_BEFORE || github.event.before }} @@ -279,14 +301,42 @@ runs: shell: bash run: | # Run 'trunk check' on all - ${GITHUB_ACTION_PATH}/all.sh + if [[ "${{ inputs.timeout-seconds }}" != "0" ]]; then + timeout ${{ inputs.timeout-seconds }} ${GITHUB_ACTION_PATH}/all.sh + else + ${GITHUB_ACTION_PATH}/all.sh + fi - name: Run trunk check on Trunk Merge if: env.TRUNK_CHECK_MODE == 'trunk_merge' shell: bash run: | # Run 'trunk check' on Trunk Merge - ${GITHUB_ACTION_PATH}/trunk_merge.sh + if [[ "${{ inputs.timeout-seconds }}" != "0" ]]; then + timeout ${{ inputs.timeout-seconds }} ${GITHUB_ACTION_PATH}/trunk_merge.sh + else + ${GITHUB_ACTION_PATH}/trunk_merge.sh + fi + + - name: Cat Trunk Cli / Daemon logs + if: always() && inputs.cat-trunk-debug-logs == 'true' + shell: bash + run: | + echo "::group::.trunk/logs/cli.log" + if [ -f .trunk/logs/cli.log ]; then + cat .trunk/logs/cli.log + else + echo ".trunk/logs/cli.log doesn't exist" + fi + echo "::endgroup::" + + echo "::group::.trunk/logs/daemon.log" + if [ -f .trunk/logs/daemon.log ]; then + cat .trunk/logs/daemon.log + else + echo ".trunk/logs/daemon.log doesn't exist" + fi + echo "::endgroup::" - name: Run trunk install to populate the GitHub Actions cache if: env.TRUNK_CHECK_MODE == 'populate_cache_only'