Repository navigation
123 lines (106 loc) · 4.83 KB
/
Copy pathmobsuccess.yml
File metadata and controls
123 lines (106 loc) · 4.83 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# DO NOT EDIT: BEGIN
# This snippet has been inserted automatically by mobsuccessbot, do not edit!
# If changes are needed, update the action mobsuccess in
# https://github.com/mobsuccess-devops/github-mobsuccess-policy
name: Mobsuccess Compliance
on:
merge_group:
types:
- checks_requested
issue_comment:
types:
- created
- edited
pull_request:
types:
- opened
- edited
- synchronize
jobs:
MobsuccessPRCompliance:
name: "Mobsuccess PR Compliance"
runs-on: ubuntu-slim
timeout-minutes: 2
steps:
- uses: mobsuccess-devops/github-actions-mobsuccess@master
with:
github-token: ${{ github.token }}
amplify-uri: ${{ secrets.AWS_AMPLIFY_URI }}${{ vars.AWS_AMPLIFY_URI }}
storybook-amplify-uri: ${{ secrets.AWS_STORYBOOK_AMPLIFY_URI }}${{ vars.AWS_STORYBOOK_AMPLIFY_URI }}
action: "validate-pr"
- name: Checkout
if: github.event_name == 'pull_request'
uses: actions/checkout@v7
with:
fetch-depth: 0
filter: blob:none
- name: Ignored directory replacement
if: github.event_name == 'pull_request'
run: |
set -uo pipefail
fail=0
die() { printf '%s\n' "::error::$(esc "$1")"; exit 1; }
esc() { local s=${1//'%'/%25}; s=${s//$'\r'/%0D}; s=${s//$'\n'/%0A}; printf '%s' "$s"; }
esc_prop() { local s; s=$(esc "$1"); s=${s//:/%3A}; s=${s//,/%2C}; printf '%s' "$s"; }
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
git diff --raw -z --no-renames --diff-filter=AMT "$BASE_SHA...$HEAD_SHA" > "$work/diff" \
|| die "Cannot diff $BASE_SHA...$HEAD_SHA. Refusing to pass without having checked."
git ls-tree -r -z --name-only "$HEAD_SHA" > "$work/tree" \
|| die "Cannot list the tree at $HEAD_SHA. Refusing to pass without having checked."
sandbox="$work/sandbox"
mkdir -p "$sandbox"
git -C "$sandbox" init -q .
: > "$sandbox/.git/info/exclude"
ignored() {
git -c core.excludesFile=/dev/null -C "$sandbox" \
check-ignore -q --no-index -- "$1"
}
while IFS= read -r -d '' gi; do
case "$gi" in .gitignore|*/.gitignore) ;; *) continue ;; esac
mkdir -p "$sandbox/$(dirname "$gi")"
git show "$HEAD_SHA:$gi" > "$sandbox/$gi" \
|| die "Cannot read $gi at $HEAD_SHA. Refusing to pass without having checked."
done < "$work/tree"
while IFS= read -r -d '' meta && IFS= read -r -d '' path; do
mode=$(printf '%s' "$meta" | awk '{print $2}')
case "$mode" in 040000|000000) continue ;; esac
if ! ignored "$path" && ignored "$path/__probe__"; then
kind="file"
if [ "$mode" = "120000" ]; then
t=$(git show "$HEAD_SHA:$path") \
|| die "Cannot read the symlink target of $path at $HEAD_SHA."
kind="symlink -> $t"
fi
printf '%s\n' "::error file=$(esc_prop "$path")::$(esc "Tracking '$path' ($kind) will DELETE the ignored directory of the same name when this is merged or checked out — its contents are gitignored but the path itself is not.")"
fail=1
fi
if [ "$mode" = "120000" ]; then
target=$(git show "$HEAD_SHA:$path") \
|| die "Cannot read the symlink target of $path at $HEAD_SHA."
resolved=$(python3 -c 'import posixpath,sys; print(posixpath.normpath(posixpath.join(posixpath.dirname(sys.argv[1]), sys.argv[2])))' "$path" "$target") \
|| die "Cannot resolve the symlink target of $path."
escape=0
case "$target" in /*) escape=1 ;; esac
case "$resolved" in ..*) escape=1 ;; esac
if [ "$escape" -eq 1 ]; then
printf '%s\n' "::error file=$(esc_prop "$path")::$(esc "Symlink '$path' -> '$target' points outside the repository. Tracked symlinks must stay repo-internal.")"
fail=1
fi
fi
done < "$work/diff"
if [ "$fail" -ne 0 ]; then
echo ""
echo "Remove the offending entry from the commit: git rm --cached <path>"
echo ""
echo "Do NOT 'fix' the .gitignore instead: 'dir/*' plus '!dir/keep' cannot be"
echo "rewritten as a bare 'dir', because git will not re-include anything inside"
echo "an ignored directory. A bare 'dir' is correct only where there is no"
echo "negation to preserve."
exit 1
fi
echo "No ignored-directory replacement detected."
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
# DO NOT EDIT: END