Skip to content

Commit 812e6fa

Browse files
devversionjelbourn
authored andcommitted
build: publish docs-content based on branch (#10020)
1 parent 07b4250 commit 812e6fa

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

scripts/deploy/publish-docs-content.sh

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,67 @@ if [[ ! ${*} == *--no-build* ]]; then
1919
$(npm bin)/gulp docs
2020
fi
2121

22-
# Path to the directory that contains the generated docs output.
23-
docsDistPath="./dist/docs"
22+
# Path to the project directory.
23+
projectPath="$(pwd)"
2424

25-
# Path to the release output of the @angular/material-examples package.
26-
examplesPackagePath="./dist/releases/material-examples"
25+
# Path to the directory that contains the generated docs output.
26+
docsDistPath="${projectPath}/dist/docs"
2727

2828
# Path to the cloned docs-content repository.
29-
docsContentPath=./tmp/material2-docs-content
29+
docsContentPath="${projectPath}/tmp/material2-docs-content"
30+
31+
# Path to the release output of the @angular/material-examples package.
32+
examplesPackagePath="${projectPath}/dist/releases/material-examples"
3033

3134
# Git clone URL for the material2-docs-content repository.
3235
docsContentRepoUrl="https://github.com/angular/material2-docs-content"
3336

3437
# Current version of Angular Material from the package.json file
3538
buildVersion=$(node -pe "require('./package.json').version")
3639

40+
# Name of the branch that is currently being deployed.
41+
branchName=${TRAVIS_BRANCH:-'master'}
42+
3743
# Additional information about the last commit for docs-content commits.
3844
commitSha=$(git rev-parse --short HEAD)
3945
commitAuthorName=$(git --no-pager show -s --format='%an' HEAD)
4046
commitAuthorEmail=$(git --no-pager show -s --format='%ae' HEAD)
4147
commitMessage=$(git log --oneline -n 1)
4248
commitTag="${buildVersion}-${commitSha}"
4349

50+
buildVersionName="${buildVersion}-${commitSha}"
51+
buildTagName="${branchName}-${commitSha}"
52+
buildCommitMessage="${branchName} - ${commitMessage}"
53+
54+
echo "Starting deployment of the docs-content for ${buildVersionName} in ${branchName}"
55+
4456
# Remove the docs-content repository if the directory exists
4557
rm -Rf ${docsContentPath}
4658

4759
# Clone the docs-content repository.
4860
git clone ${docsContentRepoUrl} ${docsContentPath} --depth 1
4961

62+
echo "Successfully cloned docs-content repository."
63+
64+
# Go into the repository directory.
65+
cd ${docsContentPath}
66+
67+
echo "Switched into the repository directory."
68+
69+
if [[ $(git ls-remote --heads origin ${branchName}) ]]; then
70+
git checkout ${branchName}
71+
echo "Switched to ${branchName} branch."
72+
else
73+
echo "Branch ${branchName} does not exist on the docs-content repo yet. Creating ${branchName}.."
74+
git checkout -b ${branchName}
75+
echo "Branch created and checked out."
76+
fi
77+
5078
# Remove everything inside of the docs-content repository.
5179
rm -Rf ${docsContentPath}/*
5280

81+
echo "Removed everything from the docs-content repository. Copying all files into repository.."
82+
5383
# Create all folders that need to exist in the docs-content repository.
5484
mkdir ${docsContentPath}/{overview,guides,api,examples,stackblitz,examples-package}
5585

@@ -62,7 +92,7 @@ cp -r ${docsDistPath}/stackblitz/* ${docsContentPath}/stackblitz
6292
cp -r ${examplesPackagePath}/* ${docsContentPath}/examples-package
6393

6494
# Copy the license file to the docs-content repository.
65-
cp ./LICENSE ${docsContentPath}
95+
cp ${projectPath}/LICENSE ${docsContentPath}
6696

6797
# Copy all immediate children of the markdown output the guides/ directory.
6898
for guidePath in $(find ${docsDistPath}/markdown/ -maxdepth 1 -type f); do
@@ -74,8 +104,12 @@ for overviewPath in $(find ${docsDistPath}/markdown/ -mindepth 2 -type f); do
74104
cp ${overviewPath} ${docsContentPath}/overview
75105
done
76106

77-
# Go into the repository directory.
78-
cd ${docsContentPath}
107+
echo "Successfully copied all content into the docs-content repository."
108+
109+
if [[ $(git ls-remote origin "refs/tags/${buildTagName}") ]]; then
110+
echo "Skipping publish of docs-content because tag is already published. Exiting.."
111+
exit 0
112+
fi
79113

80114
# Setup the Git configuration
81115
git config user.name "$commitAuthorName"
@@ -84,7 +118,11 @@ git config credential.helper "store --file=.git/credentials"
84118

85119
echo "https://${MATERIAL2_DOCS_CONTENT_TOKEN}:@github.com" > .git/credentials
86120

121+
echo "Credentials for docs-content repository are now set up. Publishing.."
122+
87123
git add -A
88-
git commit --allow-empty -m "${commitMessage}"
89-
git tag "${commitTag}"
124+
git commit --allow-empty -m "${buildCommitMessage}"
125+
git tag "${buildTagName}"
90126
git push origin master --tags
127+
128+
echo "Published docs-content for ${buildVersionName} into ${branchName} successfully"

0 commit comments

Comments
 (0)