Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action is renaming uploaded files, not preserving original name #34

Closed
andrewconnell opened this issue Sep 13, 2020 · 11 comments · Fixed by #115
Closed

Action is renaming uploaded files, not preserving original name #34

andrewconnell opened this issue Sep 13, 2020 · 11 comments · Fixed by #115

Comments

@andrewconnell
Copy link

andrewconnell commented Sep 13, 2020

I have two files in a folder to upload to the root of an existing container (no sync, no cleaning). I can't figure out looking at the code why this action is renaming my files. Here's the debug output (masking some names with $ because these are customer product downloads).

As you can see from the following logs, it's replacing my filenames with timestamps (YYYYMMDD) and appending als to one of them. I can't see in your code where you're using a datestamp, so I'm assuming that's coming from my filename... it's almost like it's having issues with the underscore in my filename... but why?

##[debug]..=> '/home/runner/work/course-$$$$/course-$$$$'
##[debug]=> '/home/runner/work/course-$$$$/course-$$$$/../azblobupload'
##[debug]Result: '/home/runner/work/course-$$$$/course-$$$$/../azblobupload'
##[debug]Loading env
Run LanceMcCarthy/Action-AzureBlobUpload@v1.7
  with:
    connection_string: ***
    container_name: downloads
    source_folder: /home/runner/work/course-$$$$/course-$$$$/../azblobupload
    clean_destination_folder: false
    fail_if_source_empty: false
  env:
    UTILITY_RELATIVE_PATH: utils/build-materials-download
    CURRENT_DATESTAMP: 20200913
##[debug]sourceFolder: /home/runner/work/course-$$$$/course-$$$$/../azblobupload
##[debug]--- cleaned: /home/runner/work/course-$$$$/course-$$$$/../azblobupload
##[debug]localFilePath: /home/runner/work/course-$$$$/azblobupload/$$$$-$$$1_20200913.zip
##[debug]--- cleaned: /home/runner/work/course-$$$$/azblobupload/$$$$-$$$1_20200913.zip
##[debug]finalPath: als_20200913.zip...
##[debug]sourceFolder: /home/runner/work/course-$$$$/course-$$$$/../azblobupload
##[debug]--- cleaned: /home/runner/work/course-$$$$/course-$$$$/../azblobupload
##[debug]localFilePath: /home/runner/work/course-$$$$/azblobupload/$$$$-$$$2_20200913.zip
##[debug]--- cleaned: /home/runner/work/course-$$$$/azblobupload/$$$$-$$$2_20200913.zip
##[debug]finalPath: 20200913.zip...
Uploaded /home/runner/work/course-$$$$/azblobupload/$$$$-$$$1_20200913.zip to downloads/als_20200913.zip...
Uploaded /home/runner/work/course-$$$$/azblobupload/$$$$-$$$2_20200913.zip to downloads/20200913.zip...
##[debug]Node Action run completed with exit code 0
##[debug]Finishing: Upload ZIPs to Azure Storage Blob
@LanceMcCarthy
Copy link
Owner

Thank you for sharing. This is indeed weird as there is nothing that explicitly changes the name of the file, the only path modifications are stripping off the source root and prefixing any destination root.

I'll take a look at this today, what runner are you using?

@andrewconnell
Copy link
Author

Latest Ubuntu

@LanceMcCarthy
Copy link
Owner

If you need to be up and running now, try the Docker-based Azure Blob upload action from Matthew Fisher https://github.com/marketplace/actions/azure-blob-storage-upload. The parameters are every similar to mine because the Azure SDK is the same for everyone.

In the meantime, I'll continue to test this.

Regarding the timestamp filename, that value seems to be coming from the environment variable CURRENT_DATESTAMP in the workflow. I don't use that variable in the Action, so I have no idea how that could possible become the filename.

However, I do have an ideas about where the 'als' part is coming from. Do you have a previous folder name that ends in als? For example, here's something I think make sense in the context

azblobupload/finals/filename.zip

The ../ in the source path is breaking the file path creation here

