Skip to content

Commit 9880fa1

Browse files
committed
chore: refactor to simplify usage with single docker image
works with in-branch flow on gitlab
1 parent 22427c3 commit 9880fa1

File tree

14 files changed

+91
-123
lines changed

14 files changed

+91
-123
lines changed

.github/workflows/docker.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,11 @@ jobs:
2424
uses: docker/setup-qemu-action@v3
2525
- name: Set up Docker Buildx
2626
uses: docker/setup-buildx-action@v3
27-
# - name: Build BitBucket image and push
28-
# uses: docker/build-push-action@v6
29-
# with:
30-
# push: true
31-
# platforms: linux/amd64
32-
# context: ./action
33-
# file: ./action/Dockerfile-bitbucket
34-
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/bitbucket:latest
35-
- name: Build Gitlab image and push
27+
- name: Build BitBucket image and push
3628
uses: docker/build-push-action@v6
3729
with:
3830
push: true
3931
platforms: linux/amd64
4032
context: ./action
41-
file: ./action/Dockerfile-gitlab
42-
tags: ${{ secrets.DOCKERHUB_USERNAME }}/gitlab:v8
33+
file: ./action/Dockerfile
34+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ci:v16

action/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ RUN npm install -g pnpm && pnpm install
1919
RUN pnpm build
2020

2121
# Run the Node.js / TypeScript application
22-
ENTRYPOINT ["node", "/app/build/github.js"]
22+
ENTRYPOINT ["node", "/app/build/index.js"]

action/Dockerfile-bitbucket

Lines changed: 0 additions & 22 deletions
This file was deleted.

action/Dockerfile-gitlab

Lines changed: 0 additions & 22 deletions
This file was deleted.

action/src/bitbucket.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

action/src/flows/_base.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Ora } from "ora";
22
import { PlatformKit } from "../platforms/_base.js";
33

44
export interface IIntegrationFlow {
5-
preRun?(): Promise<void>;
5+
preRun?(): Promise<boolean>;
66
run(): Promise<boolean>;
77
postRun?(): Promise<void>;
88
}
@@ -15,3 +15,8 @@ export abstract class IntegrationFlow implements IIntegrationFlow {
1515

1616
abstract run(): Promise<boolean>;
1717
}
18+
19+
export const gitConfig = {
20+
userName: "Replexica",
21+
userEmail: "support@replexica.com",
22+
};

action/src/flows/in-branch.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { execSync } from "child_process";
2-
import { IntegrationFlow } from "./_base.js";
2+
import { gitConfig, IntegrationFlow } from "./_base.js";
33

44
export class InBranchFlow extends IntegrationFlow {
55
async preRun() {
66
this.ora.start("Configuring git");
7-
this.configureGit();
7+
const canContinue = this.configureGit();
88
this.ora.succeed("Git configured");
9+
10+
return canContinue;
911
}
1012

1113
async run() {
@@ -17,6 +19,9 @@ export class InBranchFlow extends IntegrationFlow {
1719
const hasChanges = this.checkCommitableChanges();
1820
this.ora.succeed(hasChanges ? "Changes detected" : "No changes detected");
1921

22+
execSync(`git status`, { stdio: "inherit" });
23+
execSync(`git branch`, { stdio: "inherit" });
24+
2025
if (hasChanges) {
2126
this.ora.start("Committing changes");
2227
execSync(`git add .`, { stdio: "inherit" });
@@ -25,8 +30,13 @@ export class InBranchFlow extends IntegrationFlow {
2530
});
2631
this.ora.succeed("Changes committed");
2732

33+
execSync(`git remote -v`, { stdio: "inherit" });
34+
2835
this.ora.start("Pushing changes to remote");
29-
execSync(`git push origin HEAD --force`, { stdio: "inherit" });
36+
execSync(
37+
`git push origin ${this.platformKit.platformConfig.baseBranchName} --force`,
38+
{ stdio: "inherit" },
39+
);
3040
this.ora.succeed("Changes pushed to remote");
3141
}
3242

@@ -49,9 +59,20 @@ export class InBranchFlow extends IntegrationFlow {
4959
}
5060

5161
private configureGit() {
52-
execSync('git config --global user.name "Replexica"');
53-
execSync('git config --global user.email "support@replexica.com"');
62+
const currentAuthor = `${gitConfig.userName} <${gitConfig.userEmail}>`;
63+
const authorOfLastCommit = execSync(
64+
`git log -1 --pretty=format:'%an <%ae>'`,
65+
).toString();
66+
if (authorOfLastCommit === currentAuthor) {
67+
this.ora.fail(`The action will not run on commits by ${currentAuthor}`);
68+
return false;
69+
}
70+
71+
execSync(`git config --global user.name "${gitConfig.userName}"`);
72+
execSync(`git config --global user.email "${gitConfig.userEmail}"`);
5473
execSync(`git config --global safe.directory ${process.cwd()}`);
5574
this.platformKit?.gitConfig();
75+
76+
return true;
5677
}
5778
}

action/src/flows/pull-request.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ export class PullRequestFlow extends InBranchFlow {
55
private i18nBranchName?: string;
66

77
async preRun() {
8-
await super.preRun?.();
8+
const canContinue = await super.preRun?.();
9+
if (!canContinue) {
10+
return false;
11+
}
912

1013
this.ora.start("Calculating automated branch name");
1114
this.i18nBranchName = this.calculatePrBranchName();
@@ -32,6 +35,8 @@ export class PullRequestFlow extends InBranchFlow {
3235
this.createI18nBranch(this.i18nBranchName);
3336
this.ora.succeed(`Created branch ${this.i18nBranchName}`);
3437
}
38+
39+
return true;
3540
}
3641

3742
async postRun() {

action/src/github.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

action/src/gitlab.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)