Skip to content

Check Pull Requests #78

Check Pull Requests

Check Pull Requests #78

Workflow file for this run

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", []);
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);
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 }}"
- name: Prepare Validation
uses: actions/checkout@v4
with:
path: ./
repository: RestApia/RestApia.Extensions.Private
token: ${{ secrets.PRIVATE_REPO_TOKEN }}
- name: Checkout PR Code
uses: actions/checkout@v4
with:
ref: refs/pull/${{ matrix.pr_number }}/merge
path: .local/pr
- name: Run Validation
run: |
chmod +x ./build.sh
./build.sh Git_PR_Handle --PrNumber ${{ matrix.pr_number }}
env:
PRIVATE_REPO_TOKEN: ${{ secrets.PRIVATE_REPO_TOKEN }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: extension-package-${{ matrix.pr_number }} # Unique name per PR
path: ${{ env.ARTIFACT_PATH }}
- name: Post Validation Success
if: success()
run: echo "Validation passed successfully."
- name: Post Validation Failure
if: failure()
run: echo "Validation failed."