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
12 changes: 6 additions & 6 deletions gh-actions/github/pr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ inputs:
type: string
required: true

append-commit-message:
type: boolean
default: false
committer-name:
type: string
committer-email:
Expand Down Expand Up @@ -49,12 +46,13 @@ inputs:
export PR_DO_COMMIT='\($input.commit)'
export PR_COMMITTER_EMAIL='\($committer_email)'
export PR_COMMITTER_NAME='\($committer_name)'
export PR_COMMIT_MESSAGE=\($commit_message)
export PR_COMMIT_MESSAGE='\($commit_message)'
cd \(.working_directory)
${PR_ACTION_PATH}/create.sh
wip:
type: boolean
default: false
description: Not currently used


runs:
Expand Down Expand Up @@ -82,12 +80,14 @@ runs:
filter: |
. as $input
| .base as $base
| .body as $body
| (.body | sub("\\s+$"; "")) as $body
| .branch as $branch
| (.title | @sh) as $title
| .committer_name as $committer_name
| .committer_email as $committer_email
| ((.commit_message // $input.title) | @sh) as $commit_message
| (((.commit_message // ""
| sub("\\s+$"; ""))
| select(. != "")) // $input.title) as $commit_message
| "${{ inputs.template-create-pr }}"

- name: Upload diff
Expand Down
40 changes: 40 additions & 0 deletions gh-actions/github/pr/tests/commit-message-fallback.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
uses: ./gh-actions/github/pr
id: pr
with:
base: main
branch: ${{ env.TEST_BRANCH }}
title: ${{ env.TEST_TITLE }}
body: ${{ env.TEST_BODY }}
commit: true
committer-name: ${{ env.TEST_COMMITTER_NAME }}
committer-email: ${{ env.TEST_COMMITTER_EMAIL }}
GITHUB_TOKEN: "VERYSECRET"

before:
- shell: bash
env:
TEST_BODY: This PR tests commit functionality
TEST_BRANCH: test/pr-action-commit
TEST_COMMIT_MESSAGE: Test PR with commit
TEST_COMMITTER_EMAIL: bot@example.com
TEST_COMMITTER_NAME: PR Bot
MOCK_LOG: /tmp/mock.log
TEST_TITLE: Test PR with commit
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
rm -f ${MOCK_LOG}
echo "${{ github.workspace }}/gh-actions/github/pr/tests/mocks:$PATH" >> $GITHUB_PATH
echo "MOCK_LOG=${MOCK_LOG}" >> $GITHUB_ENV
setup_test

after:
- shell: bash
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
test_output_log \
"${TEST_COMMITTER_NAME}" \
"${TEST_COMMITTER_EMAIL}" \
"${TEST_COMMIT_MESSAGE}" \
"${TEST_BRANCH}" \
"${TEST_TITLE}" \
"${TEST_BODY}"
42 changes: 42 additions & 0 deletions gh-actions/github/pr/tests/commit.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
uses: ./gh-actions/github/pr
id: pr
with:
base: main
branch: ${{ env.TEST_BRANCH }}
title: ${{ env.TEST_TITLE }}
body: ${{ env.TEST_BODY }}
commit: true
committer-name: ${{ env.TEST_COMMITTER_NAME }}
committer-email: ${{ env.TEST_COMMITTER_EMAIL }}
commit-message: ${{ env.TEST_COMMIT_MESSAGE }}
GITHUB_TOKEN: "VERYSECRET"

before:
- shell: bash
env:
TEST_BODY: This PR tests commit functionality
TEST_BRANCH: test/pr-action-commit
TEST_COMMIT_MESSAGE: >-
chore: Test commit from action
TEST_COMMITTER_EMAIL: bot@example.com
TEST_COMMITTER_NAME: PR Bot
MOCK_LOG: /tmp/mock.log
TEST_TITLE: Test PR with commit
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
rm -f ${MOCK_LOG}
echo "${{ github.workspace }}/gh-actions/github/pr/tests/mocks:$PATH" >> $GITHUB_PATH
echo "MOCK_LOG=${MOCK_LOG}" >> $GITHUB_ENV
setup_test

after:
- shell: bash
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
test_output_log \
"${TEST_COMMITTER_NAME}" \
"${TEST_COMMITTER_EMAIL}" \
"${TEST_COMMIT_MESSAGE}" \
"${TEST_BRANCH}" \
"${TEST_TITLE}" \
"${TEST_BODY}"
43 changes: 43 additions & 0 deletions gh-actions/github/pr/tests/dry-run.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
uses: ./gh-actions/github/pr
id: pr
with:
base: main
branch: ${{ env.TEST_BRANCH }}
title: ${{ env.TEST_TITLE }}
body: ${{ env.TEST_BODY }}
commit: true
committer-name: ${{ env.TEST_COMMITTER_NAME }}
committer-email: ${{ env.TEST_COMMITTER_EMAIL }}
commit-message: ${{ env.TEST_COMMIT_MESSAGE }}
dry-run: true
GITHUB_TOKEN: "VERYSECRET"

before:
- shell: bash
env:
TEST_BODY: This PR tests dry-run functionality
TEST_BRANCH: test/pr-action-dry-run
TEST_COMMIT_MESSAGE: >-
chore: Test dry-run commit from action
TEST_COMMITTER_EMAIL: dry-run-bot@example.com
TEST_COMMITTER_NAME: PR dry-run bot
MOCK_LOG: /tmp/mock.log
TEST_TITLE: Test PR with dry-run
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
rm -f ${MOCK_LOG}
echo "${{ github.workspace }}/gh-actions/github/pr/tests/mocks:$PATH" >> $GITHUB_PATH
echo "MOCK_LOG=${MOCK_LOG}" >> $GITHUB_ENV
setup_test

after:
- shell: bash
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
test_dryrun_output_log \
"${TEST_COMMITTER_NAME}" \
"${TEST_COMMITTER_EMAIL}" \
"${TEST_COMMIT_MESSAGE}" \
"${TEST_BRANCH}" \
"${TEST_TITLE}" \
"${TEST_BODY}"
45 changes: 45 additions & 0 deletions gh-actions/github/pr/tests/mocks/gh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

# Mock gh command for testing github/pr action
# Records all calls and responds based on environment variables

set -e

MOCK_LOG="${MOCK_LOG:-/tmp/gh-mock.log}"

print_cmd() {
local arg
for arg in "$@"; do
if [[ "$arg" =~ [[:space:]] ]]; then
printf '"%s" ' "$arg"
else
printf '%s ' "$arg"
fi
done | sed 's/ $//'
echo
}

print_cmd gh "$@" >> "$MOCK_LOG"

command="$1"
subcommand="${2:-}"

case "$command" in
pr)
case "$subcommand" in
create)
# Mock PR creation - return fake URL
echo "https://github.com/envoyproxy/test/pull/12345"
exit 0
;;
*)
echo "Unknown pr subcommand: $subcommand" >&2
exit 1
;;
esac
;;
*)
echo "Unknown gh command: $command" >&2
exit 1
;;
esac
57 changes: 57 additions & 0 deletions gh-actions/github/pr/tests/mocks/git
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

