Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/action_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,49 @@ jobs:
npm install
./action_tests/assert.js all-hold-the-line-no-upload-id

pull_request_expect_trunk_check_timeout:
Copy link
Contributor Author

@Ryang20718 Ryang20718 May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not tested (since I can't run CI). Let me know if I should add a test elsewhere!

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:
Expand Down
58 changes: 54 additions & 4 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down Expand Up @@ -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 }}

Expand All @@ -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 }}
Expand All @@ -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'
Expand Down