-
-
Notifications
You must be signed in to change notification settings - Fork 7
175 lines (145 loc) · 5.7 KB
/
dead-domains-check.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
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
166
167
168
169
170
171
172
173
174
175
name: Dead Domains Check
env:
NODE_VERSION: 20
on:
schedule:
# Run the job on every Monday at 8:00 AM UTC
- cron: '0 8 * * 1'
push:
branches:
- master
paths:
- '.github/workflows/dead-domains-check.yml'
workflow_dispatch:
jobs:
dead-domains-check:
name: Run Dead Domains
runs-on: ubuntu-latest
steps:
- name: Check Out Repository
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Setup Perl and Tiny
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: '5.38'
install-modules: |
Path::Tiny
- name: Install Dependencies
run: pnpm install
- name: Export Dead Domains
run: pnpm dead-domains-linter --export dead-domains.txt
- name: Read Dead Domains
id: read-dead-domains
uses: actions/github-script@v7
with:
script: |
const { readFile } = require('fs').promises;
const deadDomains = (await readFile('dead-domains.txt', 'utf8'))
.split(/\r?\n/)
.filter(Boolean);
// Add warning to the console
for (const domain of deadDomains) {
core.warning(`Possible Dead Domain: ${domain}`);
}
core.setOutput('has_dead_domains', deadDomains.length > 0 ? 'true' : 'false');
core.setOutput('dead_domains', deadDomains);
- name: Close Pull Request(s)
uses: actions/github-script@v7
with:
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});
const previousPullRequests = pullRequests.filter(pullRequest => {
const branchName = pullRequest.head.ref;
const isAutomated = branchName.startsWith('feature/dead-domains');
const isBot = pullRequest.user.login === 'github-actions[bot]';
return isAutomated && isBot;
});
for (const previousPullRequest of previousPullRequests) {
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: previousPullRequest.number,
state: 'closed',
});
core.info(`Closed Pull Request #${previousPullRequest.number}`);
}
for (const previousPullRequest of previousPullRequests) {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${previousPullRequest.head.ref}`,
});
core.info(`Deleted Branch ${previousPullRequest.head.ref}`);
}
- name: Create New Branch
if: steps.read-dead-domains.outputs.has_dead_domains == 'true'
id: create-branch
run: |
branch_name="feature/dead-domains"
git checkout -b $branch_name
echo "branch_name=$branch_name" >> $GITHUB_OUTPUT
- name: Perform Changes
if: steps.read-dead-domains.outputs.has_dead_domains == 'true'
run: |
pnpm dead-domains-linter --auto --import dead-domains.txt
- name: Update Checksum and Date
if: steps.read-dead-domains.outputs.has_dead_domains == 'true'
run: |
for i in $(git status |grep modified |awk -F: '{print $NF}' |xargs); do
scripts/checksum-sort.sh $i
done
- name: Stage Changes
if: steps.read-dead-domains.outputs.has_dead_domains == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add "dead-domains.txt" to the .gitignore if it's not there
if ! grep -q "dead-domains.txt" .gitignore; then
echo "dead-domains.txt" >> .gitignore
fi
git add -A
- name: Commit and Push
if: steps.read-dead-domains.outputs.has_dead_domains == 'true'
run: |
git commit -m "Automated Dead Domains Check"
git push --set-upstream origin ${{ steps.create-branch.outputs.branch_name }}
- name: Create Pull Request
if: steps.read-dead-domains.outputs.has_dead_domains == 'true'
uses: actions/github-script@v7
with:
script: |
const { data: pullRequest } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Automated Dead Domains Check',
head: '${{ steps.create-branch.outputs.branch_name }}',
base: context.ref.replace('refs/heads/', ''),
body: [
'This is an automated pull request.',
'',
'Please note that this is an automated check and some low-traffic websites may be incorrectly marked as dead.',
'',
'For more information, see https://github.com/AdguardTeam/DeadDomainsLinter/blob/master/README.md',
].join('\n'),
});
core.info(`Pull Request #${pullRequest.number} Opened`);
// Add labels to the pull request
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequest.number,
labels: ['dead website'],
});