mirror of
https://github.com/trympet/nextcloud-artifacts-action.git
synced 2025-04-24 20:16:08 +02:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7c9fa20219 | ||
![]() |
3d18ab00c5 | ||
![]() |
20dadea389 | ||
![]() |
a496fd037d | ||
![]() |
61ff55deae | ||
![]() |
b357f186aa | ||
![]() |
dec03f56e0 | ||
![]() |
62e99ad6b2 | ||
![]() |
5825f9614a | ||
![]() |
e1264cbb56 | ||
![]() |
7d73f7e889 | ||
![]() |
81238124ba | ||
![]() |
935313b418 | ||
![]() |
995999b60c | ||
![]() |
cd4f651c13 |
@ -1,5 +1,5 @@
|
||||
# Nextcloud Artifact Upload Action
|
||||
Upload artifacts to nextcloud and outputs a shareable URL.
|
||||
Upload artifacts to nextcloud and output a shareable URL.
|
||||
|
||||
### How it looks:
|
||||

|
||||
@ -23,7 +23,7 @@ jobs:
|
||||
with:
|
||||
name: 'my-artifact' # Name of the artifact
|
||||
path: 'bin/**/*.exe' # Globbing supported
|
||||
nextcloud-url: 'https://nextcloud.example.com' # Format of test results
|
||||
nextcloud-url: 'https://nextcloud.example.com' # Nextcloud URL
|
||||
nextcloud-username: ${{ secrets.NEXTCLOUD_USERNAME }} # Username from repository secret
|
||||
nextcloud-password: ${{ secrets.NEXTCLOUD_PASSWORD }} # Password from repository secret
|
||||
```
|
||||
|
@ -30,5 +30,5 @@ inputs:
|
||||
required: false
|
||||
default: ${{ github.token }}
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
|
65
dist/index.js
vendored
65
dist/index.js
vendored
@ -367,6 +367,7 @@ class NextcloudArtifact {
|
||||
const client = new NextcloudClient_1.NextcloudClient(this.inputs.Endpoint, this.name, files.rootDirectory, this.inputs.Username, this.inputs.Password);
|
||||
try {
|
||||
const shareableUrl = await client.uploadFiles(files.filesToUpload);
|
||||
core.setOutput('SHAREABLE_URL', shareableUrl);
|
||||
core.info(`Nextcloud shareable URL: ${shareableUrl}`);
|
||||
const resp = await this.octokit.rest.checks.update({
|
||||
check_run_id: createResp.data.id,
|
||||
@ -472,7 +473,6 @@ const core = __importStar(__nccwpck_require__(2186));
|
||||
const os = __importStar(__nccwpck_require__(2087));
|
||||
const archiver = __importStar(__nccwpck_require__(3084));
|
||||
const node_fetch_1 = __importDefault(__nccwpck_require__(467));
|
||||
const btoa_1 = __importDefault(__nccwpck_require__(2738));
|
||||
const uuid_1 = __nccwpck_require__(5840);
|
||||
const webdav = __importStar(__nccwpck_require__(4032));
|
||||
const fs = fsSync.promises;
|
||||
@ -484,10 +484,11 @@ class NextcloudClient {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.guid = uuid_1.v4();
|
||||
this.headers = { Authorization: 'Basic ' + btoa_1.default(`${this.username}:${this.password}`) };
|
||||
this.headers = { Authorization: 'Basic ' + Buffer.from(`${this.username}:${this.password}`).toString('base64') };
|
||||
this.davClient = webdav.createClient(`${this.endpoint.href}remote.php/dav/files/${this.username}`, {
|
||||
username: this.username,
|
||||
password: this.password
|
||||
password: this.password,
|
||||
maxBodyLength: 1024 ** 3
|
||||
});
|
||||
}
|
||||
async uploadFiles(files) {
|
||||
@ -495,10 +496,15 @@ class NextcloudClient {
|
||||
const spec = this.uploadSpec(files);
|
||||
core.info('Zipping files...');
|
||||
const zip = await this.zipFiles(spec);
|
||||
core.info('Uploading to Nextcloud...');
|
||||
const filePath = await this.upload(zip);
|
||||
core.info(`Remote file path: ${filePath}`);
|
||||
return await this.shareFile(filePath);
|
||||
try {
|
||||
core.info('Uploading to Nextcloud...');
|
||||
const filePath = await this.upload(zip);
|
||||
core.info(`Remote file path: ${filePath}`);
|
||||
return await this.shareFile(filePath);
|
||||
}
|
||||
finally {
|
||||
await fs.unlink(zip);
|
||||
}
|
||||
}
|
||||
uploadSpec(files) {
|
||||
const specifications = [];
|
||||
@ -566,24 +572,7 @@ class NextcloudClient {
|
||||
}
|
||||
const remoteFilePath = `${remoteFileDir}/${this.artifact}.zip`;
|
||||
core.debug(`Transferring file... (${file})`);
|
||||
const fileStat = await fs.stat(file);
|
||||
const fileStream = fsSync.createReadStream(file);
|
||||
const fileStreamPromise = new Promise((resolve, reject) => {
|
||||
fileStream.on('error', e => reject(e)).on('close', () => resolve());
|
||||
});
|
||||
const remoteStream = this.davClient.createWriteStream(remoteFilePath, {
|
||||
headers: { 'Content-Length': fileStat.size.toString() }
|
||||
});
|
||||
const remoteStreamPromise = new Promise((resolve, reject) => {
|
||||
remoteStream.on('error', e => reject(e)).on('finish', () => resolve());
|
||||
});
|
||||
fileStream.pipe(remoteStream);
|
||||
const timer = setTimeout(() => { }, 20000);
|
||||
await Promise.all([fileStreamPromise, remoteStreamPromise]);
|
||||
// HACK: Nextcloud has not fully processed the file, despite returning 200.
|
||||
// Waiting for 1s seems to do the trick.
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
clearTimeout(timer);
|
||||
await this.davClient.putFileContents(remoteFilePath, await fs.readFile(file));
|
||||
return remoteFilePath;
|
||||
}
|
||||
async shareFile(remoteFilePath) {
|
||||
@ -17651,30 +17640,6 @@ function expand(str, isTop) {
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2738:
|
||||
/***/ ((module) => {
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function btoa(str) {
|
||||
var buffer;
|
||||
|
||||
if (str instanceof Buffer) {
|
||||
buffer = str;
|
||||
} else {
|
||||
buffer = Buffer.from(str.toString(), 'binary');
|
||||
}
|
||||
|
||||
return buffer.toString('base64');
|
||||
}
|
||||
|
||||
module.exports = btoa;
|
||||
}());
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4794:
|
||||
@ -45199,7 +45164,7 @@ module.exports = eval("require")("encoding");
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = JSON.parse('{"_from":"axios@^0.21.1","_id":"axios@0.21.1","_inBundle":false,"_integrity":"sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"range","registry":true,"raw":"axios@^0.21.1","name":"axios","escapedName":"axios","rawSpec":"^0.21.1","saveSpec":null,"fetchSpec":"^0.21.1"},"_requiredBy":["/webdav"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.21.1.tgz","_shasum":"22563481962f4d6bde9a76d516ef0e5d3c09b2b8","_spec":"axios@^0.21.1","_where":"/home/trym/source/linux/repos/nextcloud-artifacts-action/node_modules/webdav","author":{"name":"Matt Zabriskie"},"browser":{"./lib/adapters/http.js":"./lib/adapters/xhr.js"},"bugs":{"url":"https://github.com/axios/axios/issues"},"bundleDependencies":false,"bundlesize":[{"path":"./dist/axios.min.js","threshold":"5kB"}],"dependencies":{"follow-redirects":"^1.10.0"},"deprecated":false,"description":"Promise based HTTP client for the browser and node.js","devDependencies":{"bundlesize":"^0.17.0","coveralls":"^3.0.0","es6-promise":"^4.2.4","grunt":"^1.0.2","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^20.1.0","grunt-karma":"^2.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^1.0.18","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1","karma":"^1.3.0","karma-chrome-launcher":"^2.2.0","karma-coverage":"^1.1.1","karma-firefox-launcher":"^1.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-opera-launcher":"^1.0.0","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^1.2.0","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^1.7.0","load-grunt-tasks":"^3.5.2","minimist":"^1.2.0","mocha":"^5.2.0","sinon":"^4.5.0","typescript":"^2.8.1","url-search-params":"^0.10.0","webpack":"^1.13.1","webpack-dev-server":"^1.14.1"},"homepage":"https://github.com/axios/axios","jsdelivr":"dist/axios.min.js","keywords":["xhr","http","ajax","promise","node"],"license":"MIT","main":"index.js","name":"axios","repository":{"type":"git","url":"git+https://github.com/axios/axios.git"},"scripts":{"build":"NODE_ENV=production grunt build","coveralls":"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","examples":"node ./examples/server.js","fix":"eslint --fix lib/**/*.js","postversion":"git push && git push --tags","preversion":"npm test","start":"node ./sandbox/server.js","test":"grunt test && bundlesize","version":"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json"},"typings":"./index.d.ts","unpkg":"dist/axios.min.js","version":"0.21.1"}');
|
||||
module.exports = JSON.parse('{"_args":[["axios@0.21.1","C:\\\\Users\\\\trym\\\\source\\\\repos\\\\nextcloud-artifacts-action"]],"_from":"axios@0.21.1","_id":"axios@0.21.1","_inBundle":false,"_integrity":"sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"axios@0.21.1","name":"axios","escapedName":"axios","rawSpec":"0.21.1","saveSpec":null,"fetchSpec":"0.21.1"},"_requiredBy":["/webdav"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.21.1.tgz","_spec":"0.21.1","_where":"C:\\\\Users\\\\trym\\\\source\\\\repos\\\\nextcloud-artifacts-action","author":{"name":"Matt Zabriskie"},"browser":{"./lib/adapters/http.js":"./lib/adapters/xhr.js"},"bugs":{"url":"https://github.com/axios/axios/issues"},"bundlesize":[{"path":"./dist/axios.min.js","threshold":"5kB"}],"dependencies":{"follow-redirects":"^1.10.0"},"description":"Promise based HTTP client for the browser and node.js","devDependencies":{"bundlesize":"^0.17.0","coveralls":"^3.0.0","es6-promise":"^4.2.4","grunt":"^1.0.2","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^20.1.0","grunt-karma":"^2.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^1.0.18","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1","karma":"^1.3.0","karma-chrome-launcher":"^2.2.0","karma-coverage":"^1.1.1","karma-firefox-launcher":"^1.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-opera-launcher":"^1.0.0","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^1.2.0","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^1.7.0","load-grunt-tasks":"^3.5.2","minimist":"^1.2.0","mocha":"^5.2.0","sinon":"^4.5.0","typescript":"^2.8.1","url-search-params":"^0.10.0","webpack":"^1.13.1","webpack-dev-server":"^1.14.1"},"homepage":"https://github.com/axios/axios","jsdelivr":"dist/axios.min.js","keywords":["xhr","http","ajax","promise","node"],"license":"MIT","main":"index.js","name":"axios","repository":{"type":"git","url":"git+https://github.com/axios/axios.git"},"scripts":{"build":"NODE_ENV=production grunt build","coveralls":"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","examples":"node ./examples/server.js","fix":"eslint --fix lib/**/*.js","postversion":"git push && git push --tags","preversion":"npm test","start":"node ./sandbox/server.js","test":"grunt test && bundlesize","version":"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json"},"typings":"./index.d.ts","unpkg":"dist/axios.min.js","version":"0.21.1"}');
|
||||
|
||||
/***/ }),
|
||||
|
||||
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
195
dist/licenses.txt
vendored
195
dist/licenses.txt
vendored
@ -633,201 +633,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
btoa
|
||||
(MIT OR Apache-2.0)
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||
that control, are controlled by, or are under common control with that entity.
|
||||
For the purposes of this definition, "control" means (i) the power, direct or
|
||||
indirect, to cause the direction or management of such entity, whether by
|
||||
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||
permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including
|
||||
but not limited to software source code, documentation source, and configuration
|
||||
files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or
|
||||
translation of a Source form, including but not limited to compiled object code,
|
||||
generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
||||
available under the License, as indicated by a copyright notice that is included
|
||||
in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
||||
is based on (or derived from) the Work and for which the editorial revisions,
|
||||
annotations, elaborations, or other modifications represent, as a whole, an
|
||||
original work of authorship. For the purposes of this License, Derivative Works
|
||||
shall not include works that remain separable from, or merely link (or bind by
|
||||
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version
|
||||
of the Work and any modifications or additions to that Work or Derivative Works
|
||||
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||
on behalf of the copyright owner. For the purposes of this definition,
|
||||
"submitted" means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems, and
|
||||
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||
the purpose of discussing and improving the Work, but excluding communication
|
||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||
of whom a Contribution has been received by Licensor and subsequently
|
||||
incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||
Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable (except as stated in this section) patent license to make, have
|
||||
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||
such license applies only to those patent claims licensable by such Contributor
|
||||
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||
submitted. If You institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||
Contribution incorporated within the Work constitutes direct or contributory
|
||||
patent infringement, then any patent licenses granted to You under this License
|
||||
for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||
in any medium, with or without modifications, and in Source or Object form,
|
||||
provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of
|
||||
this License; and
|
||||
You must cause any modified files to carry prominent notices stating that You
|
||||
changed the files; and
|
||||
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||
all copyright, patent, trademark, and attribution notices from the Source form
|
||||
of the Work, excluding those notices that do not pertain to any part of the
|
||||
Derivative Works; and
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||
Derivative Works that You distribute must include a readable copy of the
|
||||
attribution notices contained within such NOTICE file, excluding those notices
|
||||
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||
following places: within a NOTICE text file distributed as part of the
|
||||
Derivative Works; within the Source form or documentation, if provided along
|
||||
with the Derivative Works; or, within a display generated by the Derivative
|
||||
Works, if and wherever such third-party notices normally appear. The contents of
|
||||
the NOTICE file are for informational purposes only and do not modify the
|
||||
License. You may add Your own attribution notices within Derivative Works that
|
||||
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||
provided that such additional attribution notices cannot be construed as
|
||||
modifying the License.
|
||||
You may add Your own copyright statement to Your modifications and may provide
|
||||
additional or different license terms and conditions for use, reproduction, or
|
||||
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||
with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||
conditions of this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||
any separate license agreement you may have executed with Licensor regarding
|
||||
such Contributions.
|
||||
|
||||
6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks,
|
||||
service marks, or product names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||
including, without limitation, any warranties or conditions of TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||
solely responsible for determining the appropriateness of using or
|
||||
redistributing the Work and assume any risks associated with Your exercise of
|
||||
permissions under this License.
|
||||
|
||||
8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence),
|
||||
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special, incidental,
|
||||
or consequential damages of any character arising as a result of this License or
|
||||
out of the use or inability to use the Work (including but not limited to
|
||||
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||
any and all other commercial damages or losses), even if such Contributor has
|
||||
been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||
other liability obligations and/or rights consistent with this License. However,
|
||||
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason of your
|
||||
accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate
|
||||
notice, with the fields enclosed by brackets "[]" replaced with your own
|
||||
identifying information. (Don't include the brackets!) The text should be
|
||||
enclosed in the appropriate comment syntax for the file format. We also
|
||||
recommend that a file or class name and description of purpose be included on
|
||||
the same "printed page" as the copyright notice for easier identification within
|
||||
third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
buffer-crc32
|
||||
MIT
|
||||
The MIT License
|
||||
|
@ -83,6 +83,7 @@ export class NextcloudArtifact {
|
||||
|
||||
try {
|
||||
const shareableUrl = await client.uploadFiles(files.filesToUpload)
|
||||
core.setOutput('SHAREABLE_URL', shareableUrl)
|
||||
core.info(`Nextcloud shareable URL: ${shareableUrl}`)
|
||||
const resp = await this.octokit.rest.checks.update({
|
||||
check_run_id: createResp.data.id,
|
||||
|
@ -1,303 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.NextcloudClient = void 0;
|
||||
var fsSync = require("fs");
|
||||
var path = require("path");
|
||||
var core = require("@actions/core");
|
||||
var os = require("os");
|
||||
var archiver = require("archiver");
|
||||
var node_fetch_1 = require("node-fetch");
|
||||
var btoa_1 = require("btoa");
|
||||
var uuid_1 = require("uuid");
|
||||
var webdav = require("webdav");
|
||||
var fs = fsSync.promises;
|
||||
var NextcloudClient = /** @class */ (function () {
|
||||
function NextcloudClient(endpoint, artifact, rootDirectory, username, password) {
|
||||
this.endpoint = endpoint;
|
||||
this.artifact = artifact;
|
||||
this.rootDirectory = rootDirectory;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.guid = uuid_1.v4();
|
||||
this.headers = { 'Authorization': 'Basic ' + btoa_1["default"](this.username + ":" + this.password) };
|
||||
this.davClient = webdav.createClient(this.endpoint + "/remote.php/dav/files/" + this.username, {
|
||||
username: this.username,
|
||||
password: this.password
|
||||
});
|
||||
}
|
||||
NextcloudClient.prototype.uploadFiles = function (files) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var spec, zip, path;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
core.info("Preparing upload...");
|
||||
spec = this.uploadSpec(files);
|
||||
core.info("Zipping files...");
|
||||
return [4 /*yield*/, this.zipFiles(spec)];
|
||||
case 1:
|
||||
zip = _a.sent();
|
||||
core.info("Uploading to Nextcloud...");
|
||||
return [4 /*yield*/, this.upload(zip)];
|
||||
case 2:
|
||||
path = _a.sent();
|
||||
core.info("File path: " + path);
|
||||
core.info("Sharing file...");
|
||||
return [4 /*yield*/, this.shareFile(path)];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
NextcloudClient.prototype.uploadSpec = function (files) {
|
||||
var specifications = [];
|
||||
if (!fsSync.existsSync(this.rootDirectory)) {
|
||||
throw new Error("this.rootDirectory " + this.rootDirectory + " does not exist");
|
||||
}
|
||||
if (!fsSync.lstatSync(this.rootDirectory).isDirectory()) {
|
||||
throw new Error("this.rootDirectory " + this.rootDirectory + " is not a valid directory");
|
||||
}
|
||||
// Normalize and resolve, this allows for either absolute or relative paths to be used
|
||||
var root = path.normalize(this.rootDirectory);
|
||||
root = path.resolve(root);
|
||||
/*
|
||||
Example to demonstrate behavior
|
||||
|
||||
Input:
|
||||
artifactName: my-artifact
|
||||
rootDirectory: '/home/user/files/plz-upload'
|
||||
artifactFiles: [
|
||||
'/home/user/files/plz-upload/file1.txt',
|
||||
'/home/user/files/plz-upload/file2.txt',
|
||||
'/home/user/files/plz-upload/dir/file3.txt'
|
||||
]
|
||||
|
||||
Output:
|
||||
specifications: [
|
||||
['/home/user/files/plz-upload/file1.txt', 'my-artifact/file1.txt'],
|
||||
['/home/user/files/plz-upload/file1.txt', 'my-artifact/file2.txt'],
|
||||
['/home/user/files/plz-upload/file1.txt', 'my-artifact/dir/file3.txt']
|
||||
]
|
||||
*/
|
||||
for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
|
||||
var file = files_1[_i];
|
||||
if (!fsSync.existsSync(file)) {
|
||||
throw new Error("File " + file + " does not exist");
|
||||
}
|
||||
if (!fsSync.lstatSync(file).isDirectory()) {
|
||||
// Normalize and resolve, this allows for either absolute or relative paths to be used
|
||||
file = path.normalize(file);
|
||||
file = path.resolve(file);
|
||||
if (!file.startsWith(root)) {
|
||||
throw new Error("The rootDirectory: " + root + " is not a parent directory of the file: " + file);
|
||||
}
|
||||
// Check for forbidden characters in file paths that will be rejected during upload
|
||||
var uploadPath = file.replace(root, '');
|
||||
/*
|
||||
uploadFilePath denotes where the file will be uploaded in the file container on the server. During a run, if multiple artifacts are uploaded, they will all
|
||||
be saved in the same container. The artifact name is used as the root directory in the container to separate and distinguish uploaded artifacts
|
||||
|
||||
path.join handles all the following cases and would return 'artifact-name/file-to-upload.txt
|
||||
join('artifact-name/', 'file-to-upload.txt')
|
||||
join('artifact-name/', '/file-to-upload.txt')
|
||||
join('artifact-name', 'file-to-upload.txt')
|
||||
join('artifact-name', '/file-to-upload.txt')
|
||||
*/
|
||||
specifications.push({
|
||||
absolutePath: file,
|
||||
uploadPath: path.join(this.artifact, uploadPath)
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Directories are rejected by the server during upload
|
||||
core.debug("Removing " + file + " from rawSearchResults because it is a directory");
|
||||
}
|
||||
}
|
||||
return specifications;
|
||||
};
|
||||
NextcloudClient.prototype.zipFiles = function (specs) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var tempArtifactDir, artifactPath, copies, _i, specs_1, spec, dstpath, dstDir, _a, _b, _c, archivePath, _d, _e, _f;
|
||||
return __generator(this, function (_g) {
|
||||
switch (_g.label) {
|
||||
case 0:
|
||||
tempArtifactDir = path.join(os.tmpdir(), this.guid);
|
||||
artifactPath = path.join(tempArtifactDir, "artifact-" + this.artifact);
|
||||
return [4 /*yield*/, fs.mkdir(path.join(artifactPath, this.artifact), { recursive: true })];
|
||||
case 1:
|
||||
_g.sent();
|
||||
copies = [];
|
||||
_i = 0, specs_1 = specs;
|
||||
_g.label = 2;
|
||||
case 2:
|
||||
if (!(_i < specs_1.length)) return [3 /*break*/, 6];
|
||||
spec = specs_1[_i];
|
||||
dstpath = path.join(artifactPath, spec.uploadPath);
|
||||
dstDir = path.dirname(dstpath);
|
||||
if (!!fsSync.existsSync(dstDir)) return [3 /*break*/, 4];
|
||||
return [4 /*yield*/, fs.mkdir(dstDir, { recursive: true })];
|
||||
case 3:
|
||||
_g.sent();
|
||||
_g.label = 4;
|
||||
case 4:
|
||||
copies.push(fs.copyFile(spec.absolutePath, dstpath));
|
||||
_g.label = 5;
|
||||
case 5:
|
||||
_i++;
|
||||
return [3 /*break*/, 2];
|
||||
case 6: return [4 /*yield*/, Promise.all(copies)];
|
||||
case 7:
|
||||
_g.sent();
|
||||
_b = (_a = core).info;
|
||||
_c = "files: ";
|
||||
return [4 /*yield*/, fs.readdir(path.join(artifactPath, this.artifact))];
|
||||
case 8:
|
||||
_b.apply(_a, [_c + (_g.sent())]);
|
||||
archivePath = path.join(artifactPath, this.artifact + ".zip");
|
||||
return [4 /*yield*/, this.zip(path.join(artifactPath, this.artifact), archivePath)];
|
||||
case 9:
|
||||
_g.sent();
|
||||
_e = (_d = core).info;
|
||||
_f = "archive stat: ";
|
||||
return [4 /*yield*/, fs.stat(archivePath)];
|
||||
case 10:
|
||||
_e.apply(_d, [_f + (_g.sent()).size]);
|
||||
return [2 /*return*/, archivePath];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
NextcloudClient.prototype.zip = function (dirpath, destpath) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var archive, stream;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
archive = archiver.create('zip', { zlib: { level: 9 } });
|
||||
stream = archive.directory(dirpath, false)
|
||||
.pipe(fsSync.createWriteStream(destpath));
|
||||
return [4 /*yield*/, archive.finalize()];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
||||
stream.on('error', function (e) { return reject(e); })
|
||||
.on('close', function () { return resolve(); });
|
||||
})];
|
||||
case 2: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
NextcloudClient.prototype.upload = function (file) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var remoteFileDir, remoteFilePath;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
remoteFileDir = "/artifacts/" + this.guid;
|
||||
core.info("Checking directory...");
|
||||
return [4 /*yield*/, this.davClient.exists(remoteFileDir)];
|
||||
case 1:
|
||||
if (!!(_a.sent())) return [3 /*break*/, 3];
|
||||
core.info("Creating directory...");
|
||||
return [4 /*yield*/, this.davClient.createDirectory(remoteFileDir, { recursive: true })];
|
||||
case 2:
|
||||
_a.sent();
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
remoteFilePath = remoteFileDir + "/" + this.artifact + ".zip";
|
||||
core.info("Transferring file... (" + file + ")");
|
||||
return [4 /*yield*/, this.transferFile(remoteFilePath, file)];
|
||||
case 4:
|
||||
_a.sent();
|
||||
core.info("finish");
|
||||
return [2 /*return*/, remoteFilePath];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
NextcloudClient.prototype.transferFile = function (remoteFilePath, file) {
|
||||
var fileStream = fsSync.createReadStream(file);
|
||||
var fileStreamPromise = new Promise(function (resolve, reject) {
|
||||
fileStream.on('error', function () { return reject("Failed to read file"); })
|
||||
.on('end', function () { return resolve(); });
|
||||
});
|
||||
var remoteStream = this.davClient.createWriteStream(remoteFilePath);
|
||||
fileStream.pipe(remoteStream);
|
||||
var remoteStreamPromise = new Promise(function (resolve, reject) {
|
||||
remoteStream.on('error', function () { return reject("Failed to upload file"); })
|
||||
.on('close', function () { return resolve(); });
|
||||
});
|
||||
return Promise.all([remoteStreamPromise, fileStreamPromise]);
|
||||
};
|
||||
NextcloudClient.prototype.shareFile = function (remoteFilePath) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var url, body, res, _a, _b;
|
||||
return __generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0:
|
||||
url = this.endpoint + "/ocs/v2.php/apps/files_sharing/api/v1/shares";
|
||||
body = {
|
||||
path: remoteFilePath,
|
||||
shareType: 3,
|
||||
publicUpload: "false",
|
||||
permissions: 1
|
||||
};
|
||||
return [4 /*yield*/, node_fetch_1["default"](url, {
|
||||
method: 'PUT',
|
||||
headers: this.headers,
|
||||
body: JSON.stringify(body)
|
||||
})];
|
||||
case 1:
|
||||
res = _c.sent();
|
||||
res.status;
|
||||
_b = (_a = core).info;
|
||||
return [4 /*yield*/, res.text()];
|
||||
case 2:
|
||||
_b.apply(_a, [_c.sent()]);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
return NextcloudClient;
|
||||
}());
|
||||
exports.NextcloudClient = NextcloudClient;
|
@ -29,10 +29,11 @@ export class NextcloudClient {
|
||||
private password: string
|
||||
) {
|
||||
this.guid = uuidv4()
|
||||
this.headers = { Authorization: 'Basic ' + btoa(`${this.username}:${this.password}`) }
|
||||
this.headers = { Authorization: 'Basic ' + Buffer.from(`${this.username}:${this.password}`).toString('base64') }
|
||||
this.davClient = webdav.createClient(`${this.endpoint.href}remote.php/dav/files/${this.username}`, {
|
||||
username: this.username,
|
||||
password: this.password
|
||||
password: this.password,
|
||||
maxBodyLength: 1024 ** 3
|
||||
})
|
||||
}
|
||||
|
||||
@ -41,11 +42,14 @@ export class NextcloudClient {
|
||||
const spec = this.uploadSpec(files)
|
||||
core.info('Zipping files...')
|
||||
const zip = await this.zipFiles(spec)
|
||||
|
||||
core.info('Uploading to Nextcloud...')
|
||||
const filePath = await this.upload(zip)
|
||||
core.info(`Remote file path: ${filePath}`)
|
||||
return await this.shareFile(filePath)
|
||||
try {
|
||||
core.info('Uploading to Nextcloud...')
|
||||
const filePath = await this.upload(zip)
|
||||
core.info(`Remote file path: ${filePath}`)
|
||||
return await this.shareFile(filePath)
|
||||
} finally {
|
||||
await fs.unlink(zip)
|
||||
}
|
||||
}
|
||||
|
||||
private uploadSpec(files: string[]): FileSpec[] {
|
||||
@ -125,28 +129,8 @@ export class NextcloudClient {
|
||||
const remoteFilePath = `${remoteFileDir}/${this.artifact}.zip`
|
||||
core.debug(`Transferring file... (${file})`)
|
||||
|
||||
const fileStat = await fs.stat(file)
|
||||
const fileStream = fsSync.createReadStream(file)
|
||||
const fileStreamPromise = new Promise<void>((resolve, reject) => {
|
||||
fileStream.on('error', e => reject(e)).on('close', () => resolve())
|
||||
})
|
||||
const remoteStream = this.davClient.createWriteStream(remoteFilePath, {
|
||||
headers: { 'Content-Length': fileStat.size.toString() }
|
||||
})
|
||||
const remoteStreamPromise = new Promise<void>((resolve, reject) => {
|
||||
remoteStream.on('error', e => reject(e)).on('finish', () => resolve())
|
||||
})
|
||||
await this.davClient.putFileContents(remoteFilePath, await fs.readFile(file))
|
||||
|
||||
fileStream.pipe(remoteStream)
|
||||
|
||||
const timer = setTimeout(() => {}, 20_000)
|
||||
await Promise.all([fileStreamPromise, remoteStreamPromise])
|
||||
|
||||
// HACK: Nextcloud has not fully processed the file, despite returning 200.
|
||||
// Waiting for 1s seems to do the trick.
|
||||
await new Promise(resolve => setTimeout(resolve, 1_000))
|
||||
|
||||
clearTimeout(timer)
|
||||
return remoteFilePath
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,5 @@
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"remoteAuthority": "wsl+Ubuntu-20.04",
|
||||
"settings": {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user