# Mock git command for testing github/pr action
# Only mocks commands used by create.sh - does NOT call real git

MOCK_LOG="${MOCK_LOG:-/tmp/git-mock.log}"

print_cmd() {
local arg
for arg in "$@"; do
if [[ "$arg" =~ [[:space:]] ]]; then
printf '"%s" ' "$arg"
else
printf '%s ' "$arg"
fi
done | sed 's/ $//'
echo
}

print_cmd git "$@" >> "$MOCK_LOG"

command="${1:-}"

case "$command" in
log)
# Mock git log for getting signoff
echo "Mock commit

Signed-off-by: Mock User <mock@example.com>"
exit 0
;;
checkout)
# Mock git checkout -b (branch creation)
echo "Switched to a new branch '$3'"
exit 0
;;
config)
# Mock git config (does nothing, just succeeds)
exit 0
;;
commit)
# Mock git commit
echo "[main abc1234] $*"
echo " 1 file changed, 1 insertion(+)"
exit 0
;;
push)
# Mock push - don't actually push
echo "To mock-origin"
echo " abc123..def456 HEAD -> ${MOCK_BRANCH:-test-branch}"
exit 0
;;
*)
# For any other git command, just succeed silently
exit 0
;;
esac
42 changes: 42 additions & 0 deletions gh-actions/github/pr/tests/no-commit.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
uses: ./gh-actions/github/pr
id: pr
with:
base: main
branch: ${{ env.TEST_BRANCH }}
title: ${{ env.TEST_TITLE }}
body: ${{ env.TEST_BODY }}
commit: false
committer-name: ${{ env.TEST_COMMITTER_NAME }}
committer-email: ${{ env.TEST_COMMITTER_EMAIL }}
commit-message: ${{ env.TEST_COMMIT_MESSAGE }}
GITHUB_TOKEN: "VERYSECRET"

