Skip to content

Commit 8d6b5a3

Browse files
committed
Fix: Update workflow for Fast Grants compatibility
1 parent 62b6e82 commit 8d6b5a3

File tree

2 files changed

+122
-25
lines changed

2 files changed

+122
-25
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fs = require('fs');
2+
const core = require('@actions/core');
3+
4+
function parseDeliveryFile(filePath) {
5+
try {
6+
const content = fs.readFileSync(filePath, 'utf8');
7+
8+
const appDocMatch = content.match(/\*\s*\*\*Application Document:\*\*\s*([^\s\n]+)/);
9+
const applicationDocument = appDocMatch ? appDocMatch[1] : null;
10+
11+
12+
const milestoneMatch = content.match(/\*\s*\*\*Milestone Number:\*\*\s*(\d+)/);
13+
const milestoneNumber = milestoneMatch ? milestoneMatch[1] : null;
14+
15+
if (!applicationDocument) {
16+
throw new Error('Application Document not found in file');
17+
}
18+
19+
core.setOutput('application_document', applicationDocument);
20+
core.setOutput('milestone_number', milestoneNumber);
21+
22+
console.log(`Application Document: ${applicationDocument}`);
23+
console.log(`Milestone Number: ${milestoneNumber}`);
24+
25+
} catch (error) {
26+
core.setFailed(`Error parsing delivery file: ${error.message}`);
27+
}
28+
}
29+
30+
const filePath = process.argv[2];
31+
if (!filePath) {
32+
core.setFailed('File path is required');
33+
} else {
34+
parseDeliveryFile(filePath);
35+
}

.github/workflows/check_author.yml

Lines changed: 87 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ on:
55

66
jobs:
77
get-delivery-files:
8-
runs-on: ubuntu-latest
9-
outputs:
10-
filenames: ${{ steps.files.outputs.added }}
11-
12-
steps:
13-
- name: Get filenames of any deliveries being added
14-
id: files
15-
uses: Ana06/get-changed-files@v2.3.0
16-
with:
17-
format: 'json'
18-
filter: |
19-
deliveries/*.md
20-
maintenance_deliveries/*.md
21-
8+
runs-on: ubuntu-latest
9+
outputs:
10+
filenames: ${{ steps.files.outputs.added }}
11+
12+
steps:
13+
- name: Get filenames of any deliveries being added
14+
id: files
15+
uses: Ana06/get-changed-files@v2.3.0
16+
with:
17+
format: 'json'
18+
filter: |
19+
deliveries/*.md
20+
maintenance_deliveries/*.md
21+
2222
check_author:
2323
runs-on: ubuntu-latest
2424
needs: get-delivery-files
@@ -27,34 +27,96 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
filename: ${{ fromJson(needs.get-delivery-files.outputs.filenames) }}
30-
30+
3131
steps:
3232
- uses: actions/checkout@v4
3333
with:
3434
ref: ${{ github.event.pull_request.head.sha }}
3535

36-
- name: Parse delivery file
36+
- name: Debug delivery file
37+
run: |
38+
echo "Checking file: ${{ matrix.filename }}"
39+
echo "File path: ${{ github.workspace }}/${{ matrix.filename }}"
40+
echo "File exists: $(test -f "${{ github.workspace }}/${{ matrix.filename }}" && echo 'YES' || echo 'NO')"
41+
echo ""
42+
echo "Content around 'Application Document':"
43+
grep -n -A2 -B2 -i "application document" "${{ github.workspace }}/${{ matrix.filename }}" || echo "Pattern not found"
44+
45+
- name: Extract application document (Fixed regex)
3746
id: parse-delivery
38-
uses: w3f/parse-milestone-delivery-action@master
39-
with:
40-
path: "${{ github.workspace }}/${{ matrix.filename }}"
47+
run: |
48+
file_path="${{ github.workspace }}/${{ matrix.filename }}"
49+
50+
# Try multiple patterns to extract application document
51+
app_doc=""
52+
53+
# Pattern 1: With bullet point and bold formatting (matches your JS parser)
54+
app_doc=$(grep -oP "\*\s*\*\*Application Document:\*\*\s*\K[^\s\n]+" "$file_path" 2>/dev/null | head -1 || echo "")
55+
56+
# Pattern 2: Without bullet point (fallback)
57+
if [ -z "$app_doc" ]; then
58+
app_doc=$(grep -oP "\*\*Application Document:\*\*\s*\K[^\s\n]+" "$file_path" 2>/dev/null | head -1 || echo "")
59+
fi
60+
61+
# Pattern 3: Simple applications/*.md pattern anywhere in file
62+
if [ -z "$app_doc" ]; then
63+
app_doc=$(grep -o "applications/[^[:space:]]*\.md" "$file_path" 2>/dev/null | head -1 || echo "")
64+
fi
65+
66+
# Pattern 4: More flexible regex for applications/ files
67+
if [ -z "$app_doc" ]; then
68+
app_doc=$(grep -E "applications/[a-zA-Z0-9_-]+\.md" "$file_path" 2>/dev/null | head -1 || echo "")
69+
fi
70+
71+
if [ -z "$app_doc" ]; then
72+
echo "Error: Could not extract application document from $file_path"
73+
echo "File content for debugging:"
74+
head -20 "$file_path"
75+
exit 1
76+
fi
77+
78+
echo "application_document=$app_doc" >> $GITHUB_OUTPUT
79+
echo "Found application document: $app_doc"
4180
4281
- name: Find PR author in application authors
43-
uses: actions/github-script@v5
82+
uses: actions/github-script@v7
4483
env:
4584
pr_author: ${{ github.event.pull_request.user.login }}
4685
with:
4786
script: |
87+
try {
88+
console.log(`Checking commits for: ${{ steps.parse-delivery.outputs.application_document }}`);
89+
console.log(`PR Author: ${process.env.pr_author}`);
90+
4891
const app_commits = await github.rest.repos.listCommits({
4992
owner: 'Polkadot-Fast-Grants',
5093
repo: 'apply',
51-
path: 'applications/${{ steps.parse-delivery.outputs.application_document }}'
94+
path: '${{ steps.parse-delivery.outputs.application_document }}'
5295
});
5396
54-
const app_authors = app_commits.data.map(c => c.author.login);
55-
console.log(app_authors);
56-
97+
if (app_commits.data.length === 0) {
98+
core.setFailed(`No commits found for application file: ${{ steps.parse-delivery.outputs.application_document }}`);
99+
return;
100+
}
101+
102+
const app_authors = app_commits.data
103+
.map(c => c.author?.login)
104+
.filter(author => author != null && author !== undefined);
105+
106+
console.log(`Application authors found: ${app_authors.join(', ')}`);
107+
108+
if (app_authors.length === 0) {
109+
core.setFailed('No valid authors found in application commits');
110+
return;
111+
}
57112
58113
if (!app_authors.includes(process.env.pr_author)) {
59-
core.setFailed('PR author does not match any application author.');
114+
core.setFailed(`PR author '${process.env.pr_author}' does not match any application author. Valid authors: ${app_authors.join(', ')}`);
115+
} else {
116+
console.log('Author check passed! PR author matches application author.');
60117
}
118+
119+
} catch (error) {
120+
console.error('Error details:', error);
121+
core.setFailed(`Error checking application authors: ${error.message}`);
122+
}

0 commit comments

Comments
 (0)