Skip to content

Commit

Permalink
transpile ts files for 1.0.2 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
SiqiLu committed Oct 22, 2020
1 parent 5afde0a commit e1c7b16
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
11 changes: 7 additions & 4 deletions lib/Bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class Bump {
this.packageVersionRex = /<PackageVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/PackageVersion>/i;
this.assemblyVersionRex = /<AssemblyVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/AssemblyVersion>/i;
this.fileVersionRex = /<FileVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/FileVersion>/i;
this.informationalVersionRex = /<InformationlVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/InformationlVersion>/gi;
this.informationalVersionRex = /<InformationalVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/InformationalVersion>/gi;
this.versions = new Map([
["Version", this.versionRex],
["PackageVersion", this.packageVersionRex],
["AssemblyVersionRex", this.assemblyVersionRex],
["FileVersionRex", this.fileVersionRex],
["InformationalVersionRex", this.informationalVersionRex],
["AssemblyVersion", this.assemblyVersionRex],
["FileVersion", this.fileVersionRex],
["InformationalVersion", this.informationalVersionRex],
]);
this.optionsRex = /(--(major)|--(minor)|--(patch))/i;
this.file = file;
Expand All @@ -51,6 +51,7 @@ class Bump {
const originContent = fs.readFileSync(this.file, "utf8").toString();
core.debug(`Bump.bump originContent: ${originContent}`);
var bumppedContent = originContent.trim();
var modified = false;
this.versions.forEach((v, k) => {
const matches = v.exec(bumppedContent);
core.debug(`Bump.bump matches: ${JSON.stringify(matches)}`);
Expand All @@ -65,13 +66,15 @@ class Bump {
core.debug(`Bump.bump ${k}.bumppedMatch: ${bumppedMatch}`);
bumppedContent = bumppedContent.replace(originMatch, bumppedMatch);
core.info(`"${this.file}" bump ${k} to "${bumppedVersion}" from "${originVersion}".`);
modified = true;
}
else {
core.info(`Can not find ${k} information from "${this.file}".`);
}
});
core.debug(`Bump.bump bumppedContent: ${bumppedContent}`);
fs.writeFileSync(this.file, bumppedContent, "utf8");
return modified;
}
static bumpVersion(matches, options) {
if (options === "--major") {
Expand Down
6 changes: 4 additions & 2 deletions lib/Commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.commit = void 0;
const core = __importStar(require("@actions/core"));
const exec_1 = require("@actions/exec");
exports.commit = (versionFiles, eventContext, message, githubToken) => __awaiter(void 0, void 0, void 0, function* () {
exports.commit = (filesToCommit, eventContext, message, githubToken) => __awaiter(void 0, void 0, void 0, function* () {
try {
core.info(`Committing changes with message "${message}".`);
const remoteRepository = `https://${eventContext.githubActor}:${githubToken}@github.com/${eventContext.githubRepository}.git`;
Expand All @@ -54,7 +54,9 @@ exports.commit = (versionFiles, eventContext, message, githubToken) => __awaiter
// await exec('git', ['show-ref'], options)
// await exec('git', ['branch', '--verbose'], options)
// await exec("git", ["add", "-A"], options);
for (const file of versionFiles) {
// Issue #5
// Only commit changed files
for (const file of filesToCommit) {
core.info(`git add "${file}"`);
yield exec_1.exec("git", ["add", file], options);
}
Expand Down
8 changes: 5 additions & 3 deletions lib/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ function bumpVersion() {
// 替换 version file 中的 version
const versionFiles = yield actionContext.getVersionFiles();
core.info(`VersionFiles: ${JSON.stringify(versionFiles)}`);
versionFiles.forEach(file => {
// Issue #5
// Only commit changed files
var bumpedFiles = versionFiles.filter(file => {
const bump = new Bump_1.Bump(file, actionContext.headCommit.message);
bump.bump();
return bump.bump();
});
// 推动更改
if (actionContext.needPushChanges && actionContext.githubToken) {
yield Commit_1.commit(versionFiles, actionContext, "Bump versions by dotnet-bump-version.", actionContext.githubToken);
yield Commit_1.commit(bumpedFiles, actionContext, "Bump versions by dotnet-bump-version.", actionContext.githubToken);
}
core.debug("Finishing: dotnet-bump-version");
});
Expand Down
8 changes: 4 additions & 4 deletions src/Bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export class Bump {
readonly packageVersionRex = /<PackageVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/PackageVersion>/i;
readonly assemblyVersionRex = /<AssemblyVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/AssemblyVersion>/i;
readonly fileVersionRex = /<FileVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/FileVersion>/i;
readonly informationalVersionRex = /<InformationlVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/InformationlVersion>/gi;
readonly informationalVersionRex = /<InformationalVersion>[\S]*(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))[\S]*<\/InformationalVersion>/gi;

readonly versions = new Map([
["Version", this.versionRex],
["PackageVersion", this.packageVersionRex],
["AssemblyVersionRex", this.assemblyVersionRex],
["FileVersionRex", this.fileVersionRex],
["InformationalVersionRex", this.informationalVersionRex],
["AssemblyVersion", this.assemblyVersionRex],
["FileVersion", this.fileVersionRex],
["InformationalVersion", this.informationalVersionRex],
]);

readonly optionsRex = /(--(major)|--(minor)|--(patch))/i;
Expand Down

0 comments on commit e1c7b16

Please sign in to comment.