Check Pull Requests #73
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Pull Requests | |
on: | |
schedule: | |
- cron: "* */1 * * *" # Run every hour | |
workflow_dispatch: # Allow manual triggering | |
permissions: | |
contents: read | |
pull-requests: write | |
statuses: write | |
jobs: | |
check_prs: | |
runs-on: ubuntu-latest | |
outputs: | |
prs: ${{ steps.filter_prs.outputs.prs }} | |
steps: | |
- name: List Open PRs | |
id: list_prs | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { data: pullRequests } = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open' | |
}); | |
core.exportVariable('PRS', JSON.stringify(pullRequests)); | |
- name: Filter PRs | |
id: filter_prs | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const prsRaw = process.env.PRS; | |
if (!prsRaw || prsRaw === '[]') { | |
console.log("No PRs to validate."); | |
core.setOutput("prs_to_validate", JSON.stringify([])); | |
return; | |
} | |
const prs = JSON.parse(prsRaw); | |
const prNumbers = []; | |
for (const pr of prs) { | |
const { data: statuses } = await github.rest.repos.listCommitStatusesForRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: pr.head.sha | |
}); | |
const hasValidatedStatus = statuses.some(status => status.context === 'Validated'); | |
const hasInProgressStatus = statuses.some(status => status.context === 'InProgress'); | |
if (!hasValidatedStatus && !hasInProgressStatus) { | |
prNumbers.push(pr.number); | |
} | |
} | |
console.log(`PRs to validate: ${JSON.stringify(prNumbers)}`); | |
core.setOutput("prs", prNumbers); | |
job2: | |
needs: check_prs | |
runs-on: ubuntu-latest | |
steps: | |
- name: Validate PRs | |
run: | | |
echo "1: ${{ needs.check_prs.outputs.prs }}" | |
# echo "2: ${{ needs.check_prs.outputs.prs[0] }}" | |
# echo "3: ${{ needs.check_prs.outputs.prs.length }}" | |
echo "4: ${{ fromJSON(needs.check_prs.outputs.prs) }}" | |
echo "5: ${{ fromJSON(needs.check_prs.outputs.prs)[0] }}" | |
echo "6: ${{ fromJSON(needs.check_prs.outputs.prs).length }}" | |
echo "7: ${{ fromJSON(needs.check_prs.outputs.prs).length > 0 }}" | |
trigger_validation: | |
needs: check_prs | |
if: ${{ fromJSON(needs.check_prs.outputs.prs)[0] }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
pr_number: ${{ fromJSON(needs.check_prs.outputs.prs) }} | |
steps: | |
- name: Debug | |
run: | | |
echo "PR Number: ${{ matrix.pr_number }}" |