-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.js
138 lines (104 loc) · 3.76 KB
/
main.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2022 Andy Holmes <[email protected]>
import * as artifact from '@actions/artifact';
import * as core from '@actions/core';
import * as fs from 'fs';
import * as path from 'path';
import * as flatter from './flatter.js';
import * as utils from './utils.js';
async function includeFiles(repo) {
const files = core.getMultilineInput('upload-pages-includes');
const operations = files.map(src => {
const dest = path.join(repo, path.basename(src));
return fs.promises.copyFile(src, dest);
});
return Promise.allSettled(operations);
}
/**
* Run the action
*/
async function run() {
const manifests = core.getMultilineInput('files');
const repository = `${process.cwd()}/repo`;
core.setOutput('repository', repository);
/*
* Build the Flatpak manifests
*/
if (core.getBooleanInput('run-tests')) {
for (const manifest of manifests) {
core.startGroup(`Testing "${manifest}"...`);
try {
await flatter.checkApplication(repository, manifest);
} catch (e) {
core.warning(`Checking "${manifest}": ${e.message}`);
}
try {
await flatter.testApplication(repository, manifest);
} catch (e) {
core.setFailed(`Testing "${manifest}": ${e.message}`);
}
core.endGroup();
}
} else {
await flatter.restoreCache(repository);
for (const manifest of manifests) {
core.startGroup(`Building "${manifest}"...`);
try {
await flatter.buildApplication(repository, manifest);
} catch (e) {
core.setFailed(`Failed to build "${manifest}": ${e.message}`);
}
core.endGroup();
}
core.startGroup(`Updating metadata for repository "${repository}"...`);
try {
await flatter.updateRepositoryMetadata(repository);
} catch (e) {
core.setFailed(`Failed to update metadata for repository "${repository}": ${e.message}`);
}
core.endGroup();
await flatter.saveCache(repository);
}
if (process.exitCode === core.ExitCode.Failure)
return;
/*
* GitHub Pages Artifact
*/
if (core.getBooleanInput('upload-pages-artifact')) {
core.startGroup('Uploading GitHub Pages artifact...');
try {
// Generate a .flatpakrepo file
await flatter.generateDescription(repository);
// Copy extra files to the repository directory
await includeFiles(repository);
// Upload the repository directory as a Github Pages artifact
await utils.uploadPagesArtifact(repository);
} catch (e) {
core.setFailed(`Failed to upload artifact: ${e.message}`);
}
core.endGroup();
if (process.exitCode === core.ExitCode.Failure)
return;
}
/*
* Flatpak Bundles
*/
if (core.getBooleanInput('upload-bundles')) {
core.startGroup('Uploading Flatpak bundles...');
const artifactClient = new artifact.DefaultArtifactClient();
for (const manifest of manifests) {
try {
const filePath = await flatter.bundleApplication(repository,
manifest);
const artifactName = filePath.replace('.flatpak',
`-${core.getInput('arch')}`);
await artifactClient.uploadArtifact(artifactName, [filePath], '.');
} catch (e) {
core.setFailed(`Failed to bundle "${manifest}": ${e.message}`);
}
}
core.endGroup();
}
}
run();
export default run;