before:
- shell: bash
env:
TEST_BODY: This PR tests no commit functionality
TEST_BRANCH: test/pr-action-no-commit
TEST_COMMIT_MESSAGE: >-
chore: Test no-commit from action
TEST_COMMITTER_EMAIL: no-commit-bot@example.com
TEST_COMMITTER_NAME: PR no-commit Bot
MOCK_LOG: /tmp/mock.log
TEST_TITLE: Test PR without commit
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
rm -f ${MOCK_LOG}
echo "${{ github.workspace }}/gh-actions/github/pr/tests/mocks:$PATH" >> $GITHUB_PATH
echo "MOCK_LOG=${MOCK_LOG}" >> $GITHUB_ENV
setup_test

after:
- shell: bash
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
test_nocommit_output_log \
"${TEST_COMMITTER_NAME}" \
"${TEST_COMMITTER_EMAIL}" \
"${TEST_COMMIT_MESSAGE}" \
"${TEST_BRANCH}" \
"${TEST_TITLE}" \
"${TEST_BODY}"
51 changes: 51 additions & 0 deletions gh-actions/github/pr/tests/special-characters.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
uses: ./gh-actions/github/pr
id: pr
with:
base: main
branch: ${{ env.TEST_BRANCH }}
title: ${{ env.TEST_TITLE }}
body: |
${{ env.TEST_BODY }}
commit: true
committer-name: ${{ env.TEST_COMMITTER_NAME }}
committer-email: ${{ env.TEST_COMMITTER_EMAIL }}
commit-message: |
${{ env.TEST_COMMIT_MESSAGE }}
GITHUB_TOKEN: "VERYSECRET"

before:
- shell: bash
env:
# - Single quotes: 'test' (NOT WORKING)
TEST_BODY: |
☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠
This tests special characters:
- Double quotes: "test"
- Variables: $PATH
- Backticks: `command`
☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠☠
TEST_BRANCH: test/pr-action-special-chars-commit
TEST_COMMIT_MESSAGE: >-
chore: Test commit from action
TEST_COMMITTER_EMAIL: special-chars-bot@example.com
TEST_COMMITTER_NAME: PR special chars Bot
MOCK_LOG: /tmp/mock.log
TEST_TITLE: Test PR with special chars
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
rm -f ${MOCK_LOG}
echo "${{ github.workspace }}/gh-actions/github/pr/tests/mocks:$PATH" >> $GITHUB_PATH
echo "MOCK_LOG=${MOCK_LOG}" >> $GITHUB_ENV
setup_test

after:
- shell: bash
run: |
. "${ACTION_TEST_PATH}/test_fun.sh"
test_output_log \
"${TEST_COMMITTER_NAME}" \
"${TEST_COMMITTER_EMAIL}" \
"${TEST_COMMIT_MESSAGE}" \
"${TEST_BRANCH}" \
"${TEST_TITLE}" \
"${TEST_BODY}"
Loading