-
Notifications
You must be signed in to change notification settings - Fork 6.8k
ci: setup automatic deployment for the docs app #24528
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Script that builds the docs content NPM package and moves it into a conveniently | ||
* accessible distribution directory (the project `dist/` directory). | ||
*/ | ||
|
||
import {cd, chmod, cp, exec, mkdir, rm, set} from 'shelljs'; | ||
|
||
import {BuiltPackage} from '@angular/dev-infra-private/ng-dev'; | ||
import {join} from 'path'; | ||
|
||
/** Path to the project directory. */ | ||
const projectDir = join(__dirname, '../'); | ||
devversion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Path to the distribution directory. */ | ||
const distDir = join(projectDir, 'dist/'); | ||
|
||
/** | ||
* Path to the directory where the docs-content package is copied to. Note: When | ||
* changing the path, also change the path in the docs-content deploy script. | ||
*/ | ||
const outputDir = join(distDir, 'docs-content-pkg'); | ||
|
||
/** Command that runs Bazel. */ | ||
const bazelCmd = process.env.BAZEL || `yarn -s bazel`; | ||
|
||
/** | ||
* Builds the docs content NPM package in snapshot mode. | ||
* | ||
* @returns an object describing the built package and its output path. | ||
*/ | ||
export function buildDocsContentPackage(): BuiltPackage { | ||
// ShellJS should exit if a command fails. | ||
set('-e'); | ||
|
||
// Go to project directory. | ||
cd(projectDir); | ||
|
||
/** Path to the bazel bin output directory. */ | ||
const bazelBinPath = exec(`${bazelCmd} info bazel-bin`).stdout.trim(); | ||
|
||
/** Path where the NPM package is built into by Bazel. */ | ||
const bazelBinOutDir = join(bazelBinPath, 'src/components-examples/npm_package'); | ||
|
||
// Clean the output directory to ensure that the docs-content package | ||
// will not contain outdated files from previous builds. | ||
rm('-rf', outputDir); | ||
mkdir('-p', distDir); | ||
devversion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Build the docs-content package with the snapshot-build mode. That will help | ||
// determining which commit is associated with the built docs-content. | ||
exec(`${bazelCmd} build src/components-examples:npm_package --config=snapshot-build`); | ||
|
||
// Copy the package output into the dist path. Also update the permissions | ||
// as Bazel by default marks files in the bazel-out as readonly. | ||
cp('-R', bazelBinOutDir, outputDir); | ||
chmod('-R', 'u+w', outputDir); | ||
|
||
return { | ||
name: '@angular/components-examples', | ||
outputPath: outputDir, | ||
}; | ||
} | ||
|
||
if (require.main === module) { | ||
const builtPackage = buildDocsContentPackage(); | ||
console.info(`Built docs-content into: ${builtPackage.outputPath}`); | ||
} | ||
devversion marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Docs app deployment | ||
|
||
https://docs.google.com/document/d/1xkrSOFa6WeFqyg1cTwMhl_wB8ygbVwdSxr3K2-cps14/edit?usp=sharing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
import {$} from 'zx'; | ||
devversion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import {projectDir} from './utils'; | ||
|
||
/** Git repository HTTP url pointing to the docs repository. */ | ||
export const docsRepoUrl = 'https://github.com/angular/material.angular.io.git'; | ||
|
||
/** | ||
* Clones the docs repository for the given major into a | ||
* temporary directory. | ||
* | ||
* @returns An absolute path to the temporary directory. | ||
*/ | ||
export async function cloneDocsRepositoryForMajor(major: number): Promise<string> { | ||
const repoTmpDir = path.join(projectDir, 'tmp/docs-repo'); | ||
devversion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const baseCloneArgs = [docsRepoUrl, repoTmpDir, '--single-branch', '--depth=1']; | ||
const majorDocsBranchName = getDocsBranchNameForMajor(major); | ||
|
||
// Cleanup the temporary repository directory if it exists. | ||
try { | ||
await fs.promises.rm(repoTmpDir, {recursive: true}); | ||
} catch {} | ||
|
||
// Clone the docs app (either the main branch, or a dedicated major branch if available). | ||
if (await hasUpstreamDocsBranch(majorDocsBranchName)) { | ||
console.log(`Cloning docs app with dedicated branch: ${majorDocsBranchName}`); | ||
await $`git clone ${baseCloneArgs} --branch=${majorDocsBranchName}`; | ||
} else { | ||
console.log(`Cloning docs app with default branch (no dedicated branch for major).`); | ||
await $`git clone ${baseCloneArgs}`; | ||
} | ||
|
||
return repoTmpDir; | ||
} | ||
|
||
/** | ||
* Gets whether the specified branch exists in the specified remote URL. | ||
*/ | ||
async function hasUpstreamDocsBranch(branchName: string): Promise<boolean> { | ||
try { | ||
const proc = await $`git ls-remote ${docsRepoUrl} refs/heads/${branchName}`; | ||
return proc.stdout.trim() !== ''; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the name of a potential dedicated branch for this major in the | ||
* docs repository. | ||
* | ||
* e.g. if a branch like `13.x` exists and we intend to deploy v13, then | ||
* this branch can be used as revision for the docs-app. | ||
* | ||
* More details on why this is preferred: | ||
* https://docs.google.com/document/d/1xkrSOFa6WeFqyg1cTwMhl_wB8ygbVwdSxr3K2-cps14/edit#heading=h.nsf3ag63jpwu. | ||
*/ | ||
function getDocsBranchNameForMajor(major: number): string { | ||
return 'firebase-target'; | ||
// TODO return `${major}.x`; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.