Skip to content

Commit

Permalink
feat: Relax input requirements in build-crates-standalone action (#70)
Browse files Browse the repository at this point in the history
The following inputs are now non-required:
- target
- github-token
- branch
- version
  • Loading branch information
fuzzypixelz authored Mar 27, 2024
1 parent 2ea0a14 commit c40a28b
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 175 deletions.
10 changes: 6 additions & 4 deletions build-crates-standalone/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ inputs:
repo:
required: true
version:
required: true
required: false
branch:
required: true
required: false
target:
required: true
required: false
artifact-patterns:
required: true
github-token:
required: true
required: false

outputs:
artifact-id:
description: Artifact id
artifact-name:
description: Artifact name

runs:
using: node20
Expand Down
38 changes: 27 additions & 11 deletions dist/build-crates-debian-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128145,7 +128145,7 @@ var external_child_process_ = __nccwpck_require__(32081);


const MAX_BUFFER = 10 * 1024 * 1024;
function sh(cmd, options) {
function command_sh(cmd, options) {
options = options != null ? options : {};
options.env = options.env != null ? options.env : {};
options.cwd = options.cwd != null ? options.cwd : ".";
Expand Down Expand Up @@ -128206,7 +128206,7 @@ const gitEnv = {
* @returns The list of Cargo packages present in the workspace or crate.
*/
function cargo_packages(path) {
const metadataContents = sh("cargo metadata --no-deps --format-version '1'", { cwd: path });
const metadataContents = command_sh("cargo metadata --no-deps --format-version '1'", { cwd: path });
const metadata = JSON.parse(metadataContents);
const result = [];
for (const elem of metadata.packages) {
Expand Down Expand Up @@ -128393,14 +128393,30 @@ async function installBinaryCached(name) {
// failure
const hit = await cache.restoreCache(paths, key);
if (hit == undefined) {
sh(`cargo +stable install ${name} --force`);
command_sh(`cargo +stable install ${name} --force`);
await cache.saveCache(paths, key);
}
}
else {
sh(`cargo +stable install ${name}`);
command_sh(`cargo +stable install ${name}`);
}
}
async function build(path, target) {
const crossContents = await fs.readFile(join(path, "Cross.toml"), "utf-8");
const crossManifest = toml.parse(crossContents);
if (target == undefined) {
target ??= hostTarget();
}
else {
sh(`rustup target add ${target}`, { cwd: path });
}
const command = target in crossManifest ? ["cross"] : ["cargo"];
command.concat("cross", "build", "--release", "--bins", "--lib", "--target", target);
sh(command.join(" "), { cwd: path });
}
function hostTarget() {
return sh("rustc --version --verbose").match(/host: (?<target>.*)/).groups["target"];
}
async function loadTOML(path) {
const contents = await promises_.readFile(path, "utf-8");
return parse(contents);
Expand Down Expand Up @@ -128430,10 +128446,10 @@ function fromFiles(output, ...files) {
}
const platform = external_os_.platform();
if (platform == "linux" || platform == "darwin") {
sh(`zip --verbose --junk-paths ${output} ${files.join(" ")}`);
command_sh(`zip --verbose --junk-paths ${output} ${files.join(" ")}`);
}
else if (external_os_.platform() == "win32") {
sh(`7z -y a ${output} ${files.join(" ")}`);
command_sh(`7z -y a ${output} ${files.join(" ")}`);
}
}

Expand Down Expand Up @@ -128467,24 +128483,24 @@ async function main(input) {
await installBinaryCached("cross");
const repo = input.repo.split("/")[1];
const remote = `https://${input.githubToken}@github.com/${input.repo}.git`;
sh(`git clone --recursive --branch ${input.branch} --single-branch ${remote}`);
command_sh(`git clone --recursive --branch ${input.branch} --single-branch ${remote}`);
const crossContents = await promises_.readFile(external_path_default().join(repo, "Cross.toml"), "utf-8");
const crossManifest = parse(crossContents);
sh(`rustup target add ${input.target}`, { cwd: repo });
command_sh(`rustup target add ${input.target}`, { cwd: repo });
if (input.target in crossManifest.target) {
sh(`cross build --release --bins --lib --target ${input.target}`, {
command_sh(`cross build --release --bins --lib --target ${input.target}`, {
cwd: repo,
});
}
else {
sh(`cargo build --release --bins --lib --target ${input.target}`, {
command_sh(`cargo build --release --bins --lib --target ${input.target}`, {
cwd: repo,
});
}
const packages = await packagesDebian(repo);
lib_core.info(`Building ${packages.map(p => p.name).join(", ")}`);
for (const package_ of packages) {
sh(`cargo deb --no-build --no-strip \
command_sh(`cargo deb --no-build --no-strip \
--target ${input.target} \
--package ${package_.name} \
--deb-version ${input.version}`, {
Expand Down
82 changes: 52 additions & 30 deletions dist/build-crates-standalone-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127141,7 +127141,7 @@ utils.walkdir = function(dirpath, base, callback) {
"use strict";
__nccwpck_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__nccwpck_require__.r(__webpack_exports__);
/* harmony import */ var _build_crates_standalone__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(77100);
/* harmony import */ var _build_crates_standalone__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(62010);

await (0,_build_crates_standalone__WEBPACK_IMPORTED_MODULE_0__/* .main */ .DH)((0,_build_crates_standalone__WEBPACK_IMPORTED_MODULE_0__/* .setup */ .cY)());

Expand All @@ -127150,7 +127150,7 @@ __webpack_async_result__();

/***/ }),

/***/ 77100:
/***/ 62010:
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {

"use strict";
Expand All @@ -127171,6 +127171,10 @@ var external_path_ = __nccwpck_require__(71017);
var lib_core = __nccwpck_require__(42186);
// EXTERNAL MODULE: ./node_modules/@actions/artifact/lib/artifact.js
var artifact = __nccwpck_require__(79450);
// EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(22037);
// EXTERNAL MODULE: ./node_modules/@actions/cache/lib/cache.js
var cache = __nccwpck_require__(27799);
;// CONCATENATED MODULE: ./node_modules/smol-toml/dist/error.js
/*!
* Copyright (c) Squirrel Chat et al., All rights reserved.
Expand Down Expand Up @@ -128134,10 +128138,6 @@ function parse(toml) {



// EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(22037);
// EXTERNAL MODULE: ./node_modules/@actions/cache/lib/cache.js
var cache = __nccwpck_require__(27799);
// EXTERNAL MODULE: external "child_process"
var external_child_process_ = __nccwpck_require__(32081);
;// CONCATENATED MODULE: ./src/command.ts
Expand Down Expand Up @@ -128400,6 +128400,22 @@ async function installBinaryCached(name) {
command_sh(`cargo +stable install ${name}`);
}
}
async function build(path, target) {
const crossContents = await promises_.readFile((0,external_path_.join)(path, "Cross.toml"), "utf-8");
const crossManifest = parse(crossContents);
if (target == undefined) {
target ??= hostTarget();
}
else {
command_sh(`rustup target add ${target}`, { cwd: path });
}
const command = target in crossManifest ? ["cross"] : ["cargo"];
command.concat("cross", "build", "--release", "--bins", "--lib", "--target", target);
command_sh(command.join(" "), { cwd: path });
}
function hostTarget() {
return command_sh("rustc --version --verbose").match(/host: (?<target>.*)/).groups["target"];
}
async function loadTOML(path) {
const contents = await fs.readFile(path, "utf-8");
return toml.parse(contents);
Expand Down Expand Up @@ -128436,8 +128452,25 @@ function fromFiles(output, ...files) {
}
}

;// CONCATENATED MODULE: ./src/build-crates-standalone.ts
;// CONCATENATED MODULE: ./src/git.ts

function cloneFromGitHub(repo, options) {
const remote = options.token == undefined ? `https://github.com/${repo}.git` : `https://${options.token}@github.com/${repo}.git`;
const command = ["git", "clone", "--recursive", "--single-branch"];
if (options.branch != undefined) {
command.concat("--branch", options.branch);
}
command.concat(remote);
if (options.path != undefined) {
command.concat(options.path);
}
command_sh(command.join(" "));
}
function describe(path = process.cwd()) {
return command_sh("git describe", { cwd: path });
}

;// CONCATENATED MODULE: ./src/build-crates-standalone.ts



Expand All @@ -128448,43 +128481,32 @@ function fromFiles(output, ...files) {
const build_crates_standalone_artifact = new artifact.DefaultArtifactClient();
function setup() {
const repo = lib_core.getInput("repo", { required: true });
const version = lib_core.getInput("version", { required: true });
const branch = lib_core.getInput("branch", { required: true });
const target = lib_core.getInput("target", { required: true });
const version = lib_core.getInput("version");
const branch = lib_core.getInput("branch");
const target = lib_core.getInput("target");
const artifactPatterns = lib_core.getInput("artifact-patterns", { required: true });
const githubToken = lib_core.getInput("github-token", { required: true });
const githubToken = lib_core.getInput("github-token");
return {
repo,
version,
branch,
target,
version: version == "" ? undefined : version,
branch: branch == "" ? undefined : branch,
target: target == "" ? undefined : target,
artifactRegExp: new RegExp(artifactPatterns.split("\n").join("|")),
githubToken,
githubToken: githubToken == "" ? undefined : githubToken,
};
}
async function main(input) {
try {
await installBinaryCached("cross");
const repo = input.repo.split("/")[1];
const remote = `https://${input.githubToken}@github.com/${input.repo}.git`;
command_sh(`git clone --recursive --branch ${input.branch} --single-branch ${remote}`);
const crossContents = await promises_.readFile(external_path_.join(repo, "Cross.toml"), "utf-8");
const crossManifest = parse(crossContents);
command_sh(`rustup target add ${input.target}`, { cwd: repo });
if (input.target in crossManifest.target) {
command_sh(`cross build --release --bins --lib --target ${input.target}`, {
cwd: repo,
});
}
else {
command_sh(`cargo build --release --bins --lib --target ${input.target}`, {
cwd: repo,
});
}
cloneFromGitHub(input.repo, { branch: input.branch, token: input.githubToken });
input.version ??= describe(repo);
await build(repo, input.target);
const output = artifactName(repo, input.version, input.target);
await fromDirectory(output, external_path_.join(repo, "target", input.target, "release"), input.artifactRegExp);
const { id } = await build_crates_standalone_artifact.uploadArtifact(output, [output], process.cwd());
lib_core.setOutput("artifact-id", id);
lib_core.setOutput("artifact-name", output);
await cleanup(input);
}
catch (error) {
Expand Down
16 changes: 16 additions & 0 deletions dist/bump-crates-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -82259,6 +82259,22 @@ async function installBinaryCached(name) {
sh(`cargo +stable install ${name}`);
}
}
async function build(path, target) {
const crossContents = await fs.readFile(join(path, "Cross.toml"), "utf-8");
const crossManifest = toml.parse(crossContents);
if (target == undefined) {
target ??= hostTarget();
}
else {
sh(`rustup target add ${target}`, { cwd: path });
}
const command = target in crossManifest ? ["cross"] : ["cargo"];
command.concat("cross", "build", "--release", "--bins", "--lib", "--target", target);
sh(command.join(" "), { cwd: path });
}
function hostTarget() {
return sh("rustc --version --verbose").match(/host: (?<target>.*)/).groups["target"];
}
async function loadTOML(path) {
const contents = await promises_namespaceObject.readFile(path, "utf-8");
return parse(contents);
Expand Down
32 changes: 24 additions & 8 deletions dist/publish-crates-cargo-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -82003,7 +82003,7 @@ function stringify(obj) {


const MAX_BUFFER = 10 * 1024 * 1024;
function sh(cmd, options) {
function command_sh(cmd, options) {
options = options != null ? options : {};
options.env = options.env != null ? options.env : {};
options.cwd = options.cwd != null ? options.cwd : ".";
Expand Down Expand Up @@ -82064,7 +82064,7 @@ const gitEnv = {
* @returns The list of Cargo packages present in the workspace or crate.
*/
function cargo_packages(path) {
const metadataContents = sh("cargo metadata --no-deps --format-version '1'", { cwd: path });
const metadataContents = command_sh("cargo metadata --no-deps --format-version '1'", { cwd: path });
const metadata = JSON.parse(metadataContents);
const result = [];
for (const elem of metadata.packages) {
Expand Down Expand Up @@ -82251,14 +82251,30 @@ async function installBinaryCached(name) {
// failure
const hit = await cache.restoreCache(paths, key);
if (hit == undefined) {
sh(`cargo +stable install ${name} --force`);
command_sh(`cargo +stable install ${name} --force`);
await cache.saveCache(paths, key);
}
}
else {
sh(`cargo +stable install ${name}`);
command_sh(`cargo +stable install ${name}`);
}
}
async function build(path, target) {
const crossContents = await fs.readFile(join(path, "Cross.toml"), "utf-8");
const crossManifest = toml.parse(crossContents);
if (target == undefined) {
target ??= hostTarget();
}
else {
sh(`rustup target add ${target}`, { cwd: path });
}
const command = target in crossManifest ? ["cross"] : ["cargo"];
command.concat("cross", "build", "--release", "--bins", "--lib", "--target", target);
sh(command.join(" "), { cwd: path });
}
function hostTarget() {
return sh("rustc --version --verbose").match(/host: (?<target>.*)/).groups["target"];
}
async function loadTOML(path) {
const contents = await promises_namespaceObject.readFile(path, "utf-8");
return parse(contents);
Expand Down Expand Up @@ -82361,10 +82377,10 @@ async function cleanup(input, registry) {
function clone(input, repo, branch) {
const remote = `https://${input.githubToken}@github.com/${repo}.git`;
if (branch == undefined) {
sh(`git clone --recursive ${remote}`);
command_sh(`git clone --recursive ${remote}`);
}
else {
sh(`git clone --recursive --single-branch --branch ${branch} ${remote}`);
command_sh(`git clone --recursive --single-branch --branch ${branch} ${remote}`);
}
}
async function deleteRepos(input) {
Expand Down Expand Up @@ -82405,10 +82421,10 @@ function publish(path, env) {
};
for (const package_ of packagesOrdered(path)) {
if (package_.publish == undefined || package_.publish) {
sh(`cargo publish --manifest-path ${package_.manifestPath}`, options);
command_sh(`cargo publish --manifest-path ${package_.manifestPath}`, options);
}
}
sh("cargo clean", options);
command_sh("cargo clean", options);
}


Expand Down
16 changes: 16 additions & 0 deletions dist/publish-crates-debian-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128423,6 +128423,22 @@ async function installBinaryCached(name) {
sh(`cargo +stable install ${name}`);
}
}
async function build(path, target) {
const crossContents = await fs.readFile(join(path, "Cross.toml"), "utf-8");
const crossManifest = toml.parse(crossContents);
if (target == undefined) {
target ??= hostTarget();
}
else {
sh(`rustup target add ${target}`, { cwd: path });
}
const command = target in crossManifest ? ["cross"] : ["cargo"];
command.concat("cross", "build", "--release", "--bins", "--lib", "--target", target);
sh(command.join(" "), { cwd: path });
}
function hostTarget() {
return sh("rustc --version --verbose").match(/host: (?<target>.*)/).groups["target"];
}
async function loadTOML(path) {
const contents = await fs.readFile(path, "utf-8");
return toml.parse(contents);
Expand Down
Loading

0 comments on commit c40a28b

Please sign in to comment.