forked from scala-steward-org/repos
-
Notifications
You must be signed in to change notification settings - Fork 148
123 lines (116 loc) · 4.77 KB
/
validation.yml
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
name: Repos Validation
on:
pull_request_target:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout fork
uses: actions/checkout@v2
with:
repo: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
- name: copy fork repos-*.md
run: |
mkdir -p /tmp/fork
cp repos*.md /tmp/fork
- name: checkout origin
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.sha }}
- name: copy origin repos-*.md
run: |
mkdir -p /tmp/origin
cp repos*.md /tmp/origin
- id: calc_diff
name: diff
run: |
LINKS=""
GITHUB_CHANGES=$(git diff --unified=0 --output-indicator-new=# --output-indicator-old=# /tmp/fork/repos-github.md /tmp/origin/repos-github.md || echo "")
if [[ $? -ne 0 ]]; then
echo "git error!"
exit 1;
fi
if [[ "$GITHUB_CHANGES" ]]; then
GITHUB_CHANGES=$(echo "$GITHUB_CHANGES" | grep '^#' | sed 's/#- //' | uniq)
while IFS= read -r owner_repo; do
if [[ $owner_repo == ${{ github.actor }}/* ]]; then
VALIDATION="✅"
else
owner=$(curl --silent \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Referer: https://github.com" \
https://api.github.com/repos/$owner_repo | jq ".owner"
)
if [[ $(echo $owner | jq --raw-output ".type") == 'Organization' ]]; then
org=$(echo $owner | jq --raw-output ".login")
org_admins=$(curl --silent \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Referer: https://github.com" \
https://api.github.com/orgs/$org/members?role=admin | jq --raw-output ".[].login"
)
if echo "$org_admins" | grep '^${{ github.actor}}$'; then
VALIDATION="✅"
else
VALIDATION="❔"
fi
else
VALIDATION="❔"
fi
fi
LINKS+=$'\n'"$VALIDATION [$owner_repo](https://github.com/$owner_repo)"
done <<< "$GITHUB_CHANGES"
fi
GITLAB_CHANGES=$(git diff --unified=0 --output-indicator-new=# --output-indicator-old=# /tmp/fork/repos-gitlab.md /tmp/origin/repos-gitlab.md || echo "")
if [[ "$GITLAB_CHANGES" ]]; then
GITLAB_CHANGES=$(echo "$GITLAB_CHANGES" | grep '^#' | sed 's/#- //' | uniq)
while IFS= read -r owner_repo; do
if [[ $owner_repo == ${{ github.actor }}/* ]]; then
VALIDATION="✅"
else
VALIDATION="❔"
fi
LINKS+=$'\n'"$VALIDATION [$owner_repo](https://gitlab.com/$owner_repo)"
done <<< "$GITLAB_CHANGES"
fi
BITBUCKET_CHANGES=$(git diff --unified=0 --output-indicator-new=# --output-indicator-old=# /tmp/fork/repos-bitbucket.md /tmp/origin/repos-bitbucket.md || echo "")
if [[ "$BITBUCKET_CHANGES" ]]; then
BITBUCKET_CHANGES=$(echo "$BITBUCKET_CHANGES" | grep '^#' | sed 's/#- //' | uniq)
while IFS= read -r owner_repo; do
if [[ $owner_repo == ${{ github.actor }}/* ]]; then
VALIDATION="✅"
else
VALIDATION="❔"
fi
LINKS+=$'\n'"$VALIDATION [$owner_repo](https://bitbucket.org/$owner_repo)"
done <<< "$BITBUCKET_CHANGES"
fi
echo "$LINKS"
LINKS="${LINKS//'%'/'%25'}"
LINKS="${LINKS//$'\n'/'%0A'}"
LINKS="${LINKS//$'\r'/'%0D'}"
echo "::set-output name=LINKS::${LINKS}"
- name: found diff
id: non-empty
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ steps.calc_diff.outputs.LINKS }}
with:
github_token: ${{ secrets.github_token }}
message: |
Changed repositories:
${{ steps.calc_diff.outputs.LINKS }}
Legends:
✅=Actor is a repo owner or an organization admin.
❔=Unable to validate. Requires manual validation.
- name: no updates
id: no-updates
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ steps.calc_diff.outputs.LINKS == '' }}
with:
github_token: ${{ secrets.github_token }}
message: |
No changes found on repos.