diff --git a/.github/workflows/push_to_prod.yaml b/.github/workflows/push_to_prod.yaml index 73e225c..65d0ac9 100644 --- a/.github/workflows/push_to_prod.yaml +++ b/.github/workflows/push_to_prod.yaml @@ -16,6 +16,10 @@ jobs: with: ref: "main" fetch-depth: 0 + - name: List .github directory + run: | + ls -la + ls -la .github - name: Ensure PR was approved by Code Owner id: check_approval uses: actions/github-script@v7 @@ -28,13 +32,31 @@ jobs: repo: context.repo.repo, pull_number: prNumber }); + //const codeOwners = ['cdc-as81', 'gilsharon321']; // Replace with actual code owners + const fs = require('fs'); + const path = require('path'); + //const codeownersPath = path.join(process.env.GITHUB_WORKSPACE, '.github', 'CODEOWNERS'); + const codeownersPath = path.join('.github', 'CODEOWNERS'); + let codeOwners = []; + try { + const codeownersContent = fs.readFileSync(codeownersPath, 'utf8'); + codeOwners = codeownersContent + .split('\n') + .map(line => line.trim()) + .filter(line => line && !line.startsWith('#')) + .flatMap(line => line.split(/\s+/).slice(1)) // skip the pattern, get owners + .map(owner => owner.startsWith('@') ? owner.slice(1) : owner) + .filter((owner, idx, arr) => arr.indexOf(owner) === idx); // unique + } catch (err) { + core.setFailed(`Failed to read CODEOWNERS: ${err.message}`); + } + const reviewsFromCodeOwners = reviews.filter(r => + r.state === 'APPROVED' && codeOwners.includes(r.user.login)); - const approvals = reviews.filter(r => r.state === 'APPROVED'); - - if (approvals.length === 0) { + if (reviewsFromCodeOwners.length === 0) { core.setFailed('No approvals from code owners.'); } else { - console.log(`Found ${approvals.length} approval(s)`); + console.log(`Found ${reviewsFromCodeOwners.length} approvals from code owners`); } - name: Pull from main and push to production if: success() diff --git a/README.md b/README.md index a2416fa..1b1ab12 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# sandbox \ No newline at end of file +# sandbox + +123 \ No newline at end of file