forked from numbata/danger-pr-comment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-workflows.sh
More file actions
executable file
·95 lines (82 loc) · 1.74 KB
/
install-workflows.sh
File metadata and controls
executable file
·95 lines (82 loc) · 1.74 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
#!/usr/bin/env bash
set -euo pipefail
force=0
root=""
usage() {
cat <<'USAGE'
Usage: install-workflows.sh [--root PATH] [--force]
Creates:
.github/workflows/danger.yml
.github/workflows/danger-comment.yml
Options:
--root PATH Target repository root (defaults to git root or current dir)
--force Overwrite existing workflow files
USAGE
}
while [[ $# -gt 0 ]]; do
case "$1" in
--root)
root="$2"
shift 2
;;
--force)
force=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 1
;;
esac
done
if [[ -z "$root" ]]; then
if git_root=$(git rev-parse --show-toplevel 2>/dev/null); then
root="$git_root"
else
root="$PWD"
fi
fi
workflows_dir="$root/.github/workflows"
mkdir -p "$workflows_dir"
write_file() {
local path="$1"
if [[ -e "$path" && "$force" -ne 1 ]]; then
echo "File exists: $path (use --force to overwrite)" >&2
exit 1
fi
cat > "$path"
echo "Wrote $path"
}
write_file "$workflows_dir/danger.yml" <<'EOF'
name: Danger
on:
pull_request:
types: [opened, reopened, edited, synchronize]
jobs:
danger:
uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@v0.1.0
secrets: inherit
with:
ruby-version: '3.4'
bundler-cache: true
EOF
write_file "$workflows_dir/danger-comment.yml" <<'EOF'
name: Danger Comment
on:
workflow_run:
workflows: [Danger]
types: [completed]
permissions:
actions: read # download artifacts
issues: write # list + create/update comments
pull-requests: write # PR comment access
jobs:
comment:
uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@v0.1.0
secrets: inherit
EOF