Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
phifogg committed Aug 6, 2023
2 parents 56861c0 + 8d27eb9 commit 11fbb1a
Show file tree
Hide file tree
Showing 15 changed files with 1,352 additions and 258 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: Check changed adapters

#
# WARNING:
# ** Do NOT run untrusted code when using pull_request_target **
# pull_request_target is needed as pull_request does not provide secrets and so no
# commenting of PR is possible.
#
on:
pull_request:
pull_request_target:
types: [opened, edited, ready_for_review, reopened]
issue_comment:
types: [created]
Expand All @@ -18,10 +24,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm i
- run: npm run check
env:
OWN_GITHUB_TOKEN: ${{ secrets.OWN_GITHUB_TOKEN }}
OWN_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REF: ${{ env.GITHUB_REF }}
GITHUB_EVENT_PATH: ${{ env.GITHUB_EVENT_PATH }}
20 changes: 20 additions & 0 deletions .github/workflows/checkArchived.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check archived repostories

on:
schedule:
# * is a special character in YAML, so you have to quote this string
# every sunday at 3:33
- cron: '33 3 * * 0'

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm i
- run: npm run checkArchived
env:
OWN_GITHUB_TOKEN: ${{ secrets.OWN_GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/checkNpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check npm access

on:
schedule:
# * is a special character in YAML, so you have to quote this string
# daily at 2:2
- cron: '22 2 * * *'

jobs:
check-npms:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm i
- run: npm run checkNpm
env:
OWN_GITHUB_TOKEN: ${{ secrets.OWN_GITHUB_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Automatically merge Dependabot PRs when version comparison is within the range
# that is configured in .github/auto-merge.yml

name: Auto-Merge Dependabot PRs

on:
# WARNING: This needs to be run in the PR base, DO NOT build untrusted code in this action
# details under https://github.blog/changelog/2021-02-19-github-actions-workflows-triggered-by-dependabot-prs-will-run-with-read-only-permissions/
pull_request_target:

jobs:
auto-merge:
if: github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Check if PR should be auto-merged
uses: ahmadnassri/action-dependabot-auto-merge@v2
with:
# In order to use this, you need to go to https://github.com/settings/tokens and
# create a Personal Access Token with the permission "public_repo".
# Enter this token in your repository settings under "Secrets" and name it AUTO_MERGE_TOKEN
github-token: ${{ secrets.AUTO_MERGE_TOKEN }}
# By default, squash and merge, so Github chooses nice commit messages
command: squash and merge
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: Check stable versions
name: Check ready for stable

on:
schedule:
# * is a special character in YAML, so you have to quote this string
# every day
- cron: '15 3 * * *'
- cron: '33 3 * * *'

jobs:
check:
ready-for-stable:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm i
- run: npm run stable
env:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/setLabels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will triage pull requests and apply a label based on the
# paths that are modified in the pull request.

name: Set labels

#
# WARNING:
# ** Do NOT run untrusted code when using pull_request_target **
# pull_request_target is needed as pull_request does not provide secrets and so no
# labeling of PR is possible.
#
on:
pull_request_target:
types: [opened, edited, ready_for_review, reopened, labeled, unlabeled]
issue_comment:
types: [created, edited]

jobs:
setLabels:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm i
- run: npm run setLabels
env:
OWN_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89 changes: 48 additions & 41 deletions README.md

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions lib/checkArchived.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
'use strict';

/*
*
* This script scans all adapters listed at latest and stable repository and varifies that
* - all adapters listed at stabel repository are also listed at latest repository
* - github adapter repositories are accessible
* - github adapter repositories are not archived
*
* If any of those checks fails an issue is created at ioBroker.repositories requesting a fix
*
* Note:
* Running this script locally requires environmant variable OWN_GITHUB_TOKEN to be set to avoid hitting rate limits
*
*/

const {
getGithub,
getUrl,
createIssue
} = require('./common');

async function getLatestRepo() {
return await getUrl('http://repo.iobroker.live/sources-dist-latest.json');
}

async function getStableRepo() {
return await getUrl('http://repo.iobroker.live/sources-dist.json');
}

async function getStats() {
return await getUrl('https://www.iobroker.net/data/statistics.json');
}

async function checkRepos(latest, stable, stats) {
const result = [];
let count;
let idx;

count = Object.keys(stable).length;
idx=0;
console.log ('');
console.log ('processing STABLE repository');
for (const adapter in stable) {
idx = idx + 1;
if (adapter.startsWith('_')) {
console.log (`SKIPPING ${adapter} (${idx}/${count})`);
} else {
const parts = stable[adapter].meta.split('/');
const owner = parts[3];
console.log (`checking ${adapter} (${idx}/${count})`);
if (!latest[adapter]) {
console.log(` *** ${adapter} only in stable repository`);
const item = {
adapter: adapter,
owner: owner,
installs: stats.adapters[adapter],
stable_only: true,
};
console.log (` *** ${adapter} only at stable repository (${stats.adapters[adapter]} installs)`);
result.push(item);
}
}
}

count = Object.keys(latest).length;
idx = 0;
console.log ('');
console.log ('processing LATEST repository');
for (const adapter in latest) {
idx = idx + 1;
if (adapter.startsWith('_')) {
console.log (`SKIPPING ${adapter} (${idx}/${count})`);
} else {
const parts = latest[adapter].meta.split('/');
const owner = parts[3];
console.log (`checking ${adapter} (${idx}/${count}) - ${owner}/ioBroker.${adapter}`);

try {
const json = await getGithub(`https://api.github.com/repos/${owner}/ioBroker.${adapter}`);
if (json.archived) {
const item = {
adapter: adapter,
owner: owner,
installs: stats.adapters[adapter],
archived: true,
};
console.log (` *** ${adapter} is archived (${stats.adapters[adapter]} installs)`);
result.push(item);
}
} catch (e) {
console.log (` *** error retrieving infos for ${adapter}`);
console.log (` *** ${e}`);
const item = {
adapter: adapter,
owner: owner,
installs: stats.adapters[adapter],
error: true,
e: e,
};
result.push(item);
}
}
};
return result;
}

async function generateIssue(adapter, stableFile) {
let issues;
issues = await getGithub(`https://api.github.com/repos/ioBroker/ioBroker.repositories/issues`);

const title = `[CHECK] Adapter ${adapter.adapter} needs verification`;
issues = issues.filter(i => i.state === 'open' && i.title.includes(title));
if (!issues.length) {
let body = `# Adapter ${adapter.adapter} needs verification:\n\n`;
if ( adapter.stable_only) {
body += `Adapter is listed at stable repository only\n`;
};
if ( adapter.archived) {
body += `Repository ${adapter.owner}/ioBroker.${adapter.adapter} is archived\n`;
};
if ( adapter.error) {
body += `Retrieving data from repository ${adapter.owner}/ioBroker.${adapter.adapter} failed\n`;
body += `${e}\n`;
};
body += '\n';
body += `Adapter ${adapter.adapter} is currently installed ${adapter.installs} times\n`;

body += '\n';
if ( adapter.stable_only) {
body *= `- [ ] add adapter to latest repository if adapter repository is valid\n`;
};
if ( adapter.archived) {
body += `- [ ] verify that repository https://github.com/${adapter.owner}/ioBroker.${adapter.adapter} is really archived\n`;
body += `- [ ] check if adapter has been migrated but links are not yet updated at repository\n`;
body += ` fix links at repository if this is causing the problem\n`;
body += `- [ ] decide if adapter should (and can) be moved to community-adapters (current usage ${adapter.installs} installs)\n`;
body += `- [ ] move adapter to iobroker-community-adapters or \n`;
body += ` remove adapter from repositories\n`;
};
if ( adapter.error) {
body += `- [ ] check repository ${adapter.owner}\ioBroker.${adapter.adapter}\n`;
body += `- [ ] remove adapter from repositories if adapter repository invalid\n`;
};

console.log(`\n`);
console.log(`CREATE ISSUE for ioBroker.${adapter.adapter}: ${title}\n`);
console.log(`${body}`);

try {
await createIssue('ioBroker', 'ioBroker.repositories', {title, body});
} catch (e) {
console.log(`error: Cannot create issue for adapter ${adapter.adapter}:`);
console.log(` ${e}`);
};
} else {
console.log(`ISSUE for ioBroker.${adapter.adapter} already exists`);
}
}


async function doIt() {
const latest = await getLatestRepo();
const stable = await getStableRepo();
const stats = await getStats();
const result = await checkRepos(latest, stable, stats);

console.log (`The following adapters should be checked:`);
for (const adapter of result) {
console.log (` ${adapter.owner}/ioBroker.${adapter.adapter}`);
}
for (const adapter of result) {
await generateIssue(adapter);
}
}

doIt()
.then(result => console.log('done'))
.catch(e => console.error(e));
Loading

0 comments on commit 11fbb1a

Please sign in to comment.