Skip to content
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

[Chores] Automated API doc generation and added packages/samples filter #1470

Merged
merged 24 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Our versioning strategy is as follows:

### 🧹 Chores

* Automated API doc generation and added packages/samples filter ([#1470](https://github.com/Sitecore/jss/pull/1470))
* Revisit and update github ISSUE_TEMPLATE ([#1445](https://github.com/Sitecore/jss/pull/1445))
* Configure the recommended VSCode extensions for the starters ([#1437](https://github.com/Sitecore/jss/pull/1437))
* `[templates/nextjs]` `[templates/nextjs-styleguide-tracking]` Move remaining Styleguide-Tracking artifacts from the base template ([#1422](https://github.com/Sitecore/jss/pull/1422))
Expand Down
33 changes: 24 additions & 9 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,49 @@ steps:
displayName: 'lint samples'
condition: and(succeeded(), ne(variables.shouldPublish, true))

#
# LERNA VERSION
# * Configure git with a commit user
# * Update git remote to include a Personal Access Token, so lerna can push
# * Explicitly check out the current branch since Pipelines will use disconnected HEAD by default
# * Increment pre-release version
# * Force version update even if lerna doesn't detect changes
# * Include [skip ci] in commit message to stop pipeline from triggering again when lerna pushes
# * Only run for 'dev' branch
#
# * Only run for 'dev' and 'release' branches
- script: |
git config user.email builds@sitecore.com
git config user.name "Automated Build"
git remote set-url origin https://$GITHUB_PAT_ENV@github.com/Sitecore/jss.git
git checkout $(branchName)
displayName: 'apply git configuration'
condition: and(succeeded(), eq(variables.shouldPublish, true))
env:
GITHUB_PAT_ENV: $(GITHUB-PAT)

# Only run for 'dev' and 'release' branches
# in order to don't produce extra changes in the Pull Request
- script: |
yarn generate-docs
git add ./ref-docs/**/*
git commit -m "Update API docs [skip ci]"
displayName: 'generate API docs'
condition: and(succeeded(), eq(variables.shouldPublish, true))

#
# LERNA VERSION
# * Increment pre-release version
# * Force version update even if lerna doesn't detect changes
# * Include [skip ci] in commit message to stop pipeline from triggering again when lerna pushes
# * Only run for 'dev' and 'release' branches
#
- script: |
$(npm bin)/lerna version prerelease --preid canary --force-publish --message "version %s [skip ci]" --yes
displayName: 'pre-release version update'
condition: and(succeeded(), eq(variables.shouldPublish, true))
illiakovalenko marked this conversation as resolved.
Show resolved Hide resolved
env:
GITHUB_PAT_ENV: $(GITHUB-PAT)
YARN_ENABLE_IMMUTABLE_INSTALLS: false
#
# LERNA PUBLISH
# * Configure npm to use the provided access token, so lerna can publish
# * Do a lerna canary publish of the version we've already updated and pushed
# * Disable access verification (no-verify-access) as this doesn't seem to work behind Azure DevOps' npm proxy
# * https://github.com/lerna/lerna/issues/1685
# * Only run for 'dev' branch
# * Only run for 'dev' and 'release' branches
#
- script: |
echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"scripts": {
"reset": "lerna clean --yes && yarn dlx rimraf node_modules && yarn install && yarn build",
"build": "lerna run build",
"lint-packages": "lerna run lint",
"lint-samples": "lerna run lint --scope 'sample-*' -- --fix",
"lint-packages": "lerna run lint --since=origin/dev",
"scaffold-samples": "node ./scripts/scaffold-samples.js",
"lint-samples": "node ./scripts/lint-samples.js",
"coverage-packages": "lerna run coverage",
"test-packages": "lerna run test",
"install-git-hooks": "node ./scripts/install-hooks.js",
"generate-docs": "lerna run generate-docs",
"generate-docs": "lerna run generate-docs --since=origin/dev",
"version": "yarn install && git stage yarn.lock"
},
"author": {
Expand Down
45 changes: 45 additions & 0 deletions scripts/lint-samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { execSync } = require('child_process');
const samples = require('./samples.json');
const { getAppName } = require('./utils');

/**
* Start linting process only for the samples that were affected by the new changes in:
* - create-sitecore-jss/src/templates/**
* - create-sitecore-jss/src/initializers/**
*/

const affectedTemplates = execSync(
'git diff --name-only origin/dev... -- packages/create-sitecore-jss',
{
encoding: 'utf-8',
}
)
.split('\n')
.map((filepath) => {
// Extracting template names from the filepath
const template = filepath.match(/(templates|initializers)\/([^\/]*)/);
ambrauer marked this conversation as resolved.
Show resolved Hide resolved

return template && template[2];
})
// Removing null values and leaving unique template names
.filter((template, index, list) => template && list.indexOf(template) === index);

if (!affectedTemplates.length) {
console.log('No modified templates to lint');

return;
}

const affectedSamples = samples
.filter((sample) => sample.initializers.some((template) => affectedTemplates.includes(template)))
.map((sample) => getAppName(sample.args));

if (!affectedSamples.length) {
console.log('No modified samples to lint');

return;
}

execSync(`npx lerna run lint --scope={${affectedSamples.join(',')}} -- --fix`, {
stdio: 'inherit',
});
7 changes: 4 additions & 3 deletions scripts/scaffold-samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const chalk = require('chalk');

const { initRunner } = require('../packages/create-sitecore-jss/dist/init-runner');
const samplesToScaffold = require('./samples.json');
const { getAppName } = require('./utils');

for (const sample of samplesToScaffold) {
sample.args.appName = `sample-${sample.args.appName}-${sample.args.fetchWith || ''}-${sample.args.prerender || ''}`;
sample.args.appName = getAppName(sample.args);
sample.args.destination = `./samples/${sample.args.appName}`;
sample.args.hostName = `${sample.args.appName}.jss.localhost`;
console.log(chalk.green(`Initializing sample ${sample.args.appName} ...`));
Expand All @@ -17,6 +18,6 @@ for (const sample of samplesToScaffold) {
silent: true,
noInstall: true,
...sample.args,
}
};
initRunner(sample.initializers, scaffoldArgs);
};
}
7 changes: 7 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Generates unique app name based on sample app configuration
* @param {Record<string, string>} args sample app arguments
* @returns unique app name
*/
module.exports.getAppName = (args) =>
`sample-${args.appName}-${args.fetchWith || ''}-${args.prerender || ''}`;