|
5 | 5 | name: Mobsuccess Compliance |
6 | 6 |
|
7 | 7 | on: |
| 8 | + merge_group: |
| 9 | + types: |
| 10 | + - checks_requested |
| 11 | + |
| 12 | + issue_comment: |
| 13 | + types: |
| 14 | + - created |
| 15 | + - edited |
| 16 | + |
8 | 17 | pull_request: |
9 | 18 | types: |
10 | 19 | - opened |
|
14 | 23 | jobs: |
15 | 24 | MobsuccessPRCompliance: |
16 | 25 | name: "Mobsuccess PR Compliance" |
17 | | - runs-on: ubuntu-20.04 |
| 26 | + runs-on: ubuntu-slim |
18 | 27 | timeout-minutes: 2 |
19 | 28 | steps: |
20 | 29 | - uses: mobsuccess-devops/github-actions-mobsuccess@master |
21 | 30 | with: |
22 | 31 | github-token: ${{ github.token }} |
23 | | - amplify-uri: ${{ secrets.AWS_AMPLIFY_URI }} |
24 | | - storybook-amplify-uri: ${{ secrets.AWS_STORYBOOK_AMPLIFY_URI }} |
| 32 | + amplify-uri: ${{ secrets.AWS_AMPLIFY_URI }}${{ vars.AWS_AMPLIFY_URI }} |
| 33 | + storybook-amplify-uri: ${{ secrets.AWS_STORYBOOK_AMPLIFY_URI }}${{ vars.AWS_STORYBOOK_AMPLIFY_URI }} |
25 | 34 | action: "validate-pr" |
| 35 | + |
| 36 | + - name: Checkout |
| 37 | + if: github.event_name == 'pull_request' |
| 38 | + uses: actions/checkout@v7 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + filter: blob:none |
| 42 | + |
| 43 | + - name: Ignored directory replacement |
| 44 | + if: github.event_name == 'pull_request' |
| 45 | + run: | |
| 46 | + set -uo pipefail |
| 47 | + fail=0 |
| 48 | +
|
| 49 | + die() { printf '%s\n' "::error::$(esc "$1")"; exit 1; } |
| 50 | +
|
| 51 | + esc() { local s=${1//'%'/%25}; s=${s//$'\r'/%0D}; s=${s//$'\n'/%0A}; printf '%s' "$s"; } |
| 52 | + esc_prop() { local s; s=$(esc "$1"); s=${s//:/%3A}; s=${s//,/%2C}; printf '%s' "$s"; } |
| 53 | +
|
| 54 | + work=$(mktemp -d) |
| 55 | + trap 'rm -rf "$work"' EXIT |
| 56 | +
|
| 57 | + git diff --raw -z --no-renames --diff-filter=AMT "$BASE_SHA...$HEAD_SHA" > "$work/diff" \ |
| 58 | + || die "Cannot diff $BASE_SHA...$HEAD_SHA. Refusing to pass without having checked." |
| 59 | + git ls-tree -r -z --name-only "$HEAD_SHA" > "$work/tree" \ |
| 60 | + || die "Cannot list the tree at $HEAD_SHA. Refusing to pass without having checked." |
| 61 | +
|
| 62 | + sandbox="$work/sandbox" |
| 63 | + mkdir -p "$sandbox" |
| 64 | + git -C "$sandbox" init -q . |
| 65 | +
|
| 66 | + : > "$sandbox/.git/info/exclude" |
| 67 | + ignored() { |
| 68 | + git -c core.excludesFile=/dev/null -C "$sandbox" \ |
| 69 | + check-ignore -q --no-index -- "$1" |
| 70 | + } |
| 71 | +
|
| 72 | + while IFS= read -r -d '' gi; do |
| 73 | + case "$gi" in .gitignore|*/.gitignore) ;; *) continue ;; esac |
| 74 | + mkdir -p "$sandbox/$(dirname "$gi")" |
| 75 | + git show "$HEAD_SHA:$gi" > "$sandbox/$gi" \ |
| 76 | + || die "Cannot read $gi at $HEAD_SHA. Refusing to pass without having checked." |
| 77 | + done < "$work/tree" |
| 78 | +
|
| 79 | + while IFS= read -r -d '' meta && IFS= read -r -d '' path; do |
| 80 | + mode=$(printf '%s' "$meta" | awk '{print $2}') |
| 81 | + case "$mode" in 040000|000000) continue ;; esac |
| 82 | +
|
| 83 | + if ! ignored "$path" && ignored "$path/__probe__"; then |
| 84 | + kind="file" |
| 85 | + if [ "$mode" = "120000" ]; then |
| 86 | + t=$(git show "$HEAD_SHA:$path") \ |
| 87 | + || die "Cannot read the symlink target of $path at $HEAD_SHA." |
| 88 | + kind="symlink -> $t" |
| 89 | + fi |
| 90 | + 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.")" |
| 91 | + fail=1 |
| 92 | + fi |
| 93 | +
|
| 94 | + if [ "$mode" = "120000" ]; then |
| 95 | + target=$(git show "$HEAD_SHA:$path") \ |
| 96 | + || die "Cannot read the symlink target of $path at $HEAD_SHA." |
| 97 | + resolved=$(python3 -c 'import posixpath,sys; print(posixpath.normpath(posixpath.join(posixpath.dirname(sys.argv[1]), sys.argv[2])))' "$path" "$target") \ |
| 98 | + || die "Cannot resolve the symlink target of $path." |
| 99 | + escape=0 |
| 100 | + case "$target" in /*) escape=1 ;; esac |
| 101 | + case "$resolved" in ..*) escape=1 ;; esac |
| 102 | + if [ "$escape" -eq 1 ]; then |
| 103 | + printf '%s\n' "::error file=$(esc_prop "$path")::$(esc "Symlink '$path' -> '$target' points outside the repository. Tracked symlinks must stay repo-internal.")" |
| 104 | + fail=1 |
| 105 | + fi |
| 106 | + fi |
| 107 | + done < "$work/diff" |
| 108 | +
|
| 109 | + if [ "$fail" -ne 0 ]; then |
| 110 | + echo "" |
| 111 | + echo "Remove the offending entry from the commit: git rm --cached <path>" |
| 112 | + echo "" |
| 113 | + echo "Do NOT 'fix' the .gitignore instead: 'dir/*' plus '!dir/keep' cannot be" |
| 114 | + echo "rewritten as a bare 'dir', because git will not re-include anything inside" |
| 115 | + echo "an ignored directory. A bare 'dir' is correct only where there is no" |
| 116 | + echo "negation to preserve." |
| 117 | + exit 1 |
| 118 | + fi |
| 119 | + echo "No ignored-directory replacement detected." |
| 120 | + env: |
| 121 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 122 | + HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
26 | 123 | # DO NOT EDIT: END |
0 commit comments