forked from planetscale/ghcommit-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.bats
More file actions
101 lines (80 loc) · 3.37 KB
/
entrypoint.bats
File metadata and controls
101 lines (80 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bats
load "${BATS_PLUGIN_PATH}/load.bash"
# uncomment to debug these stubs:
# export GIT_STUB_DEBUG=/dev/tty
# export GHCOMMIT_STUB_DEBUG=/dev/tty
setup() {
export GITHUB_WORKSPACE=/tmp
#export DEBUG=1
}
@test "parses git status output and generates correct flags for ghcommit" {
local commit_message='msg'
local repo='org/repo'
local branch='main'
local empty='false'
local file_pattern='.'
export GITHUB_OUTPUT="$BATS_TEST_TMPDIR/github-output"
# NOTE: we are passing our hand-crafted fixture through `tr` to convert newlines to nulls since
# we run `git status -z` which uses null terminators. The newlines are meant to make the file easier
# to modify and prevent cat from removing the leading space on lines/entries since that is a part
# of the git status output.
stub git \
"config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \
"status -s --porcelain=v1 -z -- . : cat ./tests/fixtures/git-status.out-1 | tr '\n' '\0'"
stub ghcommit \
'-b main -r org/repo -m msg --add=README.md --add=foo.txt --add=new.file --delete=old.file --delete=\""a path with spaces oh joy/file.txt\"" : echo Success. New commit: https://localhost/foo'
run ./entrypoint.sh "$commit_message" "$repo" "$branch" "$empty" "$file_pattern"
assert_success
assert_output --partial "Success"
assert_file_exist "$GITHUB_OUTPUT"
assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/foo"
}
@test "no changes" {
local commit_message='msg'
local repo='org/repo'
local branch='main'
local empty='false'
local file_pattern='.'
stub git \
"config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \
"status -s --porcelain=v1 -z -- . : echo"
run ./entrypoint.sh "$commit_message" "$repo" "$branch" "$empty" "$file_pattern"
assert_success
assert_output --partial "No changes detected"
}
@test "no changes with --empty flag creates empty commit" {
local commit_message='msg'
local repo='org/repo'
local branch='main'
local empty='true'
local file_pattern='.'
export GITHUB_OUTPUT="$BATS_TEST_TMPDIR/github-output"
stub git \
"config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \
"status -s --porcelain=v1 -z -- . : echo"
stub ghcommit \
'-b main -r org/repo -m msg --empty : echo Success. New commit: https://localhost/foo'
run ./entrypoint.sh "$commit_message" "$repo" "$branch" "$empty" "$file_pattern"
assert_success
assert_output --partial "Success"
assert_file_exist "$GITHUB_OUTPUT"
assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/foo"
}
@test "handles untracked files" {
local commit_message='msg'
local repo='org/repo'
local branch='main'
local empty='false'
local file_pattern='.'
export GITHUB_OUTPUT="$BATS_TEST_TMPDIR/github-output"
stub git \
"config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \
"status -s --porcelain=v1 -z -- . : cat ./tests/fixtures/git-status.out-2 | tr '\n' '\0'"
stub ghcommit \
'-b main -r org/repo -m msg --add=untracked.txt --add=new-file.md --add=modified.txt : echo Success. New commit: https://localhost/bar'
run ./entrypoint.sh "$commit_message" "$repo" "$branch" "$empty" "$file_pattern"
assert_success
assert_output --partial "Success"
assert_file_exist "$GITHUB_OUTPUT"
assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/bar"
}