forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7,207 changed files
with
286,900 additions
and
268,983 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains 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 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 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,43 @@ | ||
#!/usr/bin/env bash | ||
#------------------------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. | ||
#------------------------------------------------------------------------------------------------------------- | ||
# | ||
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/master/script-library/docs/github.md | ||
# | ||
# Syntax: ./github-debian.sh [version] | ||
|
||
CLI_VERSION=${1:-"latest"} | ||
|
||
set -e | ||
|
||
if [ "$(id -u)" -ne 0 ]; then | ||
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' | ||
exit 1 | ||
fi | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
# Install curl, apt-transport-https or gpg if missing | ||
if ! dpkg -s curl ca-certificates > /dev/null 2>&1; then | ||
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then | ||
apt-get update | ||
fi | ||
apt-get -y install --no-install-recommends curl ca-certificates | ||
fi | ||
|
||
# Get latest release number if latest is specified | ||
if [ "${CLI_VERSION}" = "latest" ] || [ "${CLI_VERSION}" = "current" ] || [ "${CLI_VERSION}" = "lts" ]; then | ||
LATEST_RELEASE=$(curl -sSL -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/cli/cli/releases?per_page=1&page=1") | ||
CLI_VERSION=$(echo ${LATEST_RELEASE} | grep -oE 'tag_name":\s*"v[^"]+' | sed -n '/tag_name":\s*"v/s///p') | ||
fi | ||
|
||
# Install the GitHub CLI | ||
echo "Downloading github CLI..." | ||
curl -OsSL https://github.com/cli/cli/releases/download/v${CLI_VERSION}/gh_${CLI_VERSION}_linux_amd64.deb | ||
echo "Installing github CLI..." | ||
apt-get install ./gh_${CLI_VERSION}_linux_amd64.deb | ||
echo "Removing github CLI deb file after installation..." | ||
rm -rf ./gh_${CLI_VERSION}_linux_amd64.deb | ||
echo "Done!" |
This file contains 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,12 @@ | ||
.devcontainer/ | ||
.git/ | ||
.github/ | ||
.vscode/ | ||
contributing/ | ||
docs/ | ||
node_modules/ | ||
script/ | ||
tests/ | ||
lib/rest/static/dereferenced | ||
# Folder is cloned during the preview + prod workflows, the assets are merged into other locations for use before the build | ||
docs-early-access/ |
This file contains 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 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 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,142 @@ | ||
#!/usr/bin/env node | ||
|
||
import fs from 'fs' | ||
import github from '@actions/github' | ||
|
||
const OPTIONS = Object.fromEntries( | ||
['BASE', 'BODY_FILE', 'GITHUB_TOKEN', 'HEAD', 'LANGUAGE', 'TITLE', 'GITHUB_REPOSITORY'].map( | ||
(envVarName) => { | ||
const envVarValue = process.env[envVarName] | ||
if (!envVarValue) { | ||
throw new Error(`You must supply a ${envVarName} environment variable`) | ||
} | ||
return [envVarName, envVarValue] | ||
} | ||
) | ||
) | ||
|
||
if (!process.env.GITHUB_REPOSITORY) { | ||
throw new Error('GITHUB_REPOSITORY environment variable not set') | ||
} | ||
|
||
const RETRY_STATUSES = [ | ||
422, // Retry the operation if the PR already exists | ||
502, // Retry the operation if the API responds with a `502 Bad Gateway` error. | ||
] | ||
const RETRY_ATTEMPTS = 3 | ||
const { | ||
// One of the default environment variables provided by Actions. | ||
GITHUB_REPOSITORY, | ||
|
||
// These are passed in from the step in the workflow file. | ||
TITLE, | ||
BASE, | ||
HEAD, | ||
LANGUAGE, | ||
BODY_FILE, | ||
GITHUB_TOKEN, | ||
} = OPTIONS | ||
const [OWNER, REPO] = GITHUB_REPOSITORY.split('/') | ||
|
||
const octokit = github.getOctokit(GITHUB_TOKEN) | ||
|
||
/** | ||
* @param {object} config Configuration options for finding the PR. | ||
* @returns {Promise<number | undefined>} The PR number. | ||
*/ | ||
async function findPullRequestNumber(config) { | ||
// Get a list of PRs and see if one already exists. | ||
const { data: listOfPullRequests } = await octokit.rest.pulls.list({ | ||
owner: config.owner, | ||
repo: config.repo, | ||
head: `${config.owner}:${config.head}`, | ||
}) | ||
|
||
return listOfPullRequests[0]?.number | ||
} | ||
|
||
/** | ||
* When this file was first created, we only introduced support for creating a pull request for some translation batch. | ||
* However, some of our first workflow runs failed during the pull request creation due to a timeout error. | ||
* There have been cases where, despite the timeout error, the pull request gets created _anyway_. | ||
* To accommodate this reality, we created this function to look for an existing pull request before a new one is created. | ||
* Although the "find" check is redundant in the first "cycle", it's designed this way to recursively call the function again via its retry mechanism should that be necessary. | ||
* | ||
* @param {object} config Configuration options for creating the pull request. | ||
* @returns {Promise<number>} The PR number. | ||
*/ | ||
async function findOrCreatePullRequest(config) { | ||
const found = await findPullRequestNumber(config) | ||
|
||
if (found) { | ||
return found | ||
} | ||
|
||
try { | ||
const { data: pullRequest } = await octokit.rest.pulls.create({ | ||
owner: config.owner, | ||
repo: config.repo, | ||
base: config.base, | ||
head: config.head, | ||
title: config.title, | ||
body: config.body, | ||
draft: false, | ||
}) | ||
|
||
return pullRequest.number | ||
} catch (error) { | ||
if (!error.response || !config.retryCount) { | ||
throw error | ||
} | ||
|
||
if (!config.retryStatuses.includes(error.response.status)) { | ||
throw error | ||
} | ||
|
||
console.error(`Error creating pull request: ${error.message}`) | ||
console.warn(`Retrying in 5 seconds...`) | ||
await new Promise((resolve) => setTimeout(resolve, 5000)) | ||
|
||
config.retryCount -= 1 | ||
|
||
return findOrCreatePullRequest(config) | ||
} | ||
} | ||
|
||
/** | ||
* @param {object} config Configuration options for labeling the PR | ||
* @returns {Promise<undefined>} | ||
*/ | ||
async function labelPullRequest(config) { | ||
await octokit.rest.issues.update({ | ||
owner: config.owner, | ||
repo: config.repo, | ||
issue_number: config.issue_number, | ||
labels: config.labels, | ||
}) | ||
} | ||
|
||
async function main() { | ||
const options = { | ||
title: TITLE, | ||
base: BASE, | ||
head: HEAD, | ||
body: fs.readFileSync(BODY_FILE, 'utf8'), | ||
labels: ['translation-batch', `translation-batch-${LANGUAGE}`], | ||
owner: OWNER, | ||
repo: REPO, | ||
retryStatuses: RETRY_STATUSES, | ||
retryCount: RETRY_ATTEMPTS, | ||
} | ||
|
||
options.issue_number = await findOrCreatePullRequest(options) | ||
const pr = `${GITHUB_REPOSITORY}#${options.issue_number}` | ||
console.log(`Created PR ${pr}`) | ||
|
||
// metadata parameters aren't currently available in `github.rest.pulls.create`, | ||
// but they are in `github.rest.issues.update`. | ||
await labelPullRequest(options) | ||
console.log(`Updated ${pr} with these labels: ${options.labels.join(', ')}`) | ||
} | ||
|
||
main() |
This file contains 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,37 @@ | ||
#!/usr/bin/env bash | ||
|
||
# [start-readme] | ||
# | ||
# This script sets environment variables with info about the preview app for a given PR | ||
# | ||
# [end-readme] | ||
|
||
# ENV VARS NEEDED TO RUN | ||
[[ -z $GITHUB_REPOSITORY ]] && { echo "Missing GITHUB_REPOSITORY. Exiting."; exit 1; } | ||
[[ -z $PR_NUMBER ]] && { echo "Missing PR_NUMBER. Exiting."; exit 1; } | ||
[[ -z $GITHUB_ENV ]] && { echo "Missing GITHUB_ENV. Exiting."; exit 1; } | ||
[[ -z $APP_NAME_SEED ]] && { echo "Missing APP_NAME_SEED. Exiting."; exit 1; } | ||
|
||
PREVIEW_ENV_LOCATION="eastus" | ||
echo "PREVIEW_ENV_LOCATION=${PREVIEW_ENV_LOCATION}" >> $GITHUB_ENV | ||
|
||
REPO_NAME="${GITHUB_REPOSITORY#*\/}" | ||
echo "REPO_NAME=${REPO_NAME}" >> $GITHUB_ENV | ||
|
||
DEPLOYMENT_NAME="${REPO_NAME}-pr-${PR_NUMBER}" | ||
echo "DEPLOYMENT_NAME=${DEPLOYMENT_NAME}" >> $GITHUB_ENV | ||
|
||
APP_NAME_BASE="${REPO_NAME}-preview-${PR_NUMBER}" | ||
echo "APP_NAME_BASE=${APP_NAME_BASE}" >> $GITHUB_ENV | ||
|
||
# pseudo random string so guessing a preview env URL is more difficult | ||
APP_SHA=$(echo -n "${APP_NAME_SEED}-${APP_NAME_BASE}" | sha1sum | cut -c1-6) | ||
|
||
APP_NAME="${APP_NAME_BASE}-${APP_SHA}" | ||
echo "APP_NAME=${APP_NAME}" >> $GITHUB_ENV | ||
|
||
APP_URL="https://${APP_NAME}.${PREVIEW_ENV_LOCATION}.azurecontainer.io" | ||
echo "APP_URL=${APP_URL}" >> $GITHUB_ENV | ||
|
||
IMAGE_REPO="${GITHUB_REPOSITORY}/pr-${PR_NUMBER}" | ||
echo "IMAGE_REPO=${IMAGE_REPO}" >> $GITHUB_ENV |
This file contains 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,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
# [start-readme] | ||
# | ||
# This script takes docs-early-access files and merges them into docs-internal | ||
# | ||
# [end-readme] | ||
|
||
mv docs-early-access/assets/images assets/images/early-access | ||
mv docs-early-access/content content/early-access | ||
mv docs-early-access/data data/early-access |
This file contains 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,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
# [start-readme] | ||
# | ||
# This script removes files that are unnecessary for our preview environments. | ||
# This is typically run before a docker build to reduce the size of the build context sent to docker | ||
# | ||
# [end-readme] | ||
|
||
# Remove all but the english search indexes | ||
find lib/search/indexes ! -name '*-en.json.br' ! -name '*-en-records.json.br' -maxdepth 1 -type f -delete | ||
|
||
# Translations are never tested in preview environments | ||
# but let's keep the empty directory. | ||
rm -rf translations | ||
mkdir translations | ||
|
||
# The assumption here is that a preview build will not | ||
# need these legacy redirects. Only the redirects from | ||
# front-matter will be at play. | ||
# These static redirects json files are notoriously large | ||
echo '[]' > lib/redirects/static/archived-frontmatter-fallbacks.json | ||
echo '{}' > lib/redirects/static/developer.json | ||
echo '{}' > lib/redirects/static/archived-redirects-from-213-to-217.json |
This file contains 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 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
Oops, something went wrong.