-
Notifications
You must be signed in to change notification settings - Fork 1
182 lines (154 loc) · 7.53 KB
/
create-extension.yml
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Create Extension
on:
issues:
types: [opened, edited]
jobs:
process-extension:
if: contains(github.event.issue.labels.*.name, 'new-extension')
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Parse Issue and Download Files
id: parse
uses: actions/github-script@v6
with:
script: |
const body = context.payload.issue.body;
const lines = body.split('\n');
const extension = {};
// Parse basic info
lines.forEach(line => {
if (line.startsWith('**Name:**')) extension.name = line.replace('**Name:**', '').trim();
if (line.startsWith('**Description:**')) extension.description = line.replace('**Description:**', '').trim();
if (line.startsWith('**Version:**')) extension.version = line.replace('**Version:**', '').trim();
if (line.startsWith('**Author:**')) extension.author = line.replace('**Author:**', '').trim();
if (line.startsWith('**Tags:**')) extension.tags = line.replace('**Tags:**', '').trim();
});
// Debug logs
console.log('Issue body:', body);
// Find ZIP attachment with multiple possible patterns
const attachmentPatterns = [
/https:\/\/user-images\.githubusercontent\.com\/[^\s)]+\.zip/g,
/https:\/\/github\.com\/[^\s)]+\/files\/[^\s)]+\.zip/g
];
let attachments = [];
attachmentPatterns.forEach(pattern => {
const matches = body.match(pattern) || [];
attachments.push(...matches);
});
console.log('Found attachments in body:', attachments);
// Check comments for attachments too
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number
});
comments.data.forEach(comment => {
attachmentPatterns.forEach(pattern => {
const matches = comment.body.match(pattern) || [];
attachments.push(...matches);
});
console.log('Found attachments in comment:', comment.body);
});
console.log('All attachments found:', attachments);
// Extract file ID from GitHub attachment URL
const zipFile = attachments[0];
if (!zipFile) {
console.log('No ZIP file found in attachments');
throw new Error('Missing required ZIP file containing .crx and icon. Please attach a ZIP file containing your extension.crx and icon.png files.');
}
// Convert GitHub attachment URL to raw download URL if needed
let downloadUrl = zipFile;
if (zipFile.includes('github.com')) {
const fileId = zipFile.match(/\/files\/(\d+)\//)[1];
downloadUrl = `https://github.com/user-attachments/files/${fileId}/artifact.zip`;
}
extension.zip_url = downloadUrl;
console.log('Final download URL:', downloadUrl);
return extension;
- name: Download and Process ZIP
run: |
# Create temp directory
mkdir -p temp
cd temp
# Download and extract ZIP
wget -O package.zip "${{ fromJSON(steps.parse.outputs.result).zip_url }}"
unzip package.zip
# Handle different possible file structures
if [ -d "artifact" ]; then
cd artifact
fi
# Check for files with different possible names
CRX_FILE=$(find . -name "*.crx" -o -name "build.crx" | head -n 1)
ICON_FILE=$(find . -name "icon*.png" -o -name "*.png" | head -n 1)
if [ -z "$CRX_FILE" ] || [ -z "$ICON_FILE" ]; then
echo "Missing required files (.crx file and icon)"
exit 1
fi
# Move files to final location with correct names
SAFE_NAME=$(echo "${{ fromJSON(steps.parse.outputs.result).name }}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9-]/-/g')
mkdir -p "../../extensions/${SAFE_NAME}"
cp "$CRX_FILE" "../../extensions/${SAFE_NAME}/${SAFE_NAME}.crx"
cp "$ICON_FILE" "../../extensions/${SAFE_NAME}/icon.png"
# Clean up
cd ../..
rm -rf temp
- name: Update Extensions JSON
run: |
# Generate safe name for URLs
SAFE_NAME=$(echo "${{ fromJSON(steps.parse.outputs.result).name }}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9-]/-/g')
# Generate URLs based on our repository and new directory structure
DOWNLOAD_URL="https://raw.githubusercontent.com/${{ github.repository }}/raw/refs/heads/main/extensions/${SAFE_NAME}/${SAFE_NAME}.crx"
ICON_URL="https://raw.githubusercontent.com/${{ github.repository }}/blob/main/extensions/${SAFE_NAME}/icon.png"
GITHUB_URL="https://github.com/${{ github.repository }}/blob/main/extensions/${SAFE_NAME}/"
# Initialize extensions.json if it doesn't exist
if [ ! -f extensions.json ]; then
echo '{"extensions": []}' > extensions.json
fi
# Process tags: split by comma, remove whitespace
jq --arg name "${{ fromJSON(steps.parse.outputs.result).name }}" \
--arg desc "${{ fromJSON(steps.parse.outputs.result).description }}" \
--arg ver "${{ fromJSON(steps.parse.outputs.result).version }}" \
--arg author "${{ fromJSON(steps.parse.outputs.result).author }}" \
--arg download "$DOWNLOAD_URL" \
--arg icon "$ICON_URL" \
--arg github "$GITHUB_URL" \
--arg tags "${{ fromJSON(steps.parse.outputs.result).tags }}" \
'.extensions += [{
"id": ((.extensions | length) + 1 | tostring),
"name": $name,
"description": $desc,
"version": $ver,
"author": $author,
"download_url": $download,
"icon_url": $icon,
"github_url": $github,
"tags": ($tags | split(",") | map(gsub("^\\s+|\\s+$"; ""))),
"created_at": (now | strftime("%Y-%m-%dT%H:%M:%SZ")),
"updated_at": (now | strftime("%Y-%m-%dT%H:%M:%SZ"))
}]' extensions.json > temp.json && mv temp.json extensions.json
- name: Commit and Push Changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add extensions/
git add extensions.json
git commit -m "Add new extension: ${{ fromJSON(steps.parse.outputs.result).name }}"
git push
- name: Comment on Issue
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: `Extension has been successfully added!\n\nDownload URL: ${process.env.DOWNLOAD_URL}\nIcon URL: ${process.env.ICON_URL}\nGitHub URL: ${process.env.GITHUB_URL}`
});