Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dry run option #46

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions action.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ inputs:
default: 10000
fail-mode:
description: Determines how errors that occur during mod publishing process are handled
dry-run:
description: Indicates whether to run the action in dry-run mode (without publishing anything)
outputs:
curseforge-link:
description: The link to the uploaded version on CurseForge
curseforge-data:
description: The data returned by the CurseForge API after uploading the version as JSON
modrinth-link:
description: The link to the uploaded version on Modrinth
modrinth-data:
description: The data returned by the Modrinth API after uploading the version as JSON
github-link:
description: The link to the uploaded version on GitHub
github-data:
description: The data returned by the GitHub API after uploading the version as JSON
published-to:
description: A list of platforms that the mod was published to
runs:
using: node12
main: dist/index.js
35 changes: 35 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ inputs:
description: Determines how errors that occur during mod publishing process are handled
required: false
default: ${undefined}
dry-run:
description: Indicates whether to run the action in dry-run mode (without
publishing anything)
required: false
default: ${undefined}
modrinth-files:
description: A glob of the files to upload
required: false
Expand Down Expand Up @@ -192,6 +197,11 @@ inputs:
description: Determines how errors that occur during mod publishing process are handled
required: false
default: ${undefined}
modrinth-dry-run:
description: Indicates whether to run the action in dry-run mode (without
publishing anything)
required: false
default: ${undefined}
curseforge-files:
description: A glob of the files to upload
required: false
Expand Down Expand Up @@ -256,6 +266,11 @@ inputs:
description: Determines how errors that occur during mod publishing process are handled
required: false
default: ${undefined}
curseforge-dry-run:
description: Indicates whether to run the action in dry-run mode (without
publishing anything)
required: false
default: ${undefined}
github-files:
description: A glob of the files to upload
required: false
Expand Down Expand Up @@ -320,6 +335,26 @@ inputs:
description: Determines how errors that occur during mod publishing process are handled
required: false
default: ${undefined}
github-dry-run:
description: Indicates whether to run the action in dry-run mode (without
publishing anything)
required: false
default: ${undefined}
outputs:
curseforge-link:
description: The link to the uploaded version on CurseForge
curseforge-data:
description: The data returned by the CurseForge API after uploading the version as JSON
modrinth-link:
description: The link to the uploaded version on Modrinth
modrinth-data:
description: The data returned by the Modrinth API after uploading the version as JSON
github-link:
description: The link to the uploaded version on GitHub
github-data:
description: The data returned by the GitHub API after uploading the version as JSON
published-to:
description: A list of platforms that the mod was published to
runs:
using: node12
main: dist/index.js
101 changes: 82 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23473,7 +23473,8 @@ function getEmptyLogger() {
;// CONCATENATED MODULE: ./src/publishing/publisher.ts

class Publisher {
constructor(logger) {
constructor(dryRun, logger) {
this.dryRun = dryRun !== null && dryRun !== void 0 ? dryRun : false;
this.logger = logger || getEmptyLogger();
}
validateOptions(options) {
Expand Down Expand Up @@ -24095,7 +24096,8 @@ class ModPublisher extends Publisher {
? processDependenciesInput(options.dependencies)
: (metadata === null || metadata === void 0 ? void 0 : metadata.dependencies) || [];
const uniqueDependencies = dependencies.filter((x, i, self) => !x.ignore && self.findIndex(y => y.id === x.id && y.kind === x.kind) === i);
yield this.publishMod(id, token, name, version, versionType, loaders, gameVersions, java, changelog, files, uniqueDependencies, options);
const ret = yield this.publishMod(id, token, name, version, versionType, loaders, gameVersions, java, changelog, files, uniqueDependencies, options);
return Object.assign(Object.assign({}, ret), { link: this.makeLink(ret) });
});
}
}
Expand Down Expand Up @@ -24280,15 +24282,19 @@ class GitHubPublisher extends ModPublisher {
const discussion = mapStringInput(options.discussion, null);
releaseId = yield this.createRelease(tag, name, changelog, generateChangelog, draft, prerelease, commitish, discussion, token);
}
if (!releaseId) {
if (!releaseId && !this.dryRun) {
throw new Error(`Cannot find or create release ${tag}`);
}
const existingAssets = generated ? [] : (yield octokit.rest.repos.listReleaseAssets(Object.assign(Object.assign({}, repo), { release_id: releaseId }))).data;
const existingAssets = generated || this.dryRun ? [] : (yield octokit.rest.repos.listReleaseAssets(Object.assign(Object.assign({}, repo), { release_id: releaseId }))).data;
for (const file of files) {
const existingAsset = existingAssets.find(x => x.name === file.name || x.name === file.path);
if (existingAsset) {
yield octokit.rest.repos.deleteReleaseAsset(Object.assign(Object.assign({}, repo), { asset_id: existingAsset.id }));
}
if (this.dryRun) {
this.logger.info(`Would upload asset ${file.name}`);
continue;
}
yield octokit.rest.repos.uploadReleaseAsset({
owner: repo.owner,
repo: repo.repo,
Expand All @@ -24297,6 +24303,7 @@ class GitHubPublisher extends ModPublisher {
data: yield file.getBuffer()
});
}
return (yield octokit.rest.repos.getRelease({ owner: repo.owner, repo: repo.repo, release_id: releaseId })).data;
});
}
getReleaseIdByTag(tag, token) {
Expand All @@ -24319,7 +24326,7 @@ class GitHubPublisher extends ModPublisher {
return github_publisher_awaiter(this, void 0, void 0, function* () {
const octokit = github.getOctokit(token);
try {
const response = yield octokit.rest.repos.createRelease({
const data = {
tag_name: tag,
owner: github.context.repo.owner,
repo: github.context.repo.repo,
Expand All @@ -24330,14 +24337,22 @@ class GitHubPublisher extends ModPublisher {
prerelease,
discussion_category_name: discussionCategoryName || undefined,
generate_release_notes: generateReleaseNotes,
});
};
if (this.dryRun) {
this.logger.info(`Would create GitHub release: ${JSON.stringify(data)}`);
return undefined;
}
const response = yield octokit.rest.repos.createRelease(data);
return response.status >= 200 && response.status < 300 ? response.data.id : undefined;
}
catch (_a) {
return undefined;
}
});
}
makeLink(ret) {
return ret.html_url;
}
}

// EXTERNAL MODULE: ./node_modules/form-data/lib/form_data.js
Expand Down Expand Up @@ -24617,7 +24632,11 @@ class ModrinthPublisher extends ModPublisher {
featured,
dependencies: projects
};
yield createVersion(id, data, files, token);
if (this.dryRun) {
this.logger.info(`Would upload this data to Modrinth: ${JSON.stringify(data)}`);
return;
}
return yield createVersion(id, data, files, token);
});
}
unfeatureOlderVersions(id, token, unfeatureMode, loaders, gameVersions) {
Expand All @@ -24634,6 +24653,11 @@ class ModrinthPublisher extends ModPublisher {
if (versionSubset && !olderVersion.game_versions.every(x => gameVersions.includes(x))) {
continue;
}
if (this.dryRun) {
this.logger.info(`Would unfeature ${olderVersion.id}`);
unfeaturedVersions.push(olderVersion.id);
continue;
}
if (yield modifyVersion(olderVersion.id, { featured: false }, token)) {
unfeaturedVersions.push(olderVersion.id);
}
Expand All @@ -24649,6 +24673,9 @@ class ModrinthPublisher extends ModPublisher {
}
});
}
makeLink(ret) {
return `https://modrinth.com/mod/${ret.project_id}/version/${ret.version_number}`;
}
}

