Papi Simulator - 2 Milestone #13
Workflow file for this run
This file contains hidden or 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 Author | |
| on: | |
| pull_request_target: | |
| types: [opened, synchronize] | |
| jobs: | |
| get-delivery-files: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| filenames: ${{ steps.files.outputs.added }} | |
| steps: | |
| - name: Get filenames of any deliveries being added | |
| id: files | |
| uses: Ana06/get-changed-files@v2.3.0 | |
| with: | |
| format: 'json' | |
| filter: | | |
| deliveries/*.md | |
| maintenance_deliveries/*.md | |
| check_author: | |
| runs-on: ubuntu-latest | |
| needs: get-delivery-files | |
| if: needs.get-delivery-files.outputs.filenames != '[]' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| filename: ${{ fromJson(needs.get-delivery-files.outputs.filenames) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Debug delivery file | |
| run: | | |
| echo "Checking file: ${{ matrix.filename }}" | |
| echo "File path: ${{ github.workspace }}/${{ matrix.filename }}" | |
| echo "File exists: $(test -f "${{ github.workspace }}/${{ matrix.filename }}" && echo 'YES' || echo 'NO')" | |
| echo "" | |
| echo "Content around 'Application Document':" | |
| grep -n -A2 -B2 -i "application document" "${{ github.workspace }}/${{ matrix.filename }}" || echo "Pattern not found" | |
| - name: Extract application document (Fast Grants compatible) | |
| id: parse-delivery | |
| run: | | |
| file_path="${{ github.workspace }}/${{ matrix.filename }}" | |
| # Try multiple patterns to extract application document | |
| app_doc="" | |
| # Pattern 1: After "**Application Document:**" | |
| app_doc=$(grep -oP "(?<=\*\*Application Document:\*\*\s)[^\s\n]+" "$file_path" 2>/dev/null | head -1 || echo "") | |
| # Pattern 2: Simple applications/*.md pattern | |
| if [ -z "$app_doc" ]; then | |
| app_doc=$(grep -o "applications/[^[:space:]]*\.md" "$file_path" 2>/dev/null | head -1 || echo "") | |
| fi | |
| # Pattern 3: More flexible regex | |
| if [ -z "$app_doc" ]; then | |
| app_doc=$(grep -E "applications/[a-zA-Z0-9_-]+\.md" "$file_path" 2>/dev/null | head -1 || echo "") | |
| fi | |
| if [ -z "$app_doc" ]; then | |
| echo "Error: Could not extract application document from $file_path" | |
| echo "File content for debugging:" | |
| head -20 "$file_path" | |
| exit 1 | |
| fi | |
| echo "application_document=$app_doc" >> $GITHUB_OUTPUT | |
| echo "Found application document: $app_doc" | |
| - name: Find PR author in application authors | |
| uses: actions/github-script@v7 | |
| env: | |
| pr_author: ${{ github.event.pull_request.user.login }} | |
| with: | |
| script: | | |
| try { | |
| console.log(`Checking commits for: ${{ steps.parse-delivery.outputs.application_document }}`); | |
| console.log(`PR Author: ${process.env.pr_author}`); | |
| const app_commits = await github.rest.repos.listCommits({ | |
| owner: 'Polkadot-Fast-Grants', | |
| repo: 'apply', | |
| path: '${{ steps.parse-delivery.outputs.application_document }}' | |
| }); | |
| if (app_commits.data.length === 0) { | |
| core.setFailed(`No commits found for application file: ${{ steps.parse-delivery.outputs.application_document }}`); | |
| return; | |
| } | |
| const app_authors = app_commits.data | |
| .map(c => c.author?.login) | |
| .filter(author => author != null && author !== undefined); | |
| console.log(`Application authors found: ${app_authors.join(', ')}`); | |
| if (app_authors.length === 0) { | |
| core.setFailed('No valid authors found in application commits'); | |
| return; | |
| } | |
| if (!app_authors.includes(process.env.pr_author)) { | |
| core.setFailed(`PR author '${process.env.pr_author}' does not match any application author. Valid authors: ${app_authors.join(', ')}`); | |
| } else { | |
| console.log('Author check passed! PR author matches application author.'); | |
| } | |
| } catch (error) { | |
| console.error('Error details:', error); | |
| core.setFailed(`Error checking application authors: ${error.message}`); | |
| } |