Skip to content

Commit ac63a2c

Browse files
authored
Merge pull request #287 from DefangLabs/linda-check-samples-action
Improve check-sample github workflow
2 parents 0dc408f + 8a40c7e commit ac63a2c

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

.github/workflows/check-sample.yml

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,48 +45,59 @@ jobs:
4545
const fs = require('fs');
4646
const pr_number = context.issue.number;
4747
const marker = '## Samples Checklist';
48-
49-
// Read the checklist from the file
50-
let checklist = fs.readFileSync('checklist.txt', 'utf8').trim();
48+
49+
let checklist;
5150
let error = false;
5251
53-
if(!checklist) {
54-
checklist = "✅ All good!"
55-
}
56-
else {
57-
error = true;
52+
try {
53+
// Read the checklist from the file
54+
checklist = fs.readFileSync('checklist.txt', 'utf8');
55+
checklist = checklist.trim();
56+
if(!checklist) {
57+
checklist = "✅ All good!"
58+
}
59+
else {
60+
error = true;
61+
}
62+
} catch (readFileError) {
63+
throw new Error("Could not read samples checklist from file. Please fix the issues and try again.")
5864
}
5965
60-
// Get the current PR
61-
const { data: pullRequest } = await github.rest.pulls.get({
62-
owner: context.repo.owner,
63-
repo: context.repo.repo,
64-
pull_number: pr_number
65-
});
66+
try {
67+
// Get the current PR
68+
const { data: pullRequest } = await github.rest.pulls.get({
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
pull_number: pr_number
72+
});
6673
67-
let newBody;
68-
const body = pullRequest.body || "";
69-
const markerIndex = body.indexOf(marker);
74+
let newBody;
75+
const body = pullRequest.body || "";
76+
const markerIndex = body.indexOf(marker);
7077
71-
if (markerIndex !== -1) {
72-
// Replace the content below the marker
73-
newBody = body.substring(0, markerIndex + marker.length) + "\n" + checklist;
74-
} else {
75-
// Append the checklist if the marker doesn't exist
76-
newBody = body + "\n" + marker + "\n" + checklist;
77-
}
78+
if (markerIndex !== -1) {
79+
// Replace the content below the marker
80+
newBody = body.substring(0, markerIndex + marker.length) + "\n" + checklist;
81+
} else {
82+
// Append the checklist if the marker doesn't exist
83+
newBody = body + "\n" + marker + "\n" + checklist;
84+
}
7885
79-
// Update the PR description
80-
await github.rest.pulls.update({
81-
owner: context.repo.owner,
82-
repo: context.repo.repo,
83-
pull_number: pr_number,
84-
body: newBody
85-
});
86+
// Update the PR description
87+
await github.rest.pulls.update({
88+
owner: context.repo.owner,
89+
repo: context.repo.repo,
90+
pull_number: pr_number,
91+
body: newBody
92+
});
93+
} catch (updatePrError) {
94+
throw new Error("Could not update PR description based on samples checklist. Please fix the issues and try again.")
95+
}
8696
87-
if(error) {
97+
if (error) {
8898
throw new Error("Incomplete samples checklist. Please fix the issues and try again.");
8999
}
100+
90101
91102
- name: Create / Update Template Repo
92103
uses: actions/github-script@v7

.github/workflows/publish-sample-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- main
77

88
jobs:
9-
check_samples:
9+
publish_samples:
1010
runs-on: ubuntu-latest
1111
permissions:
1212
contents: write

scripts/check-sample-files.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ for dir in ./samples/*/; do
1818
# if there is a compose.yaml file, check if it is valid
1919
(
2020
cd $dir
21-
if ! defang compose config > /dev/null 2>/dev/null; then
22-
echo " - [ ] ${dir}compose.yaml contains errors"
21+
output=$(defang compose config 2>&1)
22+
if [[ $? -ne 0 ]]; then
23+
echo " - [ ] ${dir}compose.yaml is not valid according to \`defang compose config\`: $output"
2324
fi
2425
)
2526
fi

0 commit comments

Comments
 (0)