PR Linter #187446
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
# https://octokit.github.io/rest.js | |
# https://github.com/actions/toolkit/blob/master/packages/github/src/context.ts | |
name: PR Linter | |
on: | |
pull_request_target: | |
types: | |
- labeled | |
- unlabeled | |
- edited | |
- opened | |
- synchronize | |
- reopened | |
# Triggered from a separate job when a review is added | |
workflow_run: | |
workflows: [PR Linter Trigger] | |
types: | |
- completed | |
# Trigger when a status is updated (CodeBuild leads to statuses) | |
status: {} | |
# Trigger when a check suite is completed (GitHub actions and CodeCov create checks) | |
check_suite: | |
types: [completed] | |
jobs: | |
download-if-workflow-run: | |
runs-on: ubuntu-latest | |
outputs: | |
pr_number: ${{ steps.pr_output.outputs.pr_number }} | |
pr_sha: ${{ steps.pr_output.outputs.pr_sha }} | |
# if conditions on all individual steps because subsequent jobs depend on this job | |
# and we cannot skip it entirely | |
steps: | |
- name: 'Download workflow_run artifact' | |
if: github.event_name == 'workflow_run' | |
uses: dawidd6/action-download-artifact@v7 | |
with: | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr_info | |
path: pr/ | |
search_artifacts: true | |
- name: 'Determine PR info' | |
# PR info comes from the artifact if downloaded, or GitHub context if not. | |
if: github.event_name == 'workflow_run' | |
id: 'pr_output' | |
run: | | |
if [[ ! -f pr/pr_number ]]; then | |
echo "${{ github.event.pull_request.number }}" > pr/pr_number | |
fi | |
if [[ ! -f pr/pr_sha ]]; then | |
echo "${{ github.event.pull_request.head.sha }}" > pr/pr_sha | |
fi | |
cat pr/* | |
echo "pr_number=$(cat pr/pr_number)" >> "$GITHUB_OUTPUT" | |
echo "pr_sha=$(cat pr/pr_sha)" >> "$GITHUB_OUTPUT" | |
validate-pr: | |
# Necessary to have sufficient permissions to write to the PR | |
permissions: | |
contents: read | |
pull-requests: write | |
statuses: read | |
issues: read | |
checks: read | |
runs-on: ubuntu-latest | |
needs: download-if-workflow-run | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install & Build prlint | |
run: yarn install --frozen-lockfile && cd tools/@aws-cdk/prlint && yarn build+test | |
- name: Validate | |
uses: ./tools/@aws-cdk/prlint | |
env: | |
GITHUB_TOKEN: ${{ secrets.PROJEN_GITHUB_TOKEN }} | |
PR_NUMBER: ${{ needs.download-if-workflow-run.outputs.pr_number }} | |
PR_SHA: ${{ needs.download-if-workflow-run.outputs.pr_sha }} | |
LINTER_LOGIN: ${{ vars.LINTER_LOGIN }} | |
REPO_ROOT: ${{ github.workspace }} |