Skip to content

Commit

Permalink
chore: merge latest in develop to resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
roadlittledawn committed Feb 7, 2022
2 parents aed177d + 7865a12 commit ed47d74
Show file tree
Hide file tree
Showing 711 changed files with 68,227 additions and 19,730 deletions.
33 changes: 9 additions & 24 deletions .github/workflows/update-whats-new-ids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: develop
persist-credentials: false
fetch-depth: '0'

- name: Setup node.js
uses: actions/setup-node@v1
Expand All @@ -41,7 +40,6 @@ jobs:
git add ./src/data/whats-new-ids.json
git diff-index --quiet HEAD ./src/data/whats-new-ids.json || git commit -m 'chore(whats-new-ids): updated ids'
echo "::set-output name=commit::true"
- name: Temporarily disable branch protection
id: disable-branch-protection
uses: actions/github-script@v1
Expand All @@ -52,22 +50,21 @@ jobs:
const result = await github.repos.updateBranchProtection({
owner: context.repo.owner,
repo: context.repo.repo,
branch: 'develop',
branch: context.payload.pull_request.head.ref,
required_status_checks: null,
restrictions: null,
enforce_admins: null,
required_pull_request_reviews: null
})
console.log("Result:", result)
# Push directly to the `develop` branch so we get the changes included in the release PR
# Push directly to the current release branch so we get the changes included in the release PR

- name: Push Commit
if: steps.commit-changes.outputs.commit == 'true'
uses: ad-m/github-push-action@v0.6.0
with:
github_token: ${{ secrets.OPENSOURCE_BOT_TOKEN }}
branch: develop
branch: ${{ github.head_ref }}

