diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 4f9863fc7..92a03e6bb 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -35,6 +35,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + path: ${{ github.run_id }} + + - uses: actions/checkout@v4 + with: + repository: is-a-dev/register + path: register - run: npm install @@ -45,15 +52,6 @@ jobs: with: files: domains/*.json - - name: testing - run: | - ls - ls ../ - echo ${{ steps.changed-files.outputs.all_changed_files }} - for file in ${{ steps.changed-files.outputs.all_changed_files }}; do - cat $file - done - - run: npm test env: EVENT: ${{ github.event_name }} diff --git a/tests/pr.test.js b/tests/pr.test.js index 5de425a0f..ccd3015f0 100644 --- a/tests/pr.test.js +++ b/tests/pr.test.js @@ -10,6 +10,7 @@ for (let i = 0; i < MODIFIED_FILES.length; i++) { } const domainsPath = path.resolve("domains"); +const headDomainsPath = path.resolve("../register/domains"); const admins = require("../util/administrators.json"); @@ -20,11 +21,37 @@ t("Modified JSON files must be owned by the PR author", (t) => { } MODIFIED_FILES.forEach((file) => { + const modifiedDomain = fs.readJsonSync(path.join(domainsPath, file)); + let currentDomain = null; + + try { + currentDomain = fs.readJsonSync(path.join(headDomainsPath, file)); + } catch { + currentDomain = modifiedDomain; + } + + t.true( + currentDomain.owner.username === PR_AUTHOR || admins.includes(PR_AUTHOR), + `${file}: Domain owner is ${domain.owner.username} but ${PR_AUTHOR} is the PR author` + ); + }); +}); + + +t("New JSON files must be owned by the PR author", (t) => { + if(process.env.EVENT !== "pull_request") { + t.pass(); + return; + } + + const newFiles = fs.readdirSync(domainsPath).filter((file) => !fs.readdirSync(headDomainsPath).includes(file)); + + newFiles.forEach((file) => { const domain = fs.readJsonSync(path.join(domainsPath, file)); t.true( domain.owner.username === PR_AUTHOR || admins.includes(PR_AUTHOR), - `${file}: Owner is ${domain.owner.username} but ${PR_AUTHOR} is the PR author` + `${file}: Domain owner is ${domain.owner.username} but ${PR_AUTHOR} is the PR author` ); }); -}); +})