;// CONCATENATED MODULE: ./src/utils/curseforge/index.ts
Expand All @@ -24666,15 +24693,17 @@ var curseforge_awaiter = (undefined && undefined.__awaiter) || function (thisArg


const curseforge_baseUrl = "https://minecraft.curseforge.com/api";
const newAPIBaseUrl = "https://api.curseforge.com";
const apiKey = "$2a$10$Eie/MzKO6B13/AhuQVs9ieNc.LV8dooZENuK2594vSW9AXAdN59vK";
class CurseForgeUploadError extends SoftError {
constructor(soft, message, info) {
super(soft, message);
this.info = info;
}
}
function fetchJsonArray(url) {
function fetchJsonArray(url, headers) {
return curseforge_awaiter(this, void 0, void 0, function* () {
const response = yield lib_default()(url);
const response = yield lib_default()(url, { headers });
if (!response.ok) {
const isSoft = response.status === 429 || response.status >= 500;
throw new SoftError(isSoft, `${response.status} (${response.statusText})`);
Expand Down Expand Up @@ -24703,11 +24732,11 @@ function getCurseForgeVersions(token) {
}
function loadCurseForgeVersions(token) {
return curseforge_awaiter(this, void 0, void 0, function* () {
const versionTypes = yield fetchJsonArray(`${curseforge_baseUrl}/game/version-types?token=${token}`);
const versionTypes = yield fetchJsonArray(`${curseforge_baseUrl}/game/version-types`, { "X-Api-Token": token });
const javaVersionTypes = versionTypes.filter(x => x.slug.startsWith("java")).map(x => x.id);
const minecraftVersionTypes = versionTypes.filter(x => x.slug.startsWith("minecraft")).map(x => x.id);
const loaderVersionTypes = versionTypes.filter(x => x.slug.startsWith("modloader")).map(x => x.id);
const versions = yield fetchJsonArray(`${curseforge_baseUrl}/game/versions?token=${token}`);
const versions = yield fetchJsonArray(`${curseforge_baseUrl}/game/versions`, { "X-Api-Token": token });
return versions.reduce((container, version) => {
if (javaVersionTypes.includes(version.gameVersionTypeID)) {
container.java.push(version);
Expand Down Expand Up @@ -24773,9 +24802,11 @@ function uploadFile(id, data, file, token) {
const form = new (form_data_default())();
form.append("file", file.getStream(), file.name);
form.append("metadata", JSON.stringify(data));
const response = yield lib_default()(`${curseforge_baseUrl}/projects/${id}/upload-file?token=${token}`, {
const response = yield lib_default()(`${curseforge_baseUrl}/projects/${id}/upload-file`, {
method: "POST",
headers: form.getHeaders(),
headers: form.getHeaders({
"X-Api-Token": token
}),
body: form
});
if (!response.ok) {
Expand All @@ -24792,6 +24823,21 @@ function uploadFile(id, data, file, token) {
return (yield response.json()).id;
});
}
function getModSlug(modId) {
return curseforge_awaiter(this, void 0, void 0, function* () {
const response = yield lib_default()(`${newAPIBaseUrl}/v1/mods/${modId}`, {
method: "GET",
headers: {
"Accept": "application/json",
"x-api-key": apiKey
}
});
if (!response.ok) {
throw new Error(`Failed to get mod slug: ${response.status} (${response.statusText})`);
}
return (yield response.json()).data.slug;
});
}

;// CONCATENATED MODULE: ./src/publishing/curseforge/curseforge-publisher.ts
var curseforge_publisher_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
Expand Down Expand Up @@ -24839,13 +24885,24 @@ class CurseForgePublisher extends ModPublisher {
gameVersions: parentFileId ? undefined : versions,
relations: (parentFileId || !projects.length) ? undefined : { projects }
};
if (this.dryRun) {
this.logger.info(`Would upload this data to CurseForge: ${JSON.stringify(data)}`);
continue;
}
const fileId = yield this.upload(id, data, file, token);
if (!parentFileId) {
parentFileId = fileId;
}
}
return {
project_slug: yield getModSlug(Number(id)),
file_id: parentFileId
};
});
}
makeLink(ret) {
return `https://www.curseforge.com/minecraft/mc-mods/${ret.project_slug}/files/${ret.file_id}`;
}
upload(id, data, file, token) {
var _a, _b;
return curseforge_publisher_awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -24878,14 +24935,14 @@ class CurseForgePublisher extends ModPublisher {


class PublisherFactory {
create(target, logger) {
create(target, dryRun, logger) {
switch (target) {
case publisher_target.GitHub:
return new GitHubPublisher(logger);
return new GitHubPublisher(dryRun, logger);
case publisher_target.Modrinth:
return new ModrinthPublisher(logger);
return new ModrinthPublisher(dryRun, logger);
case publisher_target.CurseForge:
return new CurseForgePublisher(logger);
return new CurseForgePublisher(dryRun, logger);
default:
throw new Error(`Unknown target "${publisher_target.toString(target)}"`);
}
Expand Down Expand Up @@ -25100,6 +25157,7 @@ var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argu




var FailMode;
(function (FailMode) {
FailMode[FailMode["Fail"] = 0] = "Fail";
Expand All @@ -25125,7 +25183,8 @@ function main() {
const retryAttempts = mapNumberInput(options.retryAttempts);
const retryDelay = mapNumberInput(options.retryDelay);
const failMode = mapEnumInput(options.failMode, FailMode, FailMode.Fail);
const publisher = publisherFactory.create(target, logger);
const dryRun = mapBooleanInput(options.dryRun);
const publisher = publisherFactory.create(target, dryRun, logger);
const func = {
func: () => publisher.publish(files, options),
maxAttempts: retryAttempts,
Expand All @@ -25137,7 +25196,10 @@ function main() {
};
const stopwatch = LoggingStopwatch.startNew(logger, `📤 Publishing assets to ${targetName}...`, ms => `✅ Successfully published assets to ${targetName} (in ${ms} ms)`);
try {
yield retry(func);
const publishResult = yield retry(func);
core.setOutput(`${targetName}-link`, publishResult.link);
delete publishResult.link;
core.setOutput(`${targetName}-data`, publishResult);
}
catch (e) {
switch (failMode) {
Expand All @@ -25161,6 +25223,7 @@ function main() {
else if (!errors.length) {
logger.warn("🗿 You didn't specify any targets, your assets have not been published");
}
core.setOutput("published-to", publishedTo);
if (errors.length) {
throw new AggregateError(errors);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading