Skip to content

Commit

Permalink
Merge pull request #5 from jmckisson/release-queue
Browse files Browse the repository at this point in the history
Revert "add release registration"
  • Loading branch information
vadi2 committed Jun 9, 2024
2 parents 1366ba9 + 89a4451 commit 09ded84
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 79 deletions.
3 changes: 1 addition & 2 deletions gha_cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ function processQueueFile($filepath) {
$queue_url = SITE_URL . 'github_artifact.php';
$headers = array();
$unzip = ($data['unzip']) ? '1' : '0';
$release = ($data['release']) ? '1' : '0';

if (isset($data['id'])) {
$id = $data['id'];
Expand All @@ -167,7 +166,7 @@ function processQueueFile($filepath) {
$headers[] = 'Max-Downloads: ' . strval( $data['maxdls'] );
}

$url = $queue_url . '?id=' . strval($id) . '&unzip=' . $unzip . '&release=' . $release;
$url = $queue_url . '?id=' . strval($id) . '&unzip=' . $unzip;

if ( processSnapshotFetch( $url, $headers ) ) {
unlink($filepath);
Expand Down
6 changes: 1 addition & 5 deletions gha_queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
}
}


$artifact_data = array(
'name' => $artifact_name,
'unzip' => $unzip,
Expand All @@ -124,11 +125,6 @@
$artifact_data['maxdls'] = $maxdls;
}

// Ensure that the artifact being queued is marked as a release in the output json
if ( isset($_REQUEST['release']) ) {
$artifact_data['release'] = true;
}

$queue_json = json_encode($artifact_data);
if ( false !== file_put_contents($artifact_queue_file, $queue_json, LOCK_EX) ) {
echo('Artifact enqueued');
Expand Down
72 changes: 0 additions & 72 deletions github_artifact.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,78 +171,6 @@
ExitFailedRequest("Failed to save {$basename} - Bad Extension\n");
}

function parseFilename($filename) {
$pattern = '/Mudlet-(\d+\.\d+\.\d+)-(windows-\d+)-installer\.exe/';
if (preg_match($pattern, $filename, $matches)) {
$version = $matches[1];
$arch = $matches[2];
return [
'version' => $version,
'arch' => $arch
];
} else {
return false;
}
}

if ( isset($_REQUEST['release'] && !empty($_REQUEST['release'] && $_REQUEST['release'] == '1') ) {
echo("Release detected\n");

// The file with basename exists in the files subdirectory of the ci-snapshots home
$cpCommand = "cp files/.$basename ".MUDLET_DEPLOY_PATH;
$returnVar = 0;
exec($cpCommand, $output, $returnVar);
if ($returnVar !== 0) {
ExitFailedRequest("Error copying file: " . implode("\n", $output));
}

$result = parseFilename($basename);
if ($result) {
$version = $result['version'];
$arch = $result['arch'];
} else {
ExitFailedRequest("Failed to parse filename for version and arch");
}

$deployUrl = "https://www.mudlet.org/wp-content/files/$basename";

// Calculate SHA256 checksum
$sha256sum = trim(exec("shasum -a 256 " . "files/".$basename . " | awk '{print $1}'"));

echo("SHA: ".$sha256sum."\n");

// Prepare cURL request
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://www.mudlet.org/wp-content/plugins/wp-downloadmanager/download-add.php',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'file_type' => 2,
'file_remote' => $deployUrl,
'file_name' => "Mudlet-{$version} (windows-{$arch})",
'file_des' => "sha256: {$sha256sum}",
'file_cat' => 0,
'file_permission' => -1,
'output' => 'json',
'do' => 'Add File'
],
CURLOPT_HTTPHEADER => [
"x-wp-download-token: ".X_WP_DOWNLOAD_TOKEN
]
]);

$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($httpCode != 200) {
ExitFailedResponse("Error adding file: " . $response);
}

echo "File uploaded and added successfully.\n";
}

if (getSnapshotDirectorySize() >= MAX_CAPACITY_BYTES && MAX_CAPACITY_DELETE_OLDEST == true) {
$targetSize = filesize($dl_tmpname);
$clearedSize = 0;
Expand Down

0 comments on commit 09ded84

Please sign in to comment.