In efbbae5a4, the `publish_packages_as_artifacts` CircleCI job was created to publish the build artifacts of PR builds on CI. In a8f4f14bd, its scope was expanded to also publish build artifacts on non-PR builds. The published artifacts names are constructed based on the PR number (e.g. include `-pr12345-`), so on non-PR builds the names do not reflect the source branch (instead, they include `-prfalse-`). This commit fixes this by using the current branch name. For example, artifact names for the `master` or `9.0.x` branch will include `-master-` and `-9.0.x-` respectively (instead of `-prfalse-`). (NOTE: For PRs, where branch name is `pull/12345`, the branch name is transformed to `pr12345`.) PR Close #33957
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env bash
 | |
| 
 | |
| set -eu -o pipefail
 | |
| 
 | |
| readonly safeBranchName="$(echo $1 | sed 's/^pull\//pr/' | sed 's/[^A-Za-z0-9_.-]/_/g')"
 | |
| readonly shortLastSha="$(git rev-parse --short $2)"
 | |
| readonly inputDir="$PROJECT_ROOT/$3"
 | |
| readonly outputDir="$PROJECT_ROOT/$4"
 | |
| readonly fileSuffix="-$safeBranchName-$shortLastSha.tgz"
 | |
| 
 | |
| echo "Creating compressed archives for packages in '$inputDir'."
 | |
| 
 | |
| # Create or clean-up the output directory.
 | |
| echo "  Preparing output directory: $outputDir"
 | |
| rm -rf "$outputDir"
 | |
| mkdir -p "$outputDir"
 | |
| 
 | |
| # If there are more than one packages in `$inputDir`...
 | |
| if [[ $(ls -1 "$inputDir" | wc -l) -gt 1 ]]; then
 | |
|   # Create a compressed archive containing all packages.
 | |
|   # (This is useful for copying all packages into `node_modules/` (without changing `package.json`).)
 | |
|   outputFileName=all$fileSuffix
 | |
|   echo "  Creating archive with all packages --> '$outputFileName'..."
 | |
|   tar --create --gzip --directory "$inputDir" --file "$outputDir/$outputFileName" --transform s/^\./packages/ .
 | |
| fi
 | |
| 
 | |
| # Create a compressed archive for each package.
 | |
| # (This is useful for referencing the path/URL to the resulting archive in `package.json`.)
 | |
| for dir in $inputDir/*
 | |
| do
 | |
|   packageName=`basename "$dir"`
 | |
|   outputFileName="$packageName$fileSuffix"
 | |
|   outputFilePath="$outputDir/$outputFileName"
 | |
| 
 | |
|   echo "  Processing package '$packageName' --> '$outputFileName'..."
 | |
| 
 | |
|   tar --create --gzip --directory "$dir" --file "$outputFilePath" --transform s/^\./package/ .
 | |
| done
 | |
| 
 | |
| echo "Done creating compressed archives."
 |