mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-13 14:16:04 +00:00
remove pr tests
This commit is contained in:
1 parent
0c45938908
commit
b7e96a5617
2 files changed
-88
No files matched your search
@@ -36,22 +36,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Clone is-a-dev/register
|
||||
run: git clone https://github.com/is-a-dev/register.git register-${{ github.run_id }}
|
||||
|
||||
- run: npm install
|
||||
|
||||
- name: Get all modified domain JSON files
|
||||
if: github.event_name == 'pull_request'
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@v45
|
||||
with:
|
||||
files: domains/*.json
|
||||
|
||||
- name: Run tests
|
||||
run: npx ava tests/*.test.js
|
||||
env:
|
||||
EVENT: ${{ github.event_name }}
|
||||
RUN_ID: ${{ github.run_id }}
|
||||
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
|
||||
MODIFIED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
|
||||
@@ -1,73 +0,0 @@
|
||||
const t = require("ava");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const PR_AUTHOR = process.env.PR_AUTHOR.toLowerCase();
|
||||
const MODIFIED_DOMAIN_FILES = (process.env.MODIFIED_FILES || "").length > 0
|
||||
? (process.env.MODIFIED_FILES || "").split(" ").map((file) => file.replace(/^domains\//, ""))
|
||||
: null;
|
||||
const EVENT = process.env.EVENT;
|
||||
const RUN_ID = process.env.RUN_ID;
|
||||
|
||||
const domainsPath = path.resolve("domains");
|
||||
const headDomainsPath = path.resolve(`register-${RUN_ID}/domains`);
|
||||
|
||||
const admins = require("../util/administrators.json").map(admin => admin.toLowerCase());
|
||||
|
||||
async function getJSONContent(basePath, fileName) {
|
||||
try {
|
||||
return await fs.readJson(path.join(basePath, fileName));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
t("Modified JSON files must be owned by the PR author", async (t) => {
|
||||
if (EVENT !== "pull_request") return t.pass();
|
||||
if (!MODIFIED_DOMAIN_FILES) return t.pass();
|
||||
|
||||
const checks = MODIFIED_DOMAIN_FILES.map(async (file) => {
|
||||
const [modifiedDomain, currentDomain] = await Promise.all([
|
||||
getJSONContent(domainsPath, file),
|
||||
getJSONContent(headDomainsPath, file)
|
||||
]);
|
||||
|
||||
const domainToCheck = currentDomain || modifiedDomain;
|
||||
|
||||
if (!modifiedDomain || !domainToCheck) {
|
||||
t.fail(`${file}: Unable to read domain data`);
|
||||
return;
|
||||
}
|
||||
|
||||
t.true(
|
||||
domainToCheck.owner.username.toLowerCase() === PR_AUTHOR || admins.includes(PR_AUTHOR),
|
||||
`${file}: Domain owner is ${domainToCheck.owner.username.toLowerCase()} but ${PR_AUTHOR} is the PR author`
|
||||
);
|
||||
});
|
||||
|
||||
await Promise.all(checks);
|
||||
t.pass();
|
||||
});
|
||||
|
||||
t("New JSON files must be owned by the PR author", async (t) => {
|
||||
if (EVENT !== "pull_request") return t.pass();
|
||||
if (!MODIFIED_DOMAIN_FILES) return t.pass();
|
||||
|
||||
const [newFiles, currentFiles] = await Promise.all([fs.readdir(domainsPath), fs.readdir(headDomainsPath)]);
|
||||
|
||||
const newDomainFiles = newFiles.filter((file) => !currentFiles.includes(file));
|
||||
|
||||
const checks = newDomainFiles.map(async (file) => {
|
||||
const domain = await getJSONContent(domainsPath, file);
|
||||
|
||||
if (!domain) return t.fail(`${file}: Unable to read domain data`);
|
||||
|
||||
t.true(
|
||||
domain.owner.username.toLowerCase() === PR_AUTHOR || admins.includes(PR_AUTHOR),
|
||||
`${file}: Domain owner is ${domain.owner.username.toLowerCase()} but ${PR_AUTHOR} is the PR author`
|
||||
);
|
||||
});
|
||||
|
||||
await Promise.all(checks);
|
||||
t.pass();
|
||||
});
|
||||
Reference in new issue
Block a user