diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 6e86fabc5..f24d6052d 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -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 }} diff --git a/tests/pr.test.js b/tests/pr.test.js deleted file mode 100644 index 4a9822684..000000000 --- a/tests/pr.test.js +++ /dev/null @@ -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(); -});