Skip to content
Draft
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
124 changes: 124 additions & 0 deletions gh-actions/github/release/tests/dry-run.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
uses: ./gh-actions/github/release
id: release
with:
dry-run: true
fail-if-exists: true
name: test-package
repository: test/repo
sha: abc123def456
token: fake-token
version: |
{"version": "1.2.3", "next": "1.2.4-dev"}
version-file: /tmp/test-version-dry-run.txt

before:
- shell: bash
run: |
mkdir -p /tmp/test-release-dry-run
echo "1.2.3-dev" > /tmp/test-version-dry-run.txt
rm -f /tmp/gh-mock-dry-run.log
rm -f /tmp/git-mock-dry-run.log
echo "${{ github.workspace }}/gh-actions/github/release/tests/mocks:$PATH" >> $GITHUB_PATH
echo "MOCK_LOG=/tmp/gh-mock-dry-run.log" >> $GITHUB_ENV
echo "MOCK_GIT_LOG=/tmp/git-mock-dry-run.log" >> $GITHUB_ENV
echo "MOCK_RELEASE_EXISTS=false" >> $GITHUB_ENV
echo "✓ Test setup complete"

after:
- shell: bash
run: |
cd /tmp/test-release-dry-run

# Get the output
RELEASE_OUTPUT='${{ steps.release.outputs.result }}'
echo "Release output:"
echo "$RELEASE_OUTPUT"

# Verify output is not empty
if [[ -z "$RELEASE_OUTPUT" ]]; then
echo "✗ Error: Release output is empty"
exit 1
fi
echo "✓ Release output is not empty"

# Parse as JSON array and check contents
OUTPUT_LINES=$(echo "$RELEASE_OUTPUT" | jq -r '.[]')
echo "Output lines:"
echo "$OUTPUT_LINES"

# Check for gh release create command
if ! echo "$OUTPUT_LINES" | grep -q "gh release create"; then
echo "✗ Error: Expected 'gh release create' in output"
exit 1
fi
echo "✓ Found 'gh release create' command in output"

# Check for SKIPPED (dry run)
if ! echo "$OUTPUT_LINES" | grep -q "SKIPPED"; then
echo "✗ Error: Expected 'SKIPPED' in output for dry run"
exit 1
fi
echo "✓ Found 'SKIPPED' markers for dry run"

# Verify gh release view was called
if [[ ! -f /tmp/gh-mock-dry-run.log ]]; then
echo "✗ Error: Mock log file not found"
exit 1
fi

if ! grep -q "gh release view" /tmp/gh-mock-dry-run.log; then
echo "✗ Error: 'gh release view' not found in mock log"
cat /tmp/gh-mock-dry-run.log
exit 1
fi
echo "✓ Mock gh command was called correctly"

# Verify gh release create was NOT called (dry run)
if grep -q "gh release create" /tmp/gh-mock-dry-run.log; then
echo "✗ Error: 'gh release create' should not be called in dry run"
cat /tmp/gh-mock-dry-run.log
exit 1
fi
echo "✓ gh release create was not called (dry run)"

# Verify version file was updated
if [[ ! -f /tmp/test-version-dry-run.txt ]]; then
echo "✗ Error: Version file not found"
exit 1
fi

VERSION_CONTENT=$(cat /tmp/test-version-dry-run.txt)
if [[ "$VERSION_CONTENT" != "1.2.4-dev" ]]; then
echo "✗ Error: Expected version '1.2.4-dev', got '$VERSION_CONTENT'"
exit 1
fi
echo "✓ Version file updated to next dev version"

# Verify git commands were called
if [[ ! -f /tmp/git-mock-dry-run.log ]]; then
echo "✗ Error: Git mock log file not found"
exit 1
fi

if ! grep -q "git commit" /tmp/git-mock-dry-run.log; then
echo "✗ Error: 'git commit' not found in git mock log"
cat /tmp/git-mock-dry-run.log
exit 1
fi
echo "✓ Git commit was called"

# Verify git push was NOT called (dry run)
if grep -q "git push" /tmp/git-mock-dry-run.log; then
echo "✗ Error: 'git push' should not be called in dry run"
cat /tmp/git-mock-dry-run.log
exit 1
fi
echo "✓ Git push was not called (dry run)"

# Cleanup
rm -rf /tmp/test-release-dry-run
rm -f /tmp/test-version-dry-run.txt
rm -f /tmp/gh-mock-dry-run.log
rm -f /tmp/git-mock-dry-run.log

