-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartifacts.ts
More file actions
71 lines (60 loc) · 2.17 KB
/
artifacts.ts
File metadata and controls
71 lines (60 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type { SimpleGit } from 'simple-git';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import type { Tags } from './tags';
import type { Configuration } from '@/configuration';
export class Artifacts {
constructor(
private readonly git: Readonly<SimpleGit>,
private readonly tags: Readonly<Tags>,
private readonly configuration: Readonly<Configuration>
) {}
public async update(): Promise<void> {
core.startGroup('📦 Creating artifacts');
try {
await this.compile();
this.configuration.isTag && (await this.tags.collect());
await this.deploy();
this.configuration.isTag && (await this.tags.move());
} catch (error: unknown) {
core.endGroup();
const message = String(error instanceof Error ? error.message : error);
throw new Error(`Failed creating artifacts: ${message}`);
}
core.endGroup();
}
private async compile(): Promise<void> {
const result = await exec.exec(this.configuration.command);
if (result !== 0) {
throw new Error('Failing to compile artifacts. Process exited with non-zero code.');
}
}
private async deploy(): Promise<void> {
await this.add();
await this.commit();
await this.push();
}
private async add(): Promise<void> {
const result = await exec.exec(`git add -f ${this.configuration.targetDir}/*`);
if (result !== 0) {
throw new Error('Failing to git-add the artifacts build. Process exited with non-zero code.');
}
}
private async commit(): Promise<void> {
const commitResult = await this.git.commit('🚀 Build Artifacts');
core.info(`Committed changes: ${commitResult.summary.changes}`);
core.info(`Committed insertions: ${commitResult.summary.insertions}`);
core.info(`Committed deletions: ${commitResult.summary.deletions}`);
}
private async push(): Promise<void> {
if (!this.configuration.canPush) {
core.info('Skipping pushing artifacts.');
return;
}
const pushingResult = await this.git.push();
const messages = pushingResult.remoteMessages.all.join('\n');
if (messages) {
core.info(`Pushed artifacts with messages: ${messages}`);
}
}
}