forked from Gusto/semantic-release-rubygem
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
192 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import path from "node:path"; | ||
import { rename, readFile, writeFile } from "node:fs/promises"; | ||
|
||
import { execa } from "execa"; | ||
import { versionRegex } from "./common.js"; | ||
|
||
const writeVersion = async ({ versionFile, nextVersion, logger, cwd }) => { | ||
const gemVersion = nextVersion.replace("-", "."); | ||
const fullVersionPath = path.resolve(cwd, versionFile); | ||
const versionContents = await readFile(fullVersionPath, "utf8"); | ||
const newContents = versionContents.replace( | ||
versionRegex, | ||
`$1${gemVersion}$2`, | ||
); | ||
|
||
logger.log("Writing version %s to `%s`", nextVersion, versionFile); | ||
|
||
await writeFile(fullVersionPath, newContents, "utf8"); | ||
|
||
return { gemVersion }; | ||
}; | ||
|
||
const bundleInstall = async ({ | ||
updateGemfileLock, | ||
cwd, | ||
env, | ||
logger, | ||
stdout, | ||
stderr, | ||
}) => { | ||
const command = | ||
typeof updateGemfileLock === "string" | ||
? updateGemfileLock | ||
: "bundle install"; | ||
|
||
logger.log("Updating lock file with command `%s`", command); | ||
|
||
const installResult = execa.command(command, { cwd, env }); | ||
|
||
installResult.stdout.pipe(stdout, { end: false }); | ||
|
||
installResult.stderr.pipe(stderr, { end: false }); | ||
|
||
await installResult; | ||
}; | ||
|
||
const buildGem = async ({ | ||
gemspec, | ||
gemName, | ||
version, | ||
cwd, | ||
env, | ||
logger, | ||
stdout, | ||
stderr, | ||
}) => { | ||
const gemFile = `${gemName}-${version}.gem`; | ||
|
||
logger.log("Building gem `%s`", gemFile); | ||
|
||
const buildResult = execa("gem", ["build", gemspec], { cwd, env }); | ||
|
||
buildResult.stdout.pipe(stdout, { end: false }); | ||
|
||
buildResult.stderr.pipe(stderr, { end: false }); | ||
|
||
await buildResult; | ||
|
||
return gemFile; | ||
}; | ||
|
||
export default async function prepare( | ||
{ updateGemfileLock = false, gemFileDir = false }, | ||
{ nextRelease: { version }, cwd, env, logger, stdout, stderr }, | ||
{ versionFile, gemSpec, gemName }, | ||
) { | ||
const { gemVersion } = await writeVersion({ | ||
versionFile, | ||
nextVersion: version, | ||
logger, | ||
cwd, | ||
}); | ||
|
||
if (updateGemfileLock) { | ||
await bundleInstall({ | ||
updateGemfileLock, | ||
cwd, | ||
env, | ||
logger, | ||
stdout, | ||
stderr, | ||
}); | ||
} | ||
|
||
let gemFile = await buildGem({ | ||
gemSpec, | ||
gemName, | ||
version: gemVersion, | ||
cwd, | ||
env, | ||
logger, | ||
stdout, | ||
stderr, | ||
}); | ||
|
||
if (gemFileDir) { | ||
const gemFileSource = path.resolve(cwd, gemFile); | ||
|
||
const gemFileDestination = path.resolve(cwd, gemFileDir.trim(), gemFile); | ||
|
||
if (gemFileSource !== gemFileDestination) { | ||
await rename(gemFileSource, gemFileDestination); | ||
} | ||
|
||
gemFile = path.join(gemFileDir.trim(), gemFile); | ||
} | ||
|
||
return { | ||
gemFile, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { unlink } from "node:fs/promises"; | ||
import { execa } from "execa"; | ||
|
||
export default async function publish( | ||
{ gemHost, gemPublish = true, gemFileDir = false }, | ||
{ cwd, env, logger, nextRelease: { version }, stdout, stderr }, | ||
{ gemFile, gemName, credentialsFile }, | ||
) { | ||
if (gemPublish !== false) { | ||
logger.log(`Publishing version ${version} to rubygems`); | ||
|
||
const args = ["push", gemFile, "--config-file", credentialsFile]; | ||
|
||
if (gemHost) { | ||
args.push("--host", gemHost); | ||
} | ||
|
||
const pushResult = execa("gem", args, { cwd, env }); | ||
|
||
pushResult.stdout.pipe(stdout, { end: false }); | ||
|
||
pushResult.stderr.pipe(stderr, { end: false }); | ||
|
||
await pushResult; | ||
|
||
logger.log(`Published version ${version} of ${gemName} to rubygems`); | ||
} else { | ||
logger.log( | ||
`Skip publishing to rubygems because gemPublish is ${gemPublish !== false}`, | ||
); | ||
} | ||
|
||
if (gemFileDir === false) { | ||
await unlink(gemFile); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.