Skip to content

Commit

Permalink
Merge pull request #4 from jmckisson/release-queue
Browse files Browse the repository at this point in the history
Add release registration step to gha queue process
  • Loading branch information
vadi2 authored Jun 7, 2024
2 parents 469d640 + 7a3a07d commit 1366ba9
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
3 changes: 2 additions & 1 deletion gha_cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ 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 @@ -166,7 +167,7 @@ function processQueueFile($filepath) {
$headers[] = 'Max-Downloads: ' . strval( $data['maxdls'] );
}

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

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


$artifact_data = array(
'name' => $artifact_name,
'unzip' => $unzip,
Expand All @@ -125,6 +124,11 @@
$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: 72 additions & 0 deletions github_artifact.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,78 @@
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 1366ba9

Please sign in to comment.