documentation/.github/workflows/add-instance-updown.yml
TheFrenchGhosty ea4d456cb4
Add a CI to add instances to updown (#525)
* Add a CI to add instances to updown

* improve adding new instance to updown

---------

Co-authored-by: Emilien Devos <4016501+unixfox@users.noreply.github.com>
2024-04-21 23:49:47 +02:00

149 lines
6.9 KiB
YAML

name: Add instance to uptimerobot
on:
issues:
types: [opened, reopened]
jobs:
replycomment:
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v3
if: contains(github.event.issue.labels.*.name, 'instance-add')
- uses: actions/setup-node@v3
if: contains(github.event.issue.labels.*.name, 'instance-add')
with:
node-version: 16
- run: npm install request linkifyjs updown.io
if: contains(github.event.issue.labels.*.name, 'instance-add')
- uses: actions/github-script@v6
if: contains(github.event.issue.labels.*.name, 'instance-add')
with:
script: |
var issueInfo = (await github.rest.issues.get({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
})).data;
var linkify = require("linkifyjs");
var issueTitleParseUrl = linkify.find(issueInfo.title);
if (issueTitleParseUrl.length !== 0) {
if (issueInfo.title.includes(".onion")) {
var replyComment =
['Hello! I have detected that you are requesting to add an onion URL.',
'Please create a pull request instead for adding your onion url as an alternative to your clearnet URL: https://github.com/iv-org/documentation/edit/master/docs/instances.md'
].join('\n');
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: replyComment
});
await github.rest.issues.update({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed'
});
}
else {
var instanceHostname = (new URL(issueTitleParseUrl[0].href)).hostname;
var request = require("request");
var optionsAddNewCheck = { method: 'POST',
url: 'https://updown.io/api/checks?api-key=${{ secrets.UPDOWN_API_KEY }}',
json:true,
headers:
{ 'content-type': 'application/x-www-form-urlencoded' },
form:
{ url: 'https://' + instanceHostname,
period: '300',
mute_until: 'forever',
published: 'true',
alias: instanceHostname,
string_match: 'An alternative front-end to YouTube' } };
request(optionsAddNewCheck, async function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
if (body.token) {
var optionsGetStatusPages = {
method: 'GET',
url: 'https://updown.io/api/status_pages?api-key=${{ secrets.UPDOWN_API_KEY }}',
json: true
};
request(optionsGetStatusPages, async function (error, response, body) {
if (error) throw new Error(error);
const statusPage = body.filter(element => element.token === "resvf");
let checksOfStatusPage = statusPage[0].checks;
checksOfStatusPage.push(body.token)
var optionsAddCheckToStatusPage = {
method: 'PUT',
url: 'https://updown.io/api/status_pages/resvf?api-key=${{ secrets.UPDOWN_API_KEY }}',
json: true,
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({checks: checksOfStatusPage})
};
request(optionsAddCheckToStatusPage, async function (error, response, body) {
if (error) throw new Error(error);
});
});
var replyComment =
['Hello! Your instance has been added to our monitoring system: https://updown.io/' + body.token,
'You need to wait 30 days before we add your instance, this is to evaluate that your instance will keep a good uptime for one month.',
'',
'Make sure you double checked all the mandatory checks or this will slow down the process of adding your instance!',
'',
'Please consult these two important tutorials:',
'',
'- Escaping the YouTube block ([403 errors in playback](https://github.com/iv-org/invidious/issues/4045)): https://docs.invidious.io/ipv6-rotator/',
'',
'- Improving the performance and the stability of your public instance: https://docs.invidious.io/improve-public-instance/',
'',
'It is highly recommended to follow these tutorials because it will allow the instance to stay stable and performant over the long term.',
'',
'Please consider joining the Matrix room for public instance maintainers by joining our Matrix room: https://matrix.to/#/#invidious:matrix.org',
'then pinging @ unixfox, @ TheFrenchGhosty and @ SamantazFox for asking to be invited to the Matrix room.',
'We discuss troubles managing a public instance, sharing some advices and more.'
].join('\n');
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: replyComment
})
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['wait-30-days']
})
}
});
}
}
else {
var replyComment =
['Domain not detected in the title, please edit the title by correcting it like this:',
'Issue title example: `[New instance] https://myinstance.com`'
].join('\n');
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: replyComment
})
}