Skip to content

[🏗️][CI]: Add CI workflows #81

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

Merged
merged 7 commits into from
Mar 25, 2024
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
35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CodeQL

on:
push:
branches:
- "next"
pull_request:
schedule:
# on sunday of each month at 5:55
- cron: "55 5 * * 0"
workflow_call:

jobs:
analyze:
name: "Analyze"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language:
- javascript
- typescript
steps:
- uses: actions/checkout@v4

- name: "🎬 Initialize CodeQL"
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}

- name: "🏗️ Autobuild"
uses: github/codeql-action/autobuild@v1

- name: "🧐 Perform CodeQL Analysis"
uses: github/codeql-action/analyze@v1
58 changes: 58 additions & 0 deletions .github/ISSUE_TEMPLATE/workflows/development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Development

on:
pull_request:
types:
- opened
- edited
- synchronize
- reopened
workflow_call:

jobs:
test:
name: Test components
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: "📦 install dependencies"
run: pnpm install

- name: "🔍 run tests"
run: pnpm test

lint:
name: Code standards
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v4

- name: "🔧 setup pnpm"
uses: pnpm/action-setup@v3
with:
version: 8

- name: "🔧 setup node"
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: "📦 install dependencies"
run: pnpm install

- name: "🔍 lint code"
run: pnpm lint
42 changes: 42 additions & 0 deletions .github/ISSUE_TEMPLATE/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: "📦 install dependencies"
run: pnpm install

- name: "🧱 build package"
run: pnpm build

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/

- name: "🚀 publish package"
run: npx tsx ./scripts/ci/publish-package.ts
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ dist
.tern-port

.DS_Store
.vscode
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@
"name": "@styleless-ui/react",
"version": "1.0.0-rc.0",
"description": "Completely unstyled, headless and accessible React UI components.",
"repository": "git@github.com:styleless-ui/react-styleless-ui.git",
"author": "mimshins <mostafa.sh.coderino@gmail.com>",
"license": "MIT",
"type": "module",
"engines": {
"node": ">=20"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/styleless-ui/react-styleless-ui.git"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/",
"tag": "rc"
},
"keywords": [
"ui",
"styleless-ui",
Expand Down
19 changes: 19 additions & 0 deletions scripts/build-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const createMainPackage = async () => {
types: "./index.d.ts",
main: "./index.js",
module: "./esm/index.js",
engines: packageJSON.engines,
publishConfig: packageJSON.publishConfig,
name: packageJSON.name,
type: packageJSON.type,
version: packageJSON.version,
Expand All @@ -126,9 +128,26 @@ const createMainPackage = async () => {
);
};

const createNPMRC = async () => {
const npmrcPath = path.join(distPath, ".npmrc");
const npmignorePath = path.join(distPath, ".npmignore");

await fs.writeFile(
npmrcPath,
[
"//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}",
"registry=https://registry.npmjs.org/",
"always-auth=true",
].join("\n"),
);

await fs.writeFile(npmignorePath, ".npmrc");
};

void (async () => {
await createModulePackages();
await createMainPackage();
await createNPMRC();

await fs.copyFile(readme, path.join(distPath, README_FILE_NAME));
await fs.copyFile(license, path.join(distPath, LICENSE_FILE_NAME));
Expand Down
27 changes: 27 additions & 0 deletions scripts/ci/publish-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable no-console */
import { exec } from "node:child_process";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { promisify } from "node:util";

const execCmd = promisify(exec);

const packagePath = process.cwd();

const distPath = path.join(packagePath, "./dist");

void (async () => {
const distPackagePath = path.join(distPath, "package.json");

const packageJSON = JSON.parse(
await fs.readFile(distPackagePath, "utf-8"),
) as Record<string, unknown>;

const { tag = "latest" } =
(packageJSON.publishConfig as { tag: string } | undefined) ?? {};

const { stderr, stdout } = await execCmd(`npm publish --tag ${tag}`);

console.log({ stdout });
console.error({ stderr });
})();