mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 08:13:37 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26074f9390 | ||
|
|
0ad2de90ee | ||
|
|
af04e69dc7 |
222
.github/scripts/upload-to-r2.js
vendored
222
.github/scripts/upload-to-r2.js
vendored
@@ -65,33 +65,197 @@ function findArtifacts(dir, pattern) {
|
|||||||
return files.filter((f) => pattern.test(f)).map((f) => path.join(dir, f));
|
return files.filter((f) => pattern.test(f)).map((f) => path.join(dir, f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkUrlAccessible(url, maxRetries = 10, initialDelay = 1000) {
|
||||||
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||||
|
try {
|
||||||
|
const result = await new Promise((resolve, reject) => {
|
||||||
|
const request = https.get(url, { timeout: 10000 }, (response) => {
|
||||||
|
const statusCode = response.statusCode;
|
||||||
|
|
||||||
|
// Follow redirects
|
||||||
|
if (
|
||||||
|
statusCode === 302 ||
|
||||||
|
statusCode === 301 ||
|
||||||
|
statusCode === 307 ||
|
||||||
|
statusCode === 308
|
||||||
|
) {
|
||||||
|
const redirectUrl = response.headers.location;
|
||||||
|
response.destroy();
|
||||||
|
if (!redirectUrl) {
|
||||||
|
resolve({
|
||||||
|
accessible: false,
|
||||||
|
statusCode,
|
||||||
|
error: "Redirect without location header",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Follow the redirect URL
|
||||||
|
return https
|
||||||
|
.get(redirectUrl, { timeout: 10000 }, (redirectResponse) => {
|
||||||
|
const redirectStatus = redirectResponse.statusCode;
|
||||||
|
const contentType =
|
||||||
|
redirectResponse.headers["content-type"] || "";
|
||||||
|
// Check if it's actually a file (zip/tar.gz) and not HTML
|
||||||
|
const isFile =
|
||||||
|
contentType.includes("application/zip") ||
|
||||||
|
contentType.includes("application/gzip") ||
|
||||||
|
contentType.includes("application/x-gzip") ||
|
||||||
|
contentType.includes("application/x-tar") ||
|
||||||
|
redirectUrl.includes(".zip") ||
|
||||||
|
redirectUrl.includes(".tar.gz");
|
||||||
|
const isGood =
|
||||||
|
redirectStatus >= 200 && redirectStatus < 300 && isFile;
|
||||||
|
redirectResponse.destroy();
|
||||||
|
resolve({
|
||||||
|
accessible: isGood,
|
||||||
|
statusCode: redirectStatus,
|
||||||
|
finalUrl: redirectUrl,
|
||||||
|
contentType,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on("error", (error) => {
|
||||||
|
resolve({
|
||||||
|
accessible: false,
|
||||||
|
statusCode,
|
||||||
|
error: error.message,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on("timeout", function () {
|
||||||
|
this.destroy();
|
||||||
|
resolve({
|
||||||
|
accessible: false,
|
||||||
|
statusCode,
|
||||||
|
error: "Timeout following redirect",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if status is good (200-299 range) and it's actually a file
|
||||||
|
const contentType = response.headers["content-type"] || "";
|
||||||
|
const isFile =
|
||||||
|
contentType.includes("application/zip") ||
|
||||||
|
contentType.includes("application/gzip") ||
|
||||||
|
contentType.includes("application/x-gzip") ||
|
||||||
|
contentType.includes("application/x-tar") ||
|
||||||
|
url.includes(".zip") ||
|
||||||
|
url.includes(".tar.gz");
|
||||||
|
const isGood = statusCode >= 200 && statusCode < 300 && isFile;
|
||||||
|
response.destroy();
|
||||||
|
resolve({ accessible: isGood, statusCode, contentType });
|
||||||
|
});
|
||||||
|
|
||||||
|
request.on("error", (error) => {
|
||||||
|
resolve({
|
||||||
|
accessible: false,
|
||||||
|
statusCode: null,
|
||||||
|
error: error.message,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
request.on("timeout", () => {
|
||||||
|
request.destroy();
|
||||||
|
resolve({
|
||||||
|
accessible: false,
|
||||||
|
statusCode: null,
|
||||||
|
error: "Request timeout",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.accessible) {
|
||||||
|
if (attempt > 0) {
|
||||||
|
console.log(
|
||||||
|
`✓ URL ${url} is now accessible after ${attempt} retries (status: ${result.statusCode})`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`✓ URL ${url} is accessible (status: ${result.statusCode})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return result.finalUrl || url; // Return the final URL (after redirects) if available
|
||||||
|
} else {
|
||||||
|
const errorMsg = result.error ? ` - ${result.error}` : "";
|
||||||
|
const statusMsg = result.statusCode
|
||||||
|
? ` (status: ${result.statusCode})`
|
||||||
|
: "";
|
||||||
|
const contentTypeMsg = result.contentType
|
||||||
|
? ` [content-type: ${result.contentType}]`
|
||||||
|
: "";
|
||||||
|
console.log(
|
||||||
|
`✗ URL ${url} not accessible${statusMsg}${contentTypeMsg}${errorMsg}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`✗ URL ${url} check failed: ${error.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attempt < maxRetries - 1) {
|
||||||
|
const delay = initialDelay * Math.pow(2, attempt);
|
||||||
|
console.log(
|
||||||
|
` Retrying in ${delay}ms... (attempt ${attempt + 1}/${maxRetries})`
|
||||||
|
);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`URL ${url} is not accessible after ${maxRetries} attempts`);
|
||||||
|
}
|
||||||
|
|
||||||
async function downloadFromGitHub(url, outputPath) {
|
async function downloadFromGitHub(url, outputPath) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
https
|
const request = https.get(url, { timeout: 30000 }, (response) => {
|
||||||
.get(url, (response) => {
|
const statusCode = response.statusCode;
|
||||||
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
||||||
// Follow redirect
|
// Follow redirects (all redirect types)
|
||||||
return downloadFromGitHub(response.headers.location, outputPath)
|
if (
|
||||||
.then(resolve)
|
statusCode === 301 ||
|
||||||
.catch(reject);
|
statusCode === 302 ||
|
||||||
}
|
statusCode === 307 ||
|
||||||
if (response.statusCode !== 200) {
|
statusCode === 308
|
||||||
reject(
|
) {
|
||||||
new Error(
|
const redirectUrl = response.headers.location;
|
||||||
`Failed to download ${url}: ${response.statusCode} ${response.statusMessage}`
|
response.destroy();
|
||||||
)
|
if (!redirectUrl) {
|
||||||
);
|
reject(new Error(`Redirect without location header for ${url}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const fileStream = fs.createWriteStream(outputPath);
|
// Resolve relative redirects
|
||||||
response.pipe(fileStream);
|
const finalRedirectUrl = redirectUrl.startsWith("http")
|
||||||
fileStream.on("finish", () => {
|
? redirectUrl
|
||||||
fileStream.close();
|
: new URL(redirectUrl, url).href;
|
||||||
resolve();
|
console.log(` Following redirect: ${finalRedirectUrl}`);
|
||||||
});
|
return downloadFromGitHub(finalRedirectUrl, outputPath)
|
||||||
fileStream.on("error", reject);
|
.then(resolve)
|
||||||
})
|
.catch(reject);
|
||||||
.on("error", reject);
|
}
|
||||||
|
|
||||||
|
if (statusCode !== 200) {
|
||||||
|
response.destroy();
|
||||||
|
reject(
|
||||||
|
new Error(
|
||||||
|
`Failed to download ${url}: ${statusCode} ${response.statusMessage}`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileStream = fs.createWriteStream(outputPath);
|
||||||
|
response.pipe(fileStream);
|
||||||
|
fileStream.on("finish", () => {
|
||||||
|
fileStream.close();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
fileStream.on("error", (error) => {
|
||||||
|
response.destroy();
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
request.on("error", reject);
|
||||||
|
request.on("timeout", () => {
|
||||||
|
request.destroy();
|
||||||
|
reject(new Error(`Request timeout for ${url}`));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,12 +275,18 @@ async function main() {
|
|||||||
const sourceZipPath = path.join(tempDir, `automaker-${VERSION}.zip`);
|
const sourceZipPath = path.join(tempDir, `automaker-${VERSION}.zip`);
|
||||||
const sourceTarGzPath = path.join(tempDir, `automaker-${VERSION}.tar.gz`);
|
const sourceTarGzPath = path.join(tempDir, `automaker-${VERSION}.tar.gz`);
|
||||||
|
|
||||||
console.log(`Downloading source archives from GitHub...`);
|
console.log(`Waiting for source archives to be available on GitHub...`);
|
||||||
console.log(` ZIP: ${githubZipUrl}`);
|
console.log(` ZIP: ${githubZipUrl}`);
|
||||||
console.log(` TAR.GZ: ${githubTarGzUrl}`);
|
console.log(` TAR.GZ: ${githubTarGzUrl}`);
|
||||||
|
|
||||||
await downloadFromGitHub(githubZipUrl, sourceZipPath);
|
// Wait for archives to be accessible with exponential backoff
|
||||||
await downloadFromGitHub(githubTarGzUrl, sourceTarGzPath);
|
// This returns the final URL after following redirects
|
||||||
|
const finalZipUrl = await checkUrlAccessible(githubZipUrl);
|
||||||
|
const finalTarGzUrl = await checkUrlAccessible(githubTarGzUrl);
|
||||||
|
|
||||||
|
console.log(`Downloading source archives from GitHub...`);
|
||||||
|
await downloadFromGitHub(finalZipUrl, sourceZipPath);
|
||||||
|
await downloadFromGitHub(finalTarGzUrl, sourceTarGzPath);
|
||||||
|
|
||||||
console.log(`Downloaded source archives successfully`);
|
console.log(`Downloaded source archives successfully`);
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -50,6 +50,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Extract and set version
|
- name: Extract and set version
|
||||||
id: version
|
id: version
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
VERSION_TAG="${{ github.event.inputs.version || github.ref_name }}"
|
VERSION_TAG="${{ github.event.inputs.version || github.ref_name }}"
|
||||||
# Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
|
# Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
|
||||||
@@ -143,6 +144,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Extract version
|
- name: Extract version
|
||||||
id: version
|
id: version
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
VERSION_TAG="${{ github.event.inputs.version || github.ref_name }}"
|
VERSION_TAG="${{ github.event.inputs.version || github.ref_name }}"
|
||||||
# Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
|
# Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user