-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Teradata/fix/build-pipelines
ci(publish): add scripts for publish and release
- Loading branch information
Showing
10 changed files
with
212 additions
and
39 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,72 @@ | ||
name: CI | ||
name: Teradata web design system CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: '*' | ||
branches: [main, beta] | ||
|
||
permissions: | ||
actions: read | ||
contents: read | ||
env: | ||
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} | ||
|
||
jobs: | ||
quality: | ||
lint: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: npm | ||
- run: npm ci | ||
- run: npm run format:check -- --base=${{ github.event.pull_request.base.sha }} | ||
- run: npx nx affected --target=scsslint --base=${{ github.event.pull_request.base.sha }} | ||
- run: npx nx affected --target=lint --base=${{ github.event.pull_request.base.sha }} | ||
|
||
# Connect your workspace on nx.app and uncomment this to enable task distribution. | ||
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested | ||
# - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
# Cache node_modules | ||
- uses: actions/setup-node@v3 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'npm' | ||
cache: npm | ||
- run: npm ci | ||
- uses: nrwl/nx-set-shas@v4 | ||
|
||
# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud | ||
# - run: npx nx-cloud record -- echo Hello World | ||
- run: npx nx affected -t lint test build e2e-ci | ||
- run: npx nx affected --target=test --base=${{ github.event.pull_request.base.sha }} | ||
|
||
publish: | ||
e2e: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: write | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
needs: [quality] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v3 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'npm' | ||
cache: npm | ||
- run: npm ci | ||
- uses: nrwl/nx-set-shas@v4 | ||
- run: NODE_OPTIONS=--max_old_space_size=4096 npx nx affected --target=e2e --base=${{ github.event.pull_request.base.sha }} | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
|
||
- run: npm run semantic-release | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: npm | ||
- run: npm ci | ||
- run: npx nx affected --target=build --base=${{ github.event.pull_request.base.sha }} | ||
- run: npx nx affected --target=build-scss --base=${{ github.event.pull_request.base.sha }} |
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,28 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: [main, beta] | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: npm | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx [email protected] |
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 @@ | ||
legacy-peer-deps=true |
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,35 @@ | ||
{ | ||
"plugins": [ | ||
["@semantic-release/commit-analyzer", { "preset": "conventionalcommits" }], | ||
["@semantic-release/release-notes-generator"], | ||
["@semantic-release/changelog",{ | ||
"changelogFile": "docs/CHANGELOG.md" | ||
}], | ||
["@semantic-release/npm", { | ||
"npmPublish": false, | ||
"tarballDir": "dist/libs" | ||
}], | ||
["@semantic-release/exec", { | ||
"prepareCmd": "npm run release:prepare", | ||
"publishCmd": "./scripts/npm-publish ${nextRelease.channel}" | ||
}], | ||
["@semantic-release/git", { | ||
"message": "ci(release): ${nextRelease.version} [skip ci]", | ||
"assets": [ | ||
"docs/CHANGELOG.md", | ||
"package.json", | ||
"package-lock.json" | ||
] | ||
}], | ||
["@semantic-release/github", { | ||
"assets": ["dist/libs/*.tgz"] | ||
}] | ||
], | ||
"branches": [{ | ||
"name": "beta", | ||
"prerelease": true, | ||
"channel": "next" | ||
},{ | ||
"name": "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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,20 @@ | ||
#!/bin/bash | ||
scope=@terdata-web | ||
tag=latest | ||
|
||
[[ $1 = 'next' ]] && tag=next || tag=latest | ||
|
||
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >.npmrc | ||
|
||
for package in ./dist/libs/* | ||
do | ||
if [ -d ${package} ] | ||
then | ||
npm publish ${package} --access=public --tag=$tag --ignore-scripts; | ||
fi | ||
done | ||
|
||
rm .npmrc | ||
|
||
echo "Published successfully [scope: $scope]. Use 'npm install [package-name]' in the project you want to use it." | ||
exit 0 |
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,77 @@ | ||
const platform = require('os').platform; | ||
const readFileSync = require('fs').readFileSync; | ||
const writeFileSync = require('fs').writeFileSync; | ||
const spawnSync = require('child_process').spawnSync; | ||
const packageJson = require('../package.json'); | ||
const args = process.argv.slice(2); | ||
|
||
const placeholders = [ | ||
['0.0.0-TERADATA-WEB', packageJson.version], | ||
['0.0.0-TSLIB', packageJson.dependencies['tslib']], | ||
]; | ||
console.log('Replacing placeholders: ', placeholders); | ||
|
||
/** RegExps that match version placeholders inside of a file. */ | ||
const placeholderRegexes = placeholders.map( | ||
(placeholder) => new RegExp(placeholder[0], 'g') | ||
); | ||
/** | ||
* Walks through every file in a directory and replaces the version placeholders | ||
*/ | ||
function replaceVersionPlaceholders(packageDir = 'dist') { | ||
// Resolve files that contain version placeholders using Grep or Findstr since those are | ||
// extremely fast and also have a very simple usage. | ||
const files = findFilesWithPlaceholders(packageDir); | ||
|
||
// Walk through every file that contains version placeholders and replace those with the current | ||
// version of the root package.json file. | ||
|
||
files.forEach((filePath) => { | ||
const fileContent = placeholderRegexes.reduce( | ||
(accumulator, currentValue, currentIndex) => | ||
accumulator.replace(currentValue, placeholders[currentIndex][1]), | ||
readFileSync(filePath, 'utf-8') | ||
); | ||
|
||
console.log(`Replacing placeholder in ${filePath}`); | ||
|
||
writeFileSync(filePath, fileContent); | ||
}); | ||
} | ||
|
||
/** Finds all files in the specified package dir where version placeholders are included. */ | ||
function findFilesWithPlaceholders(packageDir) { | ||
const findCommand = buildPlaceholderFindCommand(packageDir); | ||
|
||
console.log(`Finding files in ${packageDir}`); | ||
|
||
return spawnSync(findCommand.binary, findCommand.args) | ||
.stdout.toString() | ||
.split(/[\n\r]/) | ||
.filter(String); | ||
} | ||
|
||
/** Builds the command that will be executed to find all files containing version placeholders. */ | ||
function buildPlaceholderFindCommand(packageDir) { | ||
if (platform() === 'win32') { | ||
return { | ||
binary: 'findstr', | ||
args: [ | ||
'/msi', | ||
placeholders.map((item) => item[0]).join(' '), | ||
`${packageDir}\\*`, | ||
], | ||
}; | ||
} else { | ||
return { | ||
binary: 'grep', | ||
args: [ | ||
'-ril', | ||
placeholders.map((item) => item[0]).join(`\\|`), | ||
packageDir, | ||
], | ||
}; | ||
} | ||
} | ||
|
||
replaceVersionPlaceholders(args[0]); |