Skip to content

Commit f4b796b

Browse files
committed
Resolve conflict
2 parents dcc731a + 574d52a commit f4b796b

7 files changed

Lines changed: 89 additions & 35 deletions

File tree

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'Upload a Build Artifact to Nextcloud'
22
description: 'Upload a build artifact to Nextcloud that can be used by subsequent workflow steps'
33
author: 'Trym Lund Flogard'
4-
inputs:
4+
inputs:
55
name:
66
description: 'Artifact name'
77
default: 'artifact'
@@ -17,6 +17,10 @@ inputs:
1717
nextcloud-password:
1818
description: 'The password for the nextcloud user'
1919
required: true
20+
no-zip:
21+
description: 'Whether to zip files. Incompatible with uploading multiple files.'
22+
default: false
23+
required: false
2024
if-no-files-found:
2125
description: >
2226
The desired behavior if no files are found using the provided path.

dist/index.js

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
88

99
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1010
if (k2 === undefined) k2 = k;
11-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11+
var desc = Object.getOwnPropertyDescriptor(m, k);
12+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13+
desc = { enumerable: true, get: function() { return m[k]; } };
14+
}
15+
Object.defineProperty(o, k2, desc);
1216
}) : (function(o, m, k, k2) {
1317
if (k2 === undefined) k2 = k;
1418
o[k2] = m[k];
@@ -49,6 +53,9 @@ class ActionInputs {
4953
get Token() {
5054
return core.getInput('token', { required: true });
5155
}
56+
get NoZip() {
57+
return Boolean(core.getInput('no-zip', { required: false }));
58+
}
5259
get NoFileBehvaior() {
5360
const notFoundAction = core.getInput('if-no-files-found', { required: false }) || NoFileOption_1.NoFileOption.warn;
5461
const noFileBehavior = NoFileOption_1.NoFileOption[notFoundAction];
@@ -70,7 +77,11 @@ exports.ActionInputs = ActionInputs;
7077

7178
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7279
if (k2 === undefined) k2 = k;
73-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
80+
var desc = Object.getOwnPropertyDescriptor(m, k);
81+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
82+
desc = { enumerable: true, get: function() { return m[k]; } };
83+
}
84+
Object.defineProperty(o, k2, desc);
7485
}) : (function(o, m, k, k2) {
7586
if (k2 === undefined) k2 = k;
7687
o[k2] = m[k];
@@ -89,12 +100,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
89100
};
90101
Object.defineProperty(exports, "__esModule", ({ value: true }));
91102
exports.FileFinder = void 0;
92-
const glob = __importStar(__nccwpck_require__(8090));
93-
const fs_1 = __nccwpck_require__(5747);
94-
const core_1 = __nccwpck_require__(2186);
95-
const path = __importStar(__nccwpck_require__(5622));
96-
const util_1 = __nccwpck_require__(1669);
97-
const stats = util_1.promisify(fs_1.stat);
103+
const glob = __importStar(__nccwpck_require__(203));
104+
const fs_1 = __nccwpck_require__(7147);
105+
const core_1 = __nccwpck_require__(3722);
106+
const path = __importStar(__nccwpck_require__(1017));
107+
const util_1 = __nccwpck_require__(3837);
108+
const stats = (0, util_1.promisify)(fs_1.stat);
98109
class FileFinder {
99110
constructor(searchPath, globOptions) {
100111
this.searchPath = searchPath;
@@ -117,26 +128,26 @@ class FileFinder {
117128
const fileStats = await stats(searchResult);
118129
// isDirectory() returns false for symlinks if using fs.lstat(), make sure to use fs.stat() instead
119130
if (!fileStats.isDirectory()) {
120-
core_1.debug(`File:${searchResult} was found using the provided searchPath`);
131+
(0, core_1.debug)(`File:${searchResult} was found using the provided searchPath`);
121132
searchResults.push(searchResult);
122133
// detect any files that would be overwritten because of case insensitivity
123134
if (set.has(searchResult.toLowerCase())) {
124-
core_1.info(`Uploads are case insensitive: ${searchResult} was detected that it will be overwritten by another file with the same path`);
135+
(0, core_1.info)(`Uploads are case insensitive: ${searchResult} was detected that it will be overwritten by another file with the same path`);
125136
}
126137
else {
127138
set.add(searchResult.toLowerCase());
128139
}
129140
}
130141
else {
131-
core_1.debug(`Removing ${searchResult} from rawSearchResults because it is a directory`);
142+
(0, core_1.debug)(`Removing ${searchResult} from rawSearchResults because it is a directory`);
132143
}
133144
}
134145
// Calculate the root directory for the artifact using the search paths that were utilized
135146
const searchPaths = globber.getSearchPaths();
136147
if (searchPaths.length > 1) {
137-
core_1.info(`Multiple search paths detected. Calculating the least common ancestor of all paths`);
148+
(0, core_1.info)(`Multiple search paths detected. Calculating the least common ancestor of all paths`);
138149
const lcaSearchPath = this.getMultiPathLCA(searchPaths);
139-
core_1.info(`The least common ancestor is ${lcaSearchPath}. This will be the root directory of the artifact`);
150+
(0, core_1.info)(`The least common ancestor is ${lcaSearchPath}. This will be the root directory of the artifact`);
140151
return {
141152
filesToUpload: searchResults,
142153
rootDirectory: lcaSearchPath
@@ -166,7 +177,7 @@ class FileFinder {
166177
let smallestPathLength = Number.MAX_SAFE_INTEGER;
167178
// split each of the search paths using the platform specific separator
168179
for (const searchPath of searchPaths) {
169-
core_1.debug(`Using search path ${searchPath}`);
180+
(0, core_1.debug)(`Using search path ${searchPath}`);
170181
const splitSearchPath = path.normalize(searchPath).split(path.sep);
171182
// keep track of the smallest path length so that we don't accidentally later go out of bounds
172183
smallestPathLength = Math.min(smallestPathLength, splitSearchPath.length);
@@ -243,7 +254,11 @@ var NoFileOption;
243254

244255
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
245256
if (k2 === undefined) k2 = k;
246-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
257+
var desc = Object.getOwnPropertyDescriptor(m, k);
258+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
259+
desc = { enumerable: true, get: function() { return m[k]; } };
260+
}
261+
Object.defineProperty(o, k2, desc);
247262
}) : (function(o, m, k, k2) {
248263
if (k2 === undefined) k2 = k;
249264
o[k2] = m[k];
@@ -286,7 +301,11 @@ run();
286301

287302
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
288303
if (k2 === undefined) k2 = k;
289-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
304+
var desc = Object.getOwnPropertyDescriptor(m, k);
305+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
306+
desc = { enumerable: true, get: function() { return m[k]; } };
307+
}
308+
Object.defineProperty(o, k2, desc);
290309
}) : (function(o, m, k, k2) {
291310
if (k2 === undefined) k2 = k;
292311
o[k2] = m[k];
@@ -364,10 +383,11 @@ class NextcloudArtifact {
364383
},
365384
...github.context.repo
366385
});
367-
const client = new NextcloudClient_1.NextcloudClient(this.inputs.Endpoint, this.name, files.rootDirectory, this.inputs.Username, this.inputs.Password);
386+
const client = new NextcloudClient_1.NextcloudClient(this.inputs.Endpoint, this.name, files.rootDirectory, this.inputs.Username, this.inputs.Password, this.inputs.NoZip);
368387
try {
369388
const shareableUrl = await client.uploadFiles(files.filesToUpload);
370389
core.setOutput('SHAREABLE_URL', shareableUrl);
390+
core.setOutput('DIRECT_SHAREABLE_URL', `${shareableUrl}/download`);
371391
core.info(`Nextcloud shareable URL: ${shareableUrl}`);
372392
const resp = await this.octokit.rest.checks.update({
373393
check_run_id: createResp.data.id,
@@ -445,7 +465,11 @@ exports.NextcloudArtifact = NextcloudArtifact;
445465

446466
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
447467
if (k2 === undefined) k2 = k;
448-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
468+
var desc = Object.getOwnPropertyDescriptor(m, k);
469+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
470+
desc = { enumerable: true, get: function() { return m[k]; } };
471+
}
472+
Object.defineProperty(o, k2, desc);
449473
}) : (function(o, m, k, k2) {
450474
if (k2 === undefined) k2 = k;
451475
o[k2] = m[k];
@@ -477,13 +501,14 @@ const uuid_1 = __nccwpck_require__(5840);
477501
const webdav = __importStar(__nccwpck_require__(4032));
478502
const fs = fsSync.promises;
479503
class NextcloudClient {
480-
constructor(endpoint, artifact, rootDirectory, username, password) {
504+
constructor(endpoint, artifact, rootDirectory, username, password, nozip) {
481505
this.endpoint = endpoint;
482506
this.artifact = artifact;
483507
this.rootDirectory = rootDirectory;
484508
this.username = username;
485509
this.password = password;
486-
this.guid = uuid_1.v4();
510+
this.nozip = nozip;
511+
this.guid = (0, uuid_1.v4)();
487512
this.headers = { Authorization: 'Basic ' + Buffer.from(`${this.username}:${this.password}`).toString('base64') };
488513
this.davClient = webdav.createClient(`${this.endpoint.href}remote.php/dav/files/${this.username}`, {
489514
username: this.username,
@@ -494,8 +519,16 @@ class NextcloudClient {
494519
async uploadFiles(files) {
495520
core.info('Preparing upload...');
496521
const spec = this.uploadSpec(files);
497-
core.info('Zipping files...');
498-
const zip = await this.zipFiles(spec);
522+
let zip;
523+
if (this.nozip) {
524+
if (spec.length > 1)
525+
throw Error('no-zip is incompatible with multiple file uploads.');
526+
zip = spec[0].absolutePath;
527+
}
528+
else {
529+
core.info('Zipping files...');
530+
zip = await this.zipFiles(spec);
531+
}
499532
try {
500533
core.info('Uploading to Nextcloud...');
501534
const filePath = await this.upload(zip);
@@ -570,9 +603,9 @@ class NextcloudClient {
570603
if (!(await this.davClient.exists(remoteFileDir))) {
571604
await this.davClient.createDirectory(remoteFileDir, { recursive: true });
572605
}
573-
const remoteFilePath = `${remoteFileDir}/${this.artifact}.zip`;
606+
const remoteFilePath = `${remoteFileDir}/${this.artifact}${this.nozip ? '' : '.zip'}`;
574607
core.debug(`Transferring file... (${file})`);
575-
await this.davClient.putFileContents(remoteFilePath, await fs.readFile(file));
608+
await this.davClient.putFileContents(remoteFilePath, fsSync.createReadStream(file));
576609
return remoteFilePath;
577610
}
578611
async shareFile(remoteFilePath) {
@@ -583,7 +616,7 @@ class NextcloudClient {
583616
publicUpload: 'false',
584617
permissions: 1
585618
};
586-
const res = await node_fetch_1.default(url, {
619+
const res = await (0, node_fetch_1.default)(url, {
587620
method: 'POST',
588621
headers: Object.assign(this.headers, {
589622
'OCS-APIRequest': true,

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ActionInputs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export class ActionInputs implements Inputs {
2828
return core.getInput('token', { required: true })
2929
}
3030

31+
get NoZip(): boolean {
32+
return Boolean(core.getInput('no-zip', { required: false }))
33+
}
34+
3135
get NoFileBehvaior(): NoFileOption {
3236
const notFoundAction = core.getInput('if-no-files-found', { required: false }) || NoFileOption.warn
3337
const noFileBehavior: NoFileOption = NoFileOption[notFoundAction as keyof typeof NoFileOption]

src/Inputs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ export interface Inputs {
1515
readonly Token: string
1616

1717
readonly NoFileBehvaior: NoFileOption
18+
19+
readonly NoZip: boolean
1820
}

src/nextcloud/NextcloudArtifact.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ export class NextcloudArtifact {
7878
this.name,
7979
files.rootDirectory,
8080
this.inputs.Username,
81-
this.inputs.Password
81+
this.inputs.Password,
82+
this.inputs.NoZip
8283
)
8384

8485
try {
8586
const shareableUrl = await client.uploadFiles(files.filesToUpload)
8687
core.setOutput('SHAREABLE_URL', shareableUrl)
88+
core.setOutput('DIRECT_SHAREABLE_URL', `${shareableUrl}/download`)
8789
core.info(`Nextcloud shareable URL: ${shareableUrl}`)
8890
const resp = await this.octokit.rest.checks.update({
8991
check_run_id: createResp.data.id,

src/nextcloud/NextcloudClient.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as core from '@actions/core'
44
import * as os from 'os'
55
import * as archiver from 'archiver'
66
import fetch, { HeadersInit } from 'node-fetch'
7-
import btoa from 'btoa'
87
import { v4 as uuidv4 } from 'uuid'
98
import * as webdav from 'webdav'
109
import { URL } from 'url'
@@ -26,7 +25,8 @@ export class NextcloudClient {
2625
private artifact: string,
2726
private rootDirectory: string,
2827
private username: string,
29-
private password: string
28+
private password: string,
29+
private nozip: boolean
3030
) {
3131
this.guid = uuidv4()
3232
this.headers = { Authorization: 'Basic ' + Buffer.from(`${this.username}:${this.password}`).toString('base64') }
@@ -40,15 +40,24 @@ export class NextcloudClient {
4040
async uploadFiles(files: string[]): Promise<string> {
4141
core.info('Preparing upload...')
4242
const spec = this.uploadSpec(files)
43-
core.info('Zipping files...')
44-
const zip = await this.zipFiles(spec)
43+
let zip
44+
45+
if (this.nozip) {
46+
if (spec.length > 1) throw Error('no-zip is incompatible with multiple file uploads.')
47+
zip = spec[0].absolutePath
48+
} else {
49+
core.info('Zipping files...')
50+
zip = await this.zipFiles(spec)
51+
}
52+
4553
try {
4654
core.info('Uploading to Nextcloud...')
4755
const filePath = await this.upload(zip)
4856
core.info(`Remote file path: ${filePath}`)
4957
return await this.shareFile(filePath)
5058
} finally {
51-
await fs.unlink(zip)
59+
// Don't delete user-made files
60+
if (!this.nozip) await fs.unlink(zip)
5261
}
5362
}
5463

@@ -126,10 +135,10 @@ export class NextcloudClient {
126135
await this.davClient.createDirectory(remoteFileDir, { recursive: true })
127136
}
128137

129-
const remoteFilePath = `${remoteFileDir}/${this.artifact}.zip`
138+
const remoteFilePath = `${remoteFileDir}/${this.artifact}${this.nozip ? '' : '.zip'}`
130139
core.debug(`Transferring file... (${file})`)
131140

132-
await this.davClient.putFileContents(remoteFilePath, await fs.readFile(file))
141+
await this.davClient.putFileContents(remoteFilePath, fsSync.createReadStream(file))
133142

134143
return remoteFilePath
135144
}

0 commit comments

Comments
 (0)