Skip to content

Commit

Permalink
Updating release
Browse files Browse the repository at this point in the history
  • Loading branch information
armhil committed Jan 28, 2024
1 parent f021a15 commit 2536c54
Show file tree
Hide file tree
Showing 5,540 changed files with 1,248,588 additions and 3 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 0 additions & 3 deletions .gitignore

This file was deleted.

32 changes: 32 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as core from '@actions/core';
import { getFilesForUpload } from './src/file-system-utils';
import { uploadAll } from './src/azure-upload-utils';
try {
/**
* File types to upload should look like
* { ".html": "text/html" }
*/
const fileTypesToUpload = JSON.parse(core.getInput('fileTypesToUpload'));
/**
* Directories to upload should look like
* [
* { directoryToUpload: "", shouldRecurse: "", baseContainerPath: "" }
* ]
*/
const directoriesToUpload = JSON.parse(core.getInput('directoriesToUpload')) || [];
let filesToUpload = [];
directoriesToUpload.forEach(t => {
filesToUpload = filesToUpload.concat(getFilesForUpload(t.directoryToUpload, t.shouldRecurse, t.baseContainerPath, Object.keys(fileTypesToUpload)));
});
/**
* Azure Blob Configurations should look like
* [
* { connectionString: "", container: "" }
* ]
*/
const azureBlobConfiguration = JSON.parse(core.getInput('azureBlobConfiguration'));
uploadAll(azureBlobConfiguration, filesToUpload, fileTypesToUpload);
}
catch (error) {
core.setFailed(error.message);
}
16 changes: 16 additions & 0 deletions dist/src/azure-upload-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { BlobServiceClient } = require('@azure/storage-blob');
const path = require('path');
const fs = require('fs');
export function uploadAll(uploadConfigs, filesToUpload, supportedContentTypes) {
uploadConfigs.forEach(t => {
const blobServiceClient = BlobServiceClient.fromConnectionString(t.connectionString);
const containerClient = blobServiceClient.getContainerClient(t.container);
filesToUpload.forEach(x => {
let stream = fs.readFileSync(x.absoluteDiskPath);
let contentType = supportedContentTypes[path.extname(x.absoluteDiskPath)];
if (!contentType)
throw `Unsupported Content Type for ${x.absoluteDiskPath}`;
containerClient.uploadBlockBlob(x.relativeUploadPath, stream, stream.length, { blobHTTPHeaders: { blobContentType: contentType } });
});
});
}
54 changes: 54 additions & 0 deletions dist/src/file-system-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import fs from 'fs';
import Queue from 'queue-fifo';
import path from 'path';
let q = new Queue();
/**
* Traverses the disk and builds a list/map of which files to upload and with what relative paths.
*
* @param scanDirectory - Directory to scan on the disk
* @param shouldRecurse - If we should recurse and upload files in nested directories
* @param baseContainerPath - Most likely $web for Azure Blobs, if static content is being uploaded
* @param extensionsToUpload - List of extensions to upload
*
* @returns an array of objects which carry absolute path on disk
* and where they would be uploaded in cloud
*/
export function getFilesForUpload(scanDirectory, shouldRecurse, baseContainerPath, extensionsToUpload) {
let filesToUpload = [];
q.enqueue(scanDirectory);
while (!q.isEmpty()) {
const currentDirectoryPath = q.dequeue();
console.log('Traversing directory: ', currentDirectoryPath);
const currentDirectoryContents = fs.readdirSync(currentDirectoryPath);
const filesInCurrentDirectory = currentDirectoryContents
// filter for files only
.filter(t => !fs.lstatSync(path.join(currentDirectoryPath, t)).isDirectory())
// filenames to full path
.map(t => path.join(currentDirectoryPath, t));
console.log(`Files in ${currentDirectoryPath}`, filesInCurrentDirectory);
let uploadCandidates = filesInCurrentDirectory
// make sure we only target the specified extensions
.filter(t => extensionsToUpload.some(x => t.endsWith(x)));
console.log(`Upload candidates from ${currentDirectoryPath}`, uploadCandidates);
filesToUpload.push(...uploadCandidates);
if (shouldRecurse) {
let dirsInDir = currentDirectoryContents
.filter(t => fs.lstatSync(path.join(currentDirectoryPath, t))
// this time, query for directories only
.isDirectory()).map(t => path.join(currentDirectoryPath, t));
if (dirsInDir && dirsInDir.length) {
// enqueue directories, continue traversing
dirsInDir.forEach(t => q.enqueue(t));
}
}
}
let uploadStructure = filesToUpload.map(t => {
let relativePath = t.replace(scanDirectory, '');
if (relativePath[0] === '/')
relativePath = relativePath.substring(1);
if (baseContainerPath !== undefined)
relativePath = `${baseContainerPath}/${relativePath}`;
return { absoluteDiskPath: t, relativeUploadPath: relativePath };
});
return uploadStructure;
}
1 change: 1 addition & 0 deletions node_modules/.bin/browserslist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/browserslist-lint

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/create-jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/import-local-fixture

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jsesc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/node-which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/parser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/resolve

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ts-jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/tsc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/tsserver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2536c54

Please sign in to comment.