Repository navigation
165 lines (159 loc) · 7.31 KB
/
Copy pathremove-entry.yml
File metadata and controls
165 lines (159 loc) · 7.31 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Removes applications from the catalog completely (data/NAME, database/NAME/,
# apps/NAME.md) with code/remove-entry.sh, in three ways:
# - a maintainer comments "/remove" on an issue about an entry (the
# "Where did the AppImage of NAME go?" issues of ping-authors.yml);
# the issue is closed afterwards
# - a push to master deletes or renames a file in data/: its database/ and
# apps/ entries are removed too (deleting only data/NAME left the page)
# - by hand: Actions tab -> "Remove entry" -> names separated by blanks
# - a maintainer comments "/remove" on a pull request (job remove-pr): the PR
# is closed and labeled opt-out (never proposed again by discover-apps.sh),
# and the entries it adds or changes are removed if they are in the catalog
name: Remove entry
on:
issue_comment:
types: [created]
push:
branches:
- master
paths:
- 'data/**'
workflow_dispatch:
inputs:
names:
description: 'Names of the entries in data/ to remove, separated by blanks'
required: true
concurrency:
group: remove-entry
cancel-in-progress: false
jobs:
remove:
if: >-
github.repository == 'AppImage/appimage.github.io' && (
github.event_name != 'issue_comment' || (
!github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/remove') &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)))
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
EVENT: ${{ github.event_name }}
ISSUE: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
INPUT_NAMES: ${{ inputs.names }}
BEFORE: ${{ github.event.before }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Remove
run: |
case "$EVENT" in
issue_comment)
# The entry is named in the issue title (never taken from the comment)
NAME=$(echo "$ISSUE_TITLE" | sed -n 's/^Where did the AppImage of \([A-Za-z0-9._+-]*\) go?$/\1/p')
if [ -z "$NAME" ] ; then
gh issue comment "$ISSUE" -R "$REPO" --body "Could not tell which entry to remove: \`/remove\` works on issues titled \"Where did the AppImage of NAME go?\". Remove other entries from the Actions tab (\"Remove entry\")."
exit 1
fi
NAMES="$NAME"
REASON="as discussed in #$ISSUE"
;;
push)
# Entries whose file in data/ this push deleted or renamed away
git cat-file -e "$BEFORE" 2>/dev/null || BEFORE=HEAD~1
NAMES=$(git diff --name-status --diff-filter=DR "$BEFORE" HEAD -- data/ | awk '{ print $2 }' | sed 's|^data/||')
# Only what is left of them in database/ and apps/
NAMES=$(for N in $NAMES ; do
if [ ! -e "data/$N" ] && { [ -e "database/$N" ] || [ -e "apps/$N.md" ] ; } ; then echo "$N" ; fi
done)
[ -n "$NAMES" ] || { echo "Nothing left over from removed entries" ; exit 0 ; }
REASON="its file in data/ was removed"
;;
workflow_dispatch)
NAMES="$INPUT_NAMES"
REASON="removed by hand from the Actions tab"
;;
esac
# shellcheck disable=SC2086 # names are validated by the script
RC=0
bash code/remove-entry.sh $NAMES || RC=1 # e.g. a mistyped name; remove the others anyway
git diff --cached --quiet && { echo "Nothing to remove" ; exit $RC ; }
git config user.name "GitHub Actions"
git config user.email "actions@users.noreply.github.com"
git commit -q -m "Remove $(echo $NAMES | tr ' ' ',' | sed 's/,/, /g') from the catalog" -m "$REASON"
PUSHED=false
for TRY in 1 2 3 4 5 ; do
git push -q origin HEAD:master && { PUSHED=true ; break ; }
sleep $((TRY * 5))
git pull -q --rebase origin master
done
$PUSHED || { echo "Could not push the removal" ; exit 1 ; }
if [ "$EVENT" = issue_comment ] ; then
gh issue close "$ISSUE" -R "$REPO" --reason completed \
--comment "Removed \`data/$NAMES\` and its page from the catalog ($(git rev-parse --short HEAD)). Thank you!"
fi
exit $RC
remove-pr:
if: >-
github.repository == 'AppImage/appimage.github.io' &&
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/remove') &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
PR: ${{ github.event.issue.number }}
COMMENT_ID: ${{ github.event.comment.id }}
COMMENTER: ${{ github.event.comment.user.login }}
steps:
# master, never the PR: its files are only read as names via the API
- uses: actions/checkout@v4
with:
ref: master
- name: Remove
run: |
gh api -X POST "repos/$REPO/issues/comments/$COMMENT_ID/reactions" -f content=eyes >/dev/null || true
# The entries this PR adds or changes (plain names only)
NAMES=$(gh api --paginate "repos/$REPO/pulls/$PR/files" \
--jq '.[] | select(.filename | startswith("data/")) | .filename' \
| sed -n 's|^data/\([A-Za-z0-9_+-][A-Za-z0-9._+-]*\)$|\1|p' | sort -u)
# Only those that are in the catalog are removed from it
IN_CATALOG=()
for N in $NAMES ; do
if [ -e "data/$N" ] || [ -e "database/$N" ] || [ -e "apps/$N.md" ] ; then IN_CATALOG+=("$N") ; fi
done
MSG=""
if [ ${#IN_CATALOG[@]} -gt 0 ] ; then
bash code/remove-entry.sh "${IN_CATALOG[@]}"
git config user.name "GitHub Actions"
git config user.email "actions@users.noreply.github.com"
git commit -q -m "Remove ${IN_CATALOG[*]} from the catalog" -m "Requested with /remove in #$PR by @$COMMENTER"
PUSHED=false
for TRY in 1 2 3 4 5 ; do
git push -q origin HEAD:master && { PUSHED=true ; break ; }
sleep $((TRY * 5))
git pull -q --rebase origin master
done
$PUSHED || { echo "Could not push the removal" ; exit 1 ; }
MSG="Removed \`${IN_CATALOG[*]}\` and its page from the catalog ($(git rev-parse --short HEAD)). "
fi
# Never proposed again by discover-apps.sh
gh api -X POST "repos/$REPO/issues/$PR/labels" -f "labels[]=opt-out" >/dev/null || true
MSG="${MSG}Labeled \`opt-out\`: auto-discovery will not propose this app again."
if [ "$(gh api "repos/$REPO/pulls/$PR" --jq .state)" = open ] ; then
gh pr close "$PR" -R "$REPO" --comment "$MSG"
else
gh pr comment "$PR" -R "$REPO" --body "$MSG"
fi
gh api -X POST "repos/$REPO/issues/comments/$COMMENT_ID/reactions" -f content=rocket >/dev/null || true