echo "✓ Dry run test passed"
82 changes: 82 additions & 0 deletions gh-actions/github/release/tests/exists-warn.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
uses: ./gh-actions/github/release
id: release
with:
dry-run: false
fail-if-exists: false
name: test-package
repository: test/repo
sha: abc123def456
token: fake-token
version: |
{"version": "1.2.3", "next": "1.2.4-dev"}
version-file: /tmp/test-version-exists-warn.txt

before:
- shell: bash
run: |
mkdir -p /tmp/test-release-exists-warn
echo "1.2.3-dev" > /tmp/test-version-exists-warn.txt
rm -f /tmp/gh-mock-exists-warn.log
rm -f /tmp/git-mock-exists-warn.log
echo "${{ github.workspace }}/gh-actions/github/release/tests/mocks:$PATH" >> $GITHUB_PATH
echo "MOCK_LOG=/tmp/gh-mock-exists-warn.log" >> $GITHUB_ENV
echo "MOCK_GIT_LOG=/tmp/git-mock-exists-warn.log" >> $GITHUB_ENV
echo "MOCK_RELEASE_EXISTS=true" >> $GITHUB_ENV
echo "✓ Test setup complete"

after:
- shell: bash
run: |
cd /tmp/test-release-exists-warn

RELEASE_OUTPUT='${{ steps.release.outputs.result }}'
echo "Release output:"
echo "$RELEASE_OUTPUT"

if [[ -z "$RELEASE_OUTPUT" ]]; then
echo "✗ Error: Release output is empty"
exit 1
fi
echo "✓ Release output is not empty"

OUTPUT_LINES=$(echo "$RELEASE_OUTPUT" | jq -r '.[]')
echo "Output lines:"
echo "$OUTPUT_LINES"

if ! echo "$OUTPUT_LINES" | grep -q "gh release view"; then
echo "✗ Error: Expected 'gh release view' in output"
exit 1
fi
echo "✓ Found 'gh release view' command in output"

if ! echo "$OUTPUT_LINES" | grep -q "already exists, skipping creation"; then
echo "✗ Error: Expected 'already exists, skipping creation' message"
exit 1
fi
echo "✓ Found 'already exists, skipping creation' message"

if [[ ! -f /tmp/gh-mock-exists-warn.log ]]; then
echo "✗ Error: Mock log file not found"
exit 1
fi

if ! grep -q "gh release view" /tmp/gh-mock-exists-warn.log; then
echo "✗ Error: 'gh release view' not found in mock log"
cat /tmp/gh-mock-exists-warn.log
exit 1
fi
echo "✓ Mock gh release view was called"

if grep -q "gh release create" /tmp/gh-mock-exists-warn.log; then
echo "✗ Error: 'gh release create' should not be called when release exists"
cat /tmp/gh-mock-exists-warn.log
exit 1
fi
echo "✓ gh release create was not called"

rm -rf /tmp/test-release-exists-warn
rm -f /tmp/test-version-exists-warn.txt
rm -f /tmp/gh-mock-exists-warn.log
rm -f /tmp/git-mock-exists-warn.log

echo "✓ Release exists with warning test passed"
48 changes: 48 additions & 0 deletions gh-actions/github/release/tests/mocks/gh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# Mock gh command for testing
# Records all calls and responds based on environment variables

set -e

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

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

case "$command" in
release)
case "$subcommand" in
view)
if [[ "${MOCK_RELEASE_EXISTS}" == "true" ]]; then
echo "Release exists"
exit 0
else
echo "Error: release not found" >&2
exit 1
fi
;;
create)
shift 2
tag=""
for arg in "$@"; do
if [[ "$arg" != --* ]]; then
tag="$arg"
break
fi
done
echo "https://github.com/test/repo/releases/tag/${tag}"
exit 0
;;
*)
echo "Unknown release subcommand: $subcommand" >&2
exit 1
;;
esac
;;
*)
echo "Unknown gh command: $command" >&2
exit 1
;;
esac
39 changes: 39 additions & 0 deletions gh-actions/github/release/tests/mocks/git
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

# Mock git command for testing
# Mocks only the commands used by release.sh

MOCK_GIT_LOG="${MOCK_GIT_LOG:-/tmp/git-mock.log}"
echo "git $*" >> "$MOCK_GIT_LOG"

command="${1:-}"

case "$command" in
commit)
shift
message=""
while [[ $# -gt 0 ]]; do
case "$1" in
-m)
message="$2"
shift 2
;;
--signoff)
shift
;;
*)
shift
;;
esac
done
echo "[main $(echo $RANDOM | md5sum | head -c 7)] $message"
echo " 1 file changed, 1 insertion(+), 1 deletion(-)"
;;
push)
echo "To mock-origin"
echo " abc123..def456 main -> main"
;;
*)
exit 0
;;
esac
Loading
Loading