const cleanedSourceFolderPath = sourceFolder.replace(/\\/g, '/');
const cleanedFilePath = localFilePath.replace(/\\/g, '/');
let cleanedDestinationFolder = '';
core.debug(`sourceFolder: ${sourceFolder}`);
core.debug(`--- cleaned: ${cleanedSourceFolderPath}`);
core.debug(`localFilePath: ${localFilePath}`);
core.debug(`--- cleaned: ${cleanedFilePath}`);
if (destinationFolder !== '') {
// Replace forward slashes with backward slashes
cleanedDestinationFolder = destinationFolder.replace(/\\/g, '/');
// Remove leading and leading slashes
cleanedDestinationFolder = cleanedDestinationFolder
.split('/')
.filter(x => x)
.join('/');
core.debug(`destinationFolder: ${destinationFolder}`);
core.debug(`-- cleaned: ${cleanedDestinationFolder}`);
}
// Determining the relative path by trimming the source path from the front of the string.
const trimStartPosition = cleanedSourceFolderPath.length - 1;
const trimLength = cleanedFilePath.length - cleanedSourceFolderPath.length + 1;
const trimmedPath = cleanedFilePath.substr(trimStartPosition, trimLength);
let finalPath = '';
if (cleanedDestinationFolder !== '') {
// If there is a DestinationFolder set, prefix it to the relative path.
finalPath = [cleanedDestinationFolder, trimmedPath].join('/');
} else {
// Otherwise, use the file's relative path (this will maintain all subfolders).
finalPath = trimmedPath;
}
// Trim leading slashes, the container is always the root
if (finalPath.startsWith('/')) {
finalPath = finalPath.substr(1);
}
// If there are any double slashes in the path, replace them now
finalPath = finalPath.replace('//', '/');

@andrewconnell
Copy link
Author

I'm uploading the files as artifacts so my short term solution is to manually download & upload the files. Not ideal, but the workflow is only manually run so not a big issue.

The timestamp is part of the filename I'm passing into the action. The als may be coming from the word "fundamentals" which is one of the two things I'm masking in the OP of this issue... but there's another word used that didn't generate that... which is strange.

The reason for the ".."in the filename is because of the variable ${{ github.workspace }} points to the cloned repo in the workspace. The location where the ZIP files are that I want to upload is parallel to that folder. If there was a way to get the value of the folder path for the root of the repo (and not the identical folder name one level down), I could use that... but can't figure how to get around that.

@LanceMcCarthy
Copy link
Owner

The workspace is typically one level down from where the commands are run. So you should be able to just use:

source_folder: ..\azblobupload

Let me know how that goes.

@LanceMcCarthy
Copy link
Owner

Also, I have This Prebuilt TypeScript Playground script that mimics the Action's work.

I use to test certain files paths to see what the outcome would look like without having to make a commit to GitHub, run the Action and wait for every tiny change

Put your string paths in these called out variables, run it and check out Logs pane

image

@ghost
Copy link

ghost commented Apr 1, 2021

I'm also running into this issue. I suspect leading and trailing slashes in sourceFolder and localFilePath has an effect on the resulting trimmedPath. I tested in the TypeScript Playground (very useful!) and will submit a PR for review.

@LanceMcCarthy
Copy link
Owner

Thank you, I will review it today and push out a new release.

@LanceMcCarthy
Copy link
Owner

I have validated, built, test and released v1.8.3 to GitHub Actions Marketplace

  • @jacwil Thank you for opening the PR,
  • @andrewconnell Can you please let me know if you're seeing any problems after updating the workflow to use v1.8.3

If you'd like to see the specifics:

@andrewconnell
Copy link
Author

@LanceMcCarthy I chose to implement the upload using a different method back then. Bit swamped and the workflow works now so no offense if I don't get a chance to go back and test it out ¯_(ツ)_/¯

@LanceMcCarthy
Copy link
Owner

@andrewconnell no offense taken! If you start a new project and need this again, I'm happy to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants