Skip to content

Commit

Permalink
feat: store metadata file
Browse files Browse the repository at this point in the history
Signed-off-by: Ar Rakin <[email protected]>
  • Loading branch information
virtual-designer committed Aug 28, 2024
1 parent d318d52 commit 17c9604
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
18 changes: 12 additions & 6 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33024,6 +33024,11 @@ class GitClient {
return stdout;
});
}
pull(remote, branch) {
return __awaiter(this, void 0, void 0, function* () {
yield this.exec({ args: ["pull", remote, branch] });
});
}
getFirstCommit() {
return __awaiter(this, void 0, void 0, function* () {
const output = yield this.execWithOutput({
Expand Down Expand Up @@ -33401,6 +33406,12 @@ function run() {
let metadataFileJSON;
const gitClient = __addDisposableResource(env_1, new GitClient_1.default(gitPath), true);
const versionManager = new VersionManager_1.default();
yield gitClient.setup({
name: gitUserName,
email: gitUserEmail,
gpgKey: gitGPPKey || undefined,
});
yield gitClient.pull(gitPushRemote, gitPushBranch !== null && gitPushBranch !== void 0 ? gitPushBranch : "HEAD");
if (!createCommit) {
core.info("Creating commits is disabled.");
metadataFileJSON = {
Expand All @@ -33418,7 +33429,7 @@ function run() {
else {
metadataFileJSON = JSON.parse(yield (0, promises_1.readFile)(metadataFile, "utf-8"));
}
const commits = yield gitClient.getCommits(github.context.payload.after, metadataFileJSON.lastReadCommit);
const commits = yield gitClient.getCommits(metadataFileJSON.lastReadCommit, github.context.payload.after);
if (commits.length === 0) {
core.info("No new commits found.");
return;
Expand Down Expand Up @@ -33457,11 +33468,6 @@ function run() {
core.info(`Updated version: ${updatedVersion}`);
yield updateVersion(versionManager, updatedVersion);
core.setOutput("version", updatedVersion);
yield gitClient.setup({
name: gitUserName,
email: gitUserEmail,
gpgKey: gitGPPKey || undefined,
});
if (createCommit) {
yield (0, promises_1.writeFile)(metadataFile, JSON.stringify(metadataFileJSON, null, jsonTabWidth) + "\n");
yield gitClient.add(metadataFile);
Expand Down
4 changes: 4 additions & 0 deletions src/GitClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class GitClient implements AsyncDisposable {
return stdout;
}

public async pull(remote: string, branch: string) {
await this.exec({ args: ["pull", remote, branch] });
}

public async getFirstCommit() {
const output = await this.execWithOutput({
args: ["rev-list", "--max-parents=0", "HEAD"],
Expand Down
16 changes: 9 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ async function run() {
await using gitClient = new GitClient(gitPath);
const versionManager = new VersionManager();

await gitClient.setup({
name: gitUserName,
email: gitUserEmail,
gpgKey: gitGPPKey || undefined,
});

await gitClient.pull(gitPushRemote, gitPushBranch ?? "HEAD");

if (!createCommit) {
core.info("Creating commits is disabled.");

Expand All @@ -70,8 +78,8 @@ async function run() {
}

const commits = await gitClient.getCommits(
github.context.payload.after,
metadataFileJSON.lastReadCommit,
github.context.payload.after,
);

if (commits.length === 0) {
Expand Down Expand Up @@ -141,12 +149,6 @@ async function run() {
await updateVersion(versionManager, updatedVersion);
core.setOutput("version", updatedVersion);

await gitClient.setup({
name: gitUserName,
email: gitUserEmail,
gpgKey: gitGPPKey || undefined,
});

if (createCommit) {
await writeFile(
metadataFile,
Expand Down

0 comments on commit 17c9604

Please sign in to comment.