Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
monorepo Update build and release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilVerma committed Oct 9, 2023
1 parent f533ada commit 1412892
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"plugins": ["@typescript-eslint"],
"env": {
"browser": true
"browser": true,
"node": true
},
"rules": {
"no-prototype-builtins": "off",
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
name: Build

on:
push:
branches:
- main

defaults:
run:
shell: bash
working-directory: .

env:
DISTRIBUTION_ID: E1JYXHU7GFQMKF
BUCKET_NAME: flow.cldcvr.com
AWS_REGION: us-east-1
ROLE_NAME: flow.cldcvr.com-role
ACCOUNT_ID: 679519065279

jobs:
build:
name: Build and upload to amazon s3
Expand All @@ -24,13 +28,16 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Setup Node.js 16.x
- name: Setup Node.js 18.x
uses: actions/setup-node@v2
with:
node-version: 16.x
node-version: 18.x

- name: Install pnpm
run: corepack enable && corepack prepare [email protected] --activate

- name: Install Dependencies and Build
run: export NODE_OPTIONS="--max_old_space_size=8192" && pnpm i && pnpm run build-packages && pnpm run build-storybook
run: make build

- name: Configure AWS credentials from Test account
uses: aws-actions/configure-aws-credentials@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- name: Install pnpm
run: corepack enable && corepack prepare [email protected] --activate

- name: Test build
run: make build
- name: Unit tests
run: make test

- name: ESlint
run: pnpm run lint
Expand Down
51 changes: 14 additions & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
with:
node-version: 18.x

- name: Install Dependencies
run: pnpm i
- name: Install pnpm
run: corepack enable && corepack prepare pnpm@7.26.3 --activate

- name: Create Release Pull Request or Publish to npm
id: changesets
Expand All @@ -31,9 +31,11 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%B %d, %Y')"

- name: extract-changelogs
if: steps.changesets.outputs.published == 'true'
id: change-logs
Expand All @@ -49,6 +51,7 @@ jobs:
"@cldcvr/flow-table":"packages/flow-table/CHANGELOG.md",
"@cldcvr/flow-core-config":"packages/flow-core-config/CHANGELOG.md"
}
- name: Send Slack Notification
if: steps.changesets.outputs.published == 'true'
id: slack
Expand Down Expand Up @@ -97,59 +100,33 @@ jobs:
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

publish_to_github:
name: Publishing to github registry
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2

- name: Setup Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16.x

- name: Install Dependencies
run: pnpm i

# Remove original publishConfig in packages/flow-core/package.json
- uses: sergeysova/jq-action@v2
with:
cmd: echo "`jq '.publishConfig.registry="https://npm.pkg.github.com"' packages/flow-core/package.json`" > packages/flow-core/package.json

- uses: sergeysova/jq-action@v2
with:
cmd: echo "`jq '.publishConfig.registry="https://npm.pkg.github.com"' packages/flow-log/package.json`" > packages/flow-log/package.json

- uses: sergeysova/jq-action@v2
with:
cmd: echo "`jq '.publishConfig.registry="https://npm.pkg.github.com"' packages/flow-code-editor/package.json`" > packages/flow-code-editor/package.json

- uses: sergeysova/jq-action@v2
- name: Setup Node.js 18.x
uses: actions/[email protected]
with:
cmd: echo "`jq '.publishConfig.registry="https://npm.pkg.github.com"' packages/custom-elements-manifest-to-types/package.json`" > packages/custom-elements-manifest-to-types/package.json
node-version: 18.x

- uses: sergeysova/jq-action@v2
with:
cmd: echo "`jq '.publishConfig.registry="https://npm.pkg.github.com"' packages/flow-core-config/package.json`" > packages/flow-core-config/package.json
- name: Install pnpm
run: corepack enable && corepack prepare [email protected] --activate

- uses: sergeysova/jq-action@v2
with:
cmd: echo "`jq '.publishConfig.registry="https://npm.pkg.github.com"' packages/flow-table/package.json`" > packages/flow-table/package.json
- name: Replace publish URL
run: node replace-publish-config.js https://npm.pkg.github.com

- uses: actions/setup-node@v2
with:
node-version: "16.x"
registry-url: "https://npm.pkg.github.com"
always-auth: true
scope: "@cldcvr"
- name: Creating .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//npm.pkg.github.com/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release Pull Request or Publish to github
id: changesets
uses: changesets/action@v1
Expand Down
2 changes: 1 addition & 1 deletion .husky/post-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

pnpm i
pnpm tsc -b &
pnpm tsc -b &
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ endif
install:
pnpm install

.PHONY: build
build: install
.PHONY: build-lib
build-lib: install
cp README.md packages/flow-core
pnpm -C packages/custom-elements-manifest-to-types build
pnpm run -r build
pnpm tsc -b
node generate-types.cjs

.PHONY: build-storybook
build-storybook: install
pnpm build-storybook

.PHONY: build
build: build-lib build-storybook

.PHONY: test
test: build
pnpm run -r test

.PHONY: publish
publish: build
pnpm -r publish --dry-run
publish: build-lib
pnpm -r publish --dry-run --no-git-checks
1 change: 0 additions & 1 deletion generate-types.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */

const fs = require("fs-extra");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint": "pnpm lint:files .",
"lint:fix": "env TIMING=1 eslint --ext .js,.ts --fix .",
"lint:files": "env TIMING=1 eslint --ext .js,.ts --quiet --cache --cache-location .cache/ --",
"release": "cp README.md packages/flow-core && pnpm run build-packages && pnpm run changeset publish",
"release": "make build-lib && pnpm changeset publish",
"prettify": "prettier --config .prettierrc.cjs --write './**/*.{js,ts,md,mdx,scss,json,mjs,cjs}'",
"prettier:lint": "prettier --config .prettierrc.cjs --check",
"prettier:lint-all": "prettier --config .prettierrc.cjs --check .",
Expand Down
38 changes: 38 additions & 0 deletions replace-publish-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { execSync } = require("child_process");
const process = require("process");

const args = process.argv.slice(2);
const fs = require("fs");

if (args.length !== 1) {
console.error(`Invalid arguments to command: ${args}`);
console.error(`Only pass the URL to the published registry`);
process.exit(1);
}

const publishUrl = args[0];

const packageFiles = execSync('find ./packages -name "package.json"', {
cwd: __dirname,
encoding: "utf-8"
})
.split("\n")
.filter(Boolean);

console.log(
`Going to replace publishConfig.registry with ${publishUrl} in ${packageFiles.length} files \n\n`
);

packageFiles.forEach(packageFile => {
const packageJson = require(packageFile);

if (!packageJson.publishConfig) {
console.error(`No publishConfig in ${packageFile}`);
return;
}

packageJson.publishConfig.registry = publishUrl;
console.log(`Writing ${packageFile}`);
fs.writeFileSync(packageFile, `${JSON.stringify(packageJson, null, 2)}\n`, "utf-8");
});

0 comments on commit 1412892

Please sign in to comment.