Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/jest.config.ts → jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module.exports = {
preset: 'ts-jest',
moduleDirectories: ['node_modules'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/../src/$1',
'^@model/(.*)$': '<rootDir>/../src/model/$1',
'^@/(.*)$': '<rootDir>/src/$1',
'^@model/(.*)$': '<rootDir>/src/model/$1',
},
setupFilesAfterEnv: ['<rootDir>/setup-tests.ts'],
setupFilesAfterEnv: ['<rootDir>/tests/setup-tests.ts'],
maxWorkers: 8,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"lint": "eslint ./src --ext .ts",
"lint:test": "eslint --config ./tests/.eslintrc.json ./tests --ext .ts",
"prepare": "husky",
"test": "jest --config ./tests/jest.config.ts",
"test": "jest",
"qa": "yarn lint && yarn lint:test && yarn test"
}
}
9 changes: 8 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export class Configuration {
private static readonly COMMAND = 'yarn build';
private static readonly TARGET_DIR = './build';

constructor(private readonly read: typeof getInput) {}
constructor(
private readonly read: typeof getInput,
private readonly env: Readonly<NodeJS.ProcessEnv>
) {}

public get command(): string {
return this.read('command') || Configuration.COMMAND;
Expand All @@ -13,4 +16,8 @@ export class Configuration {
public get targetDir(): string {
return this.read('target-dir') || Configuration.TARGET_DIR;
}

public get isTag(): boolean {
return (this.env['GITHUB_REF'] ?? '').startsWith('refs/tags/');
}
}
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import { createGit } from './create-git';
import { Configuration } from './configuration';

async function main(): Promise<void> {
const configuration = new Configuration(core.getInput.bind(core));
const configuration = new Configuration(core.getInput.bind(core), process.env);

const git = await createGit();
const tags = new Tags(git);
const artifacts = new Artifacts(git, tags, configuration);
const temporaryBranch = new TemporaryBranch(git);
const { isTag } = configuration;

Promise.resolve()
.then(() => temporaryBranch.create())
.then(() => (isTag ? temporaryBranch.create() : null))
.then(() => artifacts.update())
.then(() => temporaryBranch.delete())
.then(() => (isTag ? temporaryBranch.delete() : null))

.catch((error) => {
core.setFailed(`Failed to create and push artifacts: ${error}`);
Expand Down
4 changes: 2 additions & 2 deletions src/model/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export class Artifacts {

try {
await this.compile();
await this.tags.collect();
this.configuration.isTag && (await this.tags.collect());
await this.deploy();
await this.tags.move();
this.configuration.isTag && (await this.tags.move());
} catch (error: unknown) {
core.endGroup();
const message = String(error instanceof Error ? error.message : error);
Expand Down
2 changes: 1 addition & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
},
"rootDir": "./"
},
"include": ["../src/**/*.ts", "./unit/**/*.ts", "jest.config.ts", "setup-tests.ts"],
"include": ["../src/**/*.ts", "./unit/**/*.ts", "../jest.config.ts", "setup-tests.ts"],
"exclude": ["../node_modules"]
}
43 changes: 41 additions & 2 deletions tests/unit/model/artifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,49 @@ describe('Artifacts', () => {

expect(collect.mock.invocationCallOrder[0]).toBeLessThan(move.mock.invocationCallOrder[0] ?? 0);
});

it('Do not perform any tasks associated to tags when the action is not running for tags', async () => {
const git = fromPartial<SimpleGit>({
commit: jest.fn(() =>
Promise.resolve({ summary: { changes: 0, insertions: 0, deletions: 0 } })
),
push: jest.fn(() =>
Promise.resolve({
remoteMessages: {
all: [''],
},
})
),
});

const collect = jest.fn();
const move = jest.fn();
const tags = fromPartial<Tags>({ collect, move });

const _configuration = configuration({
GITHUB_REF: 'refs/heads/main',
});
const artifacts = new Artifacts(git, tags, _configuration);

jest.mocked(exec).mockImplementation(async () => Promise.resolve(0));

await artifacts.update();

expect(collect).not.toHaveBeenCalled();
expect(move).not.toHaveBeenCalled();
});
});

function configuration(): Configuration {
return new Configuration(stubGetInput());
function configuration(env?: Readonly<NodeJS.ProcessEnv>): Configuration {
let _env = env;

if (!_env) {
_env = {
GITHUB_REF: 'refs/tags/v1.0.0',
};
}

return new Configuration(stubGetInput(), _env);
}

function stubGetInput(): typeof getInput {
Expand Down