- name: Re-enable branch protection
id: enable-branch-protection
Expand All @@ -80,25 +77,13 @@ jobs:
const result = await github.repos.updateBranchProtection({
owner: context.repo.owner,
repo: context.repo.repo,
branch: 'develop',
required_status_checks: {
strict: false,
contexts: [
'Gatsby Build Service - docs-website-develop',
'run linter',
'run tests',
'license/cla',
'unpaired translations removed'
]
},
restrictions: {
users: [],
teams: ['developer-enablement']
},
enforce_admins: null,
branch: context.payload.pull_request.head.ref,
enforce_admins: true,
required_status_checks: null,
restrictions: null,
required_pull_request_reviews: {
dismiss_stale_reviews: true,
required_approving_review_count: 1
}
})
console.log("Result:", result)
console.log("Result:", result)
2 changes: 1 addition & 1 deletion jest-preprocess.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = require('babel-jest').createTransformer({
module.exports = require('babel-jest').default.createTransformer({
presets: ['babel-preset-gatsby', '@emotion/babel-preset-css-prop'],
});
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
transform: {
'^.+\\.jsx?$': '<rootDir>/jest-preprocess.js',
'.(ts|tsx)': 'ts-jest',
},
moduleNameMapper: {
'.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
Expand All @@ -16,4 +17,6 @@ module.exports = {
},
setupFiles: ['<rootDir>/loadershim.js'],
setupFilesAfterEnv: ['<rootDir>/setup-test-env.js'],
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
moduleFileExtensions: ['js', 'ts', 'tsx', 'json'],
};
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"@mdx-js/react": "^2.0.0-next.8",
"@newrelic/gatsby-theme-newrelic": "^4.1.8",
"@splitsoftware/splitio-react": "^1.2.4",
"babel-jest": "^26.3.0",
"common-tags": "^1.8.0",
"date-fns": "^2.17.0",
"front-matter": "^4.0.2",
Expand Down Expand Up @@ -40,9 +39,6 @@
"hast-util-phrasing": "^1.0.5",
"hast-util-select": "^4.0.2",
"hast-util-to-mdast": "^7.1.3",
"jest": "^26.6.3",
"jest-emotion": "^10.0.32",
"jest-when": "^3.3.1",
"jsdom": "^16.5.0",
"lodash": "^4.17.21",
"parse-link-header": "^1.0.1",
Expand Down Expand Up @@ -70,6 +66,7 @@
},
"devDependencies": {
"@newrelic/eslint-plugin-newrelic": "^0.3.1",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.10",
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.11",
Expand Down Expand Up @@ -114,10 +111,18 @@
"remark-mdxjs": "^2.0.0-next.8",
"remark-parse": "8.0.3",
"remark-stringify": "^8.1.1",
"simple-git": "^3.1.0",
"source-map-loader": "^3.0.1",
"sync-fetch": "^0.3.0",
"to-vfile": "^6.1.0",
"ts-jest": "^27.1.3",
"jest": "^27.4.7",
"babel-jest": "~27.4.6",
"jest-emotion": "^10.0.32",
"jest-when": "^3.3.1",
"jest-mock-extended": "^2.0.4",
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"typescript": "^4.5.5",
"unified": "^9.2.0",
"unist-builder": "^2.0.3",
Expand All @@ -137,6 +142,7 @@
"node-forge": "^0.10.0",
"node-fetch": "^2.6.1",
"ini": "^1.3.6",
"yargs": "^13.3.2",
"yargs-parser": "^18.1.1"
},
"keywords": [
Expand Down Expand Up @@ -168,7 +174,8 @@
"verify-mdx": "node scripts/verify_mdx.js",
"add-remove-redirects": "node scripts/utils/docs-content-tools/add-remove-redirects.js",
"db:start": "docker-compose --file scripts/actions/translation_workflow/testing/docker-compose.yml up --build",
"db:clean": "./scripts/actions/translation_workflow/testing/cleanup.sh"
"db:clean": "./scripts/actions/translation_workflow/testing/cleanup.sh",
"i18n-utility": "npx ts-node ./scripts/i18n_utility/cli.ts"
},
"husky": {
"hooks": {
Expand Down
7 changes: 2 additions & 5 deletions scripts/actions/__tests__/vendor-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const MOCK_FAILURE_JSON = {
};

describe('Action: Send and update translation queue', () => {
beforeEach(() => {
jest.setTimeout(10000);
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllTimers();
Expand Down Expand Up @@ -64,7 +61,7 @@ describe('Action: Send and update translation queue', () => {
expect(global.console.error).toBeCalledTimes(1);
expect(global.console.warn).toBeCalledTimes(4);
}
});
}, 10000);

test('makeRequest, with no `nthTry` specified, should default to 1 and retry 4 times before throwing an error', async () => {
for (let i = 0; i < 5; i++) {
Expand All @@ -76,7 +73,7 @@ describe('Action: Send and update translation queue', () => {
expect(global.console.error).toBeCalledTimes(1);
expect(global.console.warn).toBeCalledTimes(4);
}
});
}, 10000);

test('makeRequest, given an nthTry of 3, should retry twice before throwing an error', async () => {
const mockNth = 3;
Expand Down
2 changes: 1 addition & 1 deletion scripts/actions/fetch-and-deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const deserializeHtmlToMdx = (locale) => {
* @returns {Promise<SlugStatus>}
*/
return async ({ path: contentPath, html }) => {
const completePath = path.join('src/content/docs', contentPath, '.mdx');
const completePath = `${path.join('src/content/docs', contentPath)}.mdx`;

try {
const localePath = path.join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ excludePath:
- src/content/docs/security/security-privacy/compliance
- scripts/actions/__tests__/kitchen-sink.mdx
- src/content/docs/infrastructure/manage-your-data/data-instrumentation/host-integrations-metrics.mdx
- src/content/docs/apm/agents/net-agent/configuration/net-agent-configuration.mdx
excludeType:
ja-JP:
- landingPage
123 changes: 123 additions & 0 deletions scripts/i18n_utility/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Translation Utility Script

## Introduction

### Translated files and translation directory structure

The english version of the site has content located under `src/content/docs`. For locale specific versions of the site, japanese for example, we translate a piece of content (an mdx file) into japanese and store the file in a path that mirrors the english version of the site. For japansese, this would be `src/i18n/content/jp/docs`. If we have an english file that lives at `src/content/docs/accounts/accounts/account-maintenance/change-passwords-user-preferences.mdx` its japanese equivalent would live at `src/i18n/content/jp/docs/accounts/accounts/account-maintenance/change-passwords-user-preferences.mdx`. For other locales, you can swap out the locale value in the path to get the appropriate location. For another language, say korean, its content would live under the path `src/i18n/content/kr/docs/`.

### Orphaned files -- what are they, how does a file become orphaned, why do we care

Periodically, changes are made to the english content. If the change is solely limited to content, a translation will be submitted for the new updated file and the process works seamlessly.

An orphaned file is a file that lives under `src/i18n/content/[locale]/docs` that does not have an english counterpart (underneath `src/content/docs`). Files that are orphaned are NOT providing any value, and exist only to take up space in the repository. Additionally, in the process of creating an orphaned file, content may be out of date or incorrect.

If we move or delete an english file and forget to do the same for its translated counterparts, we create orphaned files. For content that we delete, this strictly is just taking up space in the repository. For content that we move, if we dont also move the equivalent translated content, the translated version of the site will display english content despite us having translated content -- this is because localized pages on the site are explicitly tied to file paths matching up. This isn't permanent, but in the period in which content is being translated the localized version of the site will not be as accurate as it could be.

### Utility

This is a command-line utility to:

* identify orphaned translation related files
* delete orphaned files
* identify rename changes to make for translation related files
* make rename changes for translation related files

## Troubleshooting

There are a couple scenarios that are easy enough to find yourself in where you may not see output that you expect to, or you think the script isn't running correctly.

### Scenario: You see a rename change you didn't make

It may be the case that you see a (rename) change listed that you did not make. The script runs against `origin/develop` and creates a diff between the two branches. This can include changes that do not exist locally if the branch is behind develop. The more behind a branch is, the higher the chance of running into this is.

The fix: keep working branch up to date. Merge or rebase with develop frequently (this is a good habit to have in general).

### Scenario: Your rename isn't detected by git

Git will naturally see renames changes as add a new file, delete your old file. For example, if you rename a file `README.md` -> `NEW_README.md`, git will see this as deleting README.md, and adding NEW_README.md until you stage BOTH changes. At that point, git uses a diff algorithm to make a best guess at whether to consolidate that change as a rename. If you only move or rename file, and do not change content, git should see that as a rename.

However, if you move a file and change its content, depending on how much the file is changed, git may not be able to detect that you renamed a file. The more a file changes (and changes significantly), the likelier git thinks its a new file.

The fix: If you intend to rename & change the content of a file, try to commit those changes separately -- one commit for the rename, one for the content update. Also, if you are renaming a file, using the `git mv` command explicitly tells git that you are renaming a file. This will also let you make content & rename changes in one commit.

## Commands & Examples

### Commands

The following commands are available when running the script:

```sh
help
list-orphans
delete-orphans
list-renames
make-renames
```

To run a given command, simply append it to the yarn script command: `yarn i18n-utility`.

### Examples

#### List orphans

```sh
# invoke
> yarn i18n-utility list-orphans

# output
Found 2 orphaned files.
[
"~/repos/docs-website/src/i18n/content/jp/docs/accounts/accounts-billing/general-account-settings/introduction-account-settings.mdx",
"~/repos/docs-website/src/i18n/content/jp/docs/accounts/accounts-billing/new-relic-one-user-management/images/New-Relic-capabilities-UI-screenshot.png",
]
```

#### Delete orphans

```sh
# invoke
> yarn i18n-utility delete-orphans

# output
Deleting: /Users/kkenney/repos/docs-website/src/i18n/content/jp/docs/accounts/accounts-billing/general-account-settings/introduction-account-settings.mdx
Deleting: /Users/kkenney/repos/docs-website/src/i18n/content/jp/docs/accounts/accounts-billing/new-relic-one-user-management/images/New-Relic-capabilities-UI-screenshot.png
```

#### List renames

```sh
# invoke
> yarn i18n-utility list-renames

# output
1 files will be moved.
[
{
"from": "src/i18n/content/jp/docs/accounts/accounts/account-maintenance/change-passwords-user-preferences.mdx",
"to": "src/i18n/content/jp/docs/change-passwords-user-preferences.mdx"
}
]
```

#### Make renames

```sh
# invoke
> yarn i18n-utility make-renames

# output
Moving src/i18n/content/jp/docs/accounts/accounts/account-maintenance/change-passwords-user-preferences.mdx to src/i18n/content/jp/docs/change-passwords-user-preferences.mdx
```

## Code Layout & Organization

The script uses [commander](https://github.com/tj/commander.js/) to implement common CLI functionality.

The file names -- `actions.ts`, `commands.ts` -- reflect core terms from Commander, which are explained below.

The overall organization (and why) is:

* `cli.ts` is the entrypoint for running the CLI. It houses `Program` and is where we explicitly connect commands to the CLI.
* `commands.ts` is where the CLI commands are defined. Commands are exported from here & connected in `cli.ts`. Additionally, actions are imported into here and hooked up for each command.
* `actions.ts` is where the implementation of functionality happens. At the the moment, the code is organized in such a way that if you have the `list-orphans` command, there is a method in actions called `list-orphans` that defines the actual functionality of that command. There are actually more actions than there are commands, to fill in intermediate steps that dont have explicit commands, but the approach above is kind of the guiding rail.

0 comments on commit ed47d74

Please sign in to comment.