Skip to content

Commit

Permalink
chore(ci): ci optimizations (SAP#8662)
Browse files Browse the repository at this point in the history
* feat: implemented new ci pipelines and optimized them

* chore(ci): deleted unused token

* chore(ci): fixed firebase tokens

* chore(ci): added --runner cloud to the commands

* chore(deps): fixed merge broken dependency

* chore(deps): added cacheable operations to the nx.json

* chore(deps): deleted local runner

* chore(ci): deleted cloud runner refs

* chore(ci): fixed lint issues

* chore(ci): updated netlify build script

* chore(ci): replaced http://placeimg.com to secure version

* chore(ci): added read-only token for local cloud runner

* feat(ci): there is no point in building doc pages

* feat(ci): there is no point in using builder from nrwl

* feat(ci): removed buildable from template docs

* chore: nx formatting

* feat(ci): excluded docs from build in one step

* chore(ci): turns out nrwl executor works just fine

* chore(ci): fixed most of illustrated-message-docs examples

* chore(ci): modified how ci-env flags are generated

* chore(ci): added schema property to the angular.json

* fix(docs): update NEW_COMPONENT.md

* fix(docs): missed a few things

* chore: added prepare target dependency

* chore: removed runner cloud from ci scripts

* feat: removed redundant scripts from package.json

* feat: added back netlify build script

* feat: deleted unused files

* feat: deleted unnecessary screenshots

* feat: deleted unnecessary PLATFORM_README and replaced its usage with platform/Readme version

* feat: deleted unnecessary PLATFORM_README copy step from platform project.json

* feat: removed unnecessary copyReadme step from prepare executor

* feat: moved new component doc to the shared docs file, so file modifications now trigger app cache invalidation

* feat: added implicit dependency from app to umbrella libs so that changes to readmes are also triggering app rebuild

* chore: ran nx format:write against main

* feat: added missing implicit dependencies

Co-authored-by: Mike O'Donnell <[email protected]>
Co-authored-by: Inna Atanasova <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2022
1 parent 1404077 commit 459f442
Show file tree
Hide file tree
Showing 12,174 changed files with 49,951 additions and 43,546 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .ci-env/flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# This flag indicates if the tag should be treated as a latest one, which is going to trigger
# - npm publish with `latest` tag, which will become new default version
# - main version incrementation
latest=false
echo '::set-output name=isLatest::false'
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ trim_trailing_whitespace = false


[*.json]
indent_size = 2
indent_size = 4
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
{
"sourceTag": "scope:docs",
"onlyDependOnLibsWithTags": [
"scope:docs",
"scope:fd",
"scope:fdp",
"scope:fn",
Expand Down
27 changes: 27 additions & 0 deletions .github/actions/bump-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Action for semantic version bump
description: Bump version of root package.json

inputs:
isPrerelease:
description: Whether this is a prerelease
required: false
default: 'false'
isHotfix:
description: Whether this is a hotfix
required: false
default: 'false'
writeFile:
description: Write to package.json
required: false
default: 'false'
outputs:
newVersion:
description: New version
isPrerelease:
description: Is prerelease version
releaseTag:
description: Release tag

runs:
using: node16
main: ./index.js
110 changes: 110 additions & 0 deletions .github/actions/bump-version/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const recommendedVersion = require('conventional-recommended-bump');
const semver = require('semver');
const fs = require('fs');
const core = require('@actions/core');
const { getInput } = require('@actions/core');
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const releaseType = core.getInput('isPrerelease') !== 'false' ? 'prerelease' : 'release';
const writeFile = core.getInput('writeFile') !== 'false';
const isHotfix = getInput('isHotfix') !== 'false';
const currentVersion = packageJson.version;
const prereleaseRequested = releaseType === 'prerelease';

function isInPrerelease(version) {
return Array.isArray(semver.prerelease(version));
}

function shouldContinuePrerelease(version, expectType) {
return getCurrentActiveType(version) === expectType;
}

const TypeList = ['major', 'minor', 'patch'].reverse();

/**
* extract the in-pre-release type in target version
*
* @param version
* @return {string}
*/
function getCurrentActiveType(version) {
const typelist = TypeList;
for (let i = 0; i < typelist.length; i++) {
if (semver[typelist[i]](version)) {
return typelist[i];
}
}
}

/**
* calculate the priority of release type,
* major - 2, minor - 1, patch - 0
*
* @param type
* @return {number}
*/
function getTypePriority(type) {
return TypeList.indexOf(type);
}

const bumpedVersionType = () => {
return new Promise((resolve, reject) => {
recommendedVersion(
{
preset: {
name: require.resolve('conventional-changelog-conventionalcommits'),
preMajor: semver.lt(currentVersion, '1.0.0')
},
tagPrefix: 'v'
},
(err, release) => {
if (err) {
return reject(err);
}
if (prereleaseRequested) {
if (isInPrerelease(currentVersion)) {
if (
shouldContinuePrerelease(currentVersion, release.releaseType) ||
getTypePriority(getCurrentActiveType(currentVersion)) > getTypePriority(release.releaseType)
) {
release.releaseType = 'prerelease';
return resolve(release);
}
}
release.releaseType = 'pre' + release.releaseType;
return resolve(release);
}
return resolve(release);
}
);
});
};

const getReleaseTag = (hotfix, preRelease) => {
if (hotfix) {
return 'archive';
}
if (preRelease) {
return 'prerelease';
}
return 'latest';
};

const run = async () => {
const release = await bumpedVersionType();
core.info(`${release.reason}, therefore release type should be ${release.releaseType}`);

const newVersion =
semver.valid(release.releaseType, undefined) ||
semver.inc(currentVersion, release.releaseType, prereleaseRequested, 'rc');
core.info(`new version is ${newVersion}`);
if (writeFile) {
packageJson.version = newVersion;
fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2));
}
const isPrerelease = !!semver.prerelease(newVersion, undefined);
core.setOutput('newVersion', newVersion);
core.setOutput('isPrerelease', isPrerelease.toString());
core.setOutput('releaseTag', getReleaseTag(isHotfix, isPrerelease));
};

run();
10 changes: 10 additions & 0 deletions .github/actions/generate-conventional-release-notes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Generate changelog
description: Generates changelog from nearest release to current commit

outputs:
generatedChangelog:
description: Generated changelog

runs:
using: node16
main: ./index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const semver = require('semver');
const fs = require('fs');
const gitSemverTags = require('git-semver-tags');

const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));

const semverTags = (maxVersion) => {
return new Promise((resolve, reject) => {
gitSemverTags({ tagPrefix: 'v', skipUnstable: false }, function (err, result) {
if (err) {
reject(err);
} else {
const firstLessIndex = result.findIndex((v) => semver.lt(v, maxVersion));
resolve(result.slice(firstLessIndex, result.length));
}
});
});
};

module.exports = async () => {
const isPrerelease = !!semver.prerelease(packageJson.version);
const availableVersions = await semverTags(packageJson.version);
let closestIndex = 0;
if (!isPrerelease) {
closestIndex = availableVersions.findIndex((v) => !semver.prerelease(v));
}
return {
closest: availableVersions[closestIndex],
tagsTillClosest: availableVersions.slice(0, closestIndex)
};
};
34 changes: 34 additions & 0 deletions .github/actions/generate-conventional-release-notes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const conventionalChangelog = require('conventional-changelog');
const core = require('@actions/core');
const through = require('through2');
const closestVersion = require('./closest-version');
const childProcess = require('child_process');

const run = async () => {
const { closest, tagsTillClosest } = await closestVersion();
childProcess.execSync(`git tag -d ${tagsTillClosest.join(' ')}`);
const changelog = await conventionalChangelog(
{
preset: 'angular',
releaseCount: 1
},
null,
{ from: closest },
null,
{ headerPartial: '' }
);
let generatedReleaseNotes = '';
changelog
.pipe(
through(function (chunk, _enc, callback) {
this.push(chunk);
generatedReleaseNotes += chunk.toString();
callback();
})
)
.on('finish', () => {
core.setOutput('generatedReleaseNotes', generatedReleaseNotes);
});
};

run();
25 changes: 17 additions & 8 deletions .github/actions/nodejs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,30 @@ runs:
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
shell: bash

- name: Use the global Yarn cache if available
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ inputs.node_version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ inputs.node_version }}-yarn-
- uses: actions/cache@v3
id: node-modules-cache
id: node_modules
name: Use project node_modules cache if available
with:
path: '**/node_modules/'
key: ${{ runner.os }}-${{ inputs.node-version }}-node-modules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ inputs.node-version }}-node-modules-
- shell: bash
run: |
echo "Show environment Node.js, yarn ..."
node -v
yarn -v
- name: Install dependencies
if: steps.node-modules-cache.outputs.cache-hit != 'true'
if: steps.node_modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
shell: bash
16 changes: 16 additions & 0 deletions .github/actions/npm-publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Publish library
description: Publish library to npm repository
inputs:
projects:
description: Path to package.json
required: true
releaseTag:
description: Release tag of publish
required: true
token:
description: NPM token
required: true

runs:
using: node16
main: ./index.js
30 changes: 30 additions & 0 deletions .github/actions/npm-publish/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { getInput, info } = require('@actions/core');
const { npmPublish } = require('@jsdevtools/npm-publish');
const { readFileSync } = require('fs');
const { resolve } = require('path');

const run = async () => {
const projectsMap = JSON.parse(readFileSync('./angular.json', { encoding: 'utf-8' })).projects;
const projects = JSON.parse('["core", "i18n", "platform", "fn", "moment-adapter", "datetime-adapter"]').map(
(projectName) => {
const ngPackage = JSON.parse(
readFileSync(`${projectsMap[projectName]}/ng-package.json`, { encoding: 'utf-8' })
);
return resolve(projectsMap[projectName], ngPackage.dest, 'package.json');
}
);
const tag = getInput('releaseTag');
const npmToken = getInput('token');

for (const packageJsonPath of projects) {
const result = await npmPublish({
package: packageJsonPath,
token: npmToken,
tag,
dryRun: true
});
info(`Published ${result.package}@${result.version}`);
}
};

run().catch((e) => console.log(e));
34 changes: 34 additions & 0 deletions .github/actions/parallel-commands/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Preparing command utils
description: Command utils

inputs:
parallel-commands:
description: Parallel commands
required: true

runs:
using: composite
steps:
- name: Prepare command utils
run: chmod +x ./.github/actions/parallel-commands/run-commands-in-parallel.sh
shell: bash
- name: Process parallel commands configuration
uses: actions/github-script@v6
id: commands
env:
PARALLEL_COMMANDS: ${{ inputs.parallel-commands }}
with:
script: |
const parallelCommands = (process.env.PARALLEL_COMMANDS || '').split('\n')
.map(command => command.trim())
.filter(command => command.length > 0)
.map(s => s.replace(/'/g, '%27'));
const stringifiedEncodedArrayOfCommands = JSON.stringify(parallelCommands)
.replace(/%27/g, "'\\''");
return stringifiedEncodedArrayOfCommands
result-encoding: string
- name: Run commands in parallel
run: ./.github/actions/parallel-commands/run-commands-in-parallel.sh '${{ steps.commands.outputs.result }}'
shell: bash
19 changes: 19 additions & 0 deletions .github/actions/parallel-commands/run-commands-in-parallel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Extract the provided commands from the stringified JSON array.
IFS=$'
' read -d '' -a userCommands < <((jq -c -r '.[]') <<<"$1")

# Invoke the provided commands in parallel and collect their exit codes.
pids=()
for userCommand in "${userCommands[@]}"; do
eval "$userCommand" & pids+=($!)
done

# If any one of the invoked commands exited with a non-zero exit code, exit the whole thing with code 1.
for pid in ${pids[*]}; do
if ! wait $pid; then
exit 1
fi
done

# All the invoked commands must have exited with code zero.
exit 0
18 changes: 18 additions & 0 deletions .github/actions/set-up-git/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Set up git user
description: Action for setting up git user
inputs:
name:
description: Github user name
required: true
email:
description: Github email
required: true

runs:
using: composite
steps:
- name: Set up git user
run: |
git config --global user.email "${{ inputs.email }}"
git config --global user.name "${{ inputs.name }}"
shell: bash
Loading

0 comments on commit 459f442

Please sign in to comment.