-
-
Notifications
You must be signed in to change notification settings - Fork 26
95 lines (78 loc) · 3.25 KB
/
create-initial-issues.yml
File metadata and controls
95 lines (78 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Create Initial Issues
on:
workflow_dispatch:
jobs:
create-issues:
runs-on: ubuntu-latest
concurrency:
group: create-initial-issues-${{ github.ref }}
cancel-in-progress: false
if: ${{ github.repository != 'AOSSIE-Org/Template-Repo' }}
permissions:
contents: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if issues file exists
id: check_file
run: |
if [ -f ".github/initial-issues.json" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Issues file not found. Skipping..."
fi
- name: Create issues from JSON
if: steps.check_file.outputs.exists == 'true'
id: create_issues
uses: actions/github-script@v7
#js-yaml is NOT bundled with actions/github-script@v7 hecne we use JSON for the issues file
with:
script: |
const fs = require('fs');
// Read and parse the issues JSON file
const issuesData = JSON.parse(fs.readFileSync('.github/initial-issues.json', 'utf8'));
// Validate structure
if (!issuesData || !issuesData.issues || !Array.isArray(issuesData.issues)) {
throw new Error('Invalid issues data structure. Expected { issues: [...] }');
}
console.log(`Creating ${issuesData.issues.length} issues...`);
let successCount = 0;
let failCount = 0;
// Create each issue
for (const issue of issuesData.issues) {
try {
const response = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issue.title,
body: issue.body,
labels: issue.labels || []
});
console.log(`✓ Created issue #${response.data.number}: ${issue.title}`);
successCount++;
} catch (error) {
console.error(`✗ Failed to create issue "${issue.title}":`, error.message);
failCount++;
}
}
console.log(`\nSummary: ${successCount} succeeded, ${failCount} failed`);
// Fail the step if any issues failed to create
if (failCount > 0) {
throw new Error(`Failed to create ${failCount} issue(s)`);
}
- name: Delete issues file and workflow
if: steps.create_issues.outcome == 'success'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Delete the files
git rm .github/initial-issues.json
git rm .github/workflows/create-initial-issues.yml
# Commit the changes
git commit -m "chore: cleanup initial issues automation files"
# Pull latest changes to avoid conflicts
git pull --rebase origin ${{ github.ref_name }}
# Push the changes
git push