Skip to content

Commit 2536c54

Browse files
committed
Updating release
1 parent f021a15 commit 2536c54

File tree

5,540 files changed

+1248588
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,540 files changed

+1248588
-3
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as core from '@actions/core';
2+
import { getFilesForUpload } from './src/file-system-utils';
3+
import { uploadAll } from './src/azure-upload-utils';
4+
try {
5+
/**
6+
* File types to upload should look like
7+
* { ".html": "text/html" }
8+
*/
9+
const fileTypesToUpload = JSON.parse(core.getInput('fileTypesToUpload'));
10+
/**
11+
* Directories to upload should look like
12+
* [
13+
* { directoryToUpload: "", shouldRecurse: "", baseContainerPath: "" }
14+
* ]
15+
*/
16+
const directoriesToUpload = JSON.parse(core.getInput('directoriesToUpload')) || [];
17+
let filesToUpload = [];
18+
directoriesToUpload.forEach(t => {
19+
filesToUpload = filesToUpload.concat(getFilesForUpload(t.directoryToUpload, t.shouldRecurse, t.baseContainerPath, Object.keys(fileTypesToUpload)));
20+
});
21+
/**
22+
* Azure Blob Configurations should look like
23+
* [
24+
* { connectionString: "", container: "" }
25+
* ]
26+
*/
27+
const azureBlobConfiguration = JSON.parse(core.getInput('azureBlobConfiguration'));
28+
uploadAll(azureBlobConfiguration, filesToUpload, fileTypesToUpload);
29+
}
30+
catch (error) {
31+
core.setFailed(error.message);
32+
}

dist/src/azure-upload-utils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { BlobServiceClient } = require('@azure/storage-blob');
2+
const path = require('path');
3+
const fs = require('fs');
4+
export function uploadAll(uploadConfigs, filesToUpload, supportedContentTypes) {
5+
uploadConfigs.forEach(t => {
6+
const blobServiceClient = BlobServiceClient.fromConnectionString(t.connectionString);
7+
const containerClient = blobServiceClient.getContainerClient(t.container);
8+
filesToUpload.forEach(x => {
9+
let stream = fs.readFileSync(x.absoluteDiskPath);
10+
let contentType = supportedContentTypes[path.extname(x.absoluteDiskPath)];
11+
if (!contentType)
12+
throw `Unsupported Content Type for ${x.absoluteDiskPath}`;
13+
containerClient.uploadBlockBlob(x.relativeUploadPath, stream, stream.length, { blobHTTPHeaders: { blobContentType: contentType } });
14+
});
15+
});
16+
}

dist/src/file-system-utils.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import fs from 'fs';
2+
import Queue from 'queue-fifo';
3+
import path from 'path';
4+
let q = new Queue();
5+
/**
6+
* Traverses the disk and builds a list/map of which files to upload and with what relative paths.
7+
*
8+
* @param scanDirectory - Directory to scan on the disk
9+
* @param shouldRecurse - If we should recurse and upload files in nested directories
10+
* @param baseContainerPath - Most likely $web for Azure Blobs, if static content is being uploaded
11+
* @param extensionsToUpload - List of extensions to upload
12+
*
13+
* @returns an array of objects which carry absolute path on disk
14+
* and where they would be uploaded in cloud
15+
*/
16+
export function getFilesForUpload(scanDirectory, shouldRecurse, baseContainerPath, extensionsToUpload) {
17+
let filesToUpload = [];
18+
q.enqueue(scanDirectory);
19+
while (!q.isEmpty()) {
20+
const currentDirectoryPath = q.dequeue();
21+
console.log('Traversing directory: ', currentDirectoryPath);
22+
const currentDirectoryContents = fs.readdirSync(currentDirectoryPath);
23+
const filesInCurrentDirectory = currentDirectoryContents
24+
// filter for files only
25+
.filter(t => !fs.lstatSync(path.join(currentDirectoryPath, t)).isDirectory())
26+
// filenames to full path
27+
.map(t => path.join(currentDirectoryPath, t));
28+
console.log(`Files in ${currentDirectoryPath}`, filesInCurrentDirectory);
29+
let uploadCandidates = filesInCurrentDirectory
30+
// make sure we only target the specified extensions
31+
.filter(t => extensionsToUpload.some(x => t.endsWith(x)));
32+
console.log(`Upload candidates from ${currentDirectoryPath}`, uploadCandidates);
33+
filesToUpload.push(...uploadCandidates);
34+
if (shouldRecurse) {
35+
let dirsInDir = currentDirectoryContents
36+
.filter(t => fs.lstatSync(path.join(currentDirectoryPath, t))
37+
// this time, query for directories only
38+
.isDirectory()).map(t => path.join(currentDirectoryPath, t));
39+
if (dirsInDir && dirsInDir.length) {
40+
// enqueue directories, continue traversing
41+
dirsInDir.forEach(t => q.enqueue(t));
42+
}
43+
}
44+
}
45+
let uploadStructure = filesToUpload.map(t => {
46+
let relativePath = t.replace(scanDirectory, '');
47+
if (relativePath[0] === '/')
48+
relativePath = relativePath.substring(1);
49+
if (baseContainerPath !== undefined)
50+
relativePath = `${baseContainerPath}/${relativePath}`;
51+
return { absoluteDiskPath: t, relativeUploadPath: relativePath };
52+
});
53+
return uploadStructure;
54+
}

node_modules/.bin/browserslist

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

node_modules/.bin/browserslist-lint

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

node_modules/.bin/create-jest

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

node_modules/.bin/esparse

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

node_modules/.bin/esvalidate

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

node_modules/.bin/import-local-fixture

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

0 commit comments

Comments
 (0)