Skip to content

Commit

Permalink
added bun parsing (faster) and some config npm deploying tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinciarka committed Sep 11, 2023
1 parent 82d550a commit c2b9afc
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 1,215 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/bump-version-and-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Bump package version and tag it

on:
push:
branches:
- main

jobs:
bump-and-tag:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Bump and Tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get Tags
run: git fetch origin +refs/tags/*:refs/tags/*

- name: Bump Version
id: bump_and_tag
uses: konsentus/action.bump-version-and-tag@v2
2 changes: 1 addition & 1 deletion .github/workflows/publish-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: bun dle
- uses: actions/upload-artifact@v3
with:
name: oazo-configuration
name: oazo-configuration-${{ github.event.repository.updated_at}}
path: ${{ vars.SOURCE_CONFIGURATION_FILE_PATH }}
if-no-files-found: error
- name: Copy a file to AWS S3 bucket 🪣
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/publish-on-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Publish new NPM package version on tag

on:
push:
tags:
- "*"

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: "1.0.0"
- name: Install packages 📦
run: bun install
- name: Lint the config files 🧹
run: bun lint
- name: Build and publish 📣
run: bun dle-publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const constants = {
Environments.staging,
],
configFolder: path.join(__dirname, "../configs"),
distFolder: path.join(__dirname, "../dist"),
};
20 changes: 13 additions & 7 deletions helpers/generate-configs.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { createConfigFiles, getConfigMainModules, parseConfig } from "🛠️";
import { green, italic, yellow } from "kleur";
import formatting from "kleur";

const generatingTimeStart = Date.now();

export async function generateConfigs() {
console.log(`\n${green(italic("Generating Oazo config files 🦾"))}\n`);
console.log(
`\n${formatting.green(
formatting.italic("Generating Oazo config files 🦾")
)}\n`
);
const configModulesFolders = await getConfigMainModules();
console.log(
italic(
formatting.italic(
`Found ${
configModulesFolders.length
} config folders: ${configModulesFolders.map(yellow).join(", ")}`
} config folders: ${configModulesFolders
.map(formatting.yellow)
.join(", ")}`
)
);
const configsList = await Promise.all(configModulesFolders.map(parseConfig));
Expand All @@ -35,8 +41,8 @@ export async function generateConfigs() {
console.table(consoleReportData);

console.log(
`\n${green("Oazo config files generated! 🫒")} \n${green(
`Time: ${Date.now() - generatingTimeStart}ms`
)}\n`
`\n${formatting.green(
"Oazo config files generated! 🫒"
)} \n${formatting.green(`Time: ${Date.now() - generatingTimeStart}ms`)}\n`
);
}
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
"name": "oazo-configuration",
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": "./scripts/generate-config.js",
"scripts": {
"dle": "rimraf dist; ts-node ./index.ts",
"dle": "rimraf dist; bun ./index.ts",
"lint": "eslint --ext .ts .",
"lint:fix": "eslint --fix --ext .ts ."
"lint:fix": "eslint --fix --ext .ts .",
"dle-publish": "bun dle && npm publish"
},
"files": [
"dist",
"./scripts/generate-config.js"
],
"repository": {
"type": "git",
"url": "git+https://github.com/OasisDEX/oazo-configuration.git"
Expand All @@ -28,6 +33,6 @@
"rimraf": "^5.0.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "5.1.6"
"typescript": "^5.2.2"
}
}
33 changes: 33 additions & 0 deletions scripts/generate-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ts-node

import { constants } from "🛠️";
import { readdir } from "fs/promises";
import formatting from "kleur";

// This will create a single `config.json` file

const allowedEnvNames = ["development", "production", "staging"];

async function generateConfig() {
const allowedConfigNames = await readdir(constants.distFolder);
console.log("allowedConfigNames", allowedConfigNames);
const envName = process.argv[3];
const configName = process.argv[2];
if (!allowedEnvNames.includes(envName)) {
throw new Error(
`Invalid environment name. Allowed names: ${allowedEnvNames.join(", ")}`
);
}
if (!allowedConfigNames.includes(configName)) {
throw new Error(
`Invalid config name. Allowed names: ${allowedConfigNames.join(", ")}`
);
}
console.log(
formatting.cyan(
`Generating ${configName} config for ${envName} environment`
)
);
}

generateConfig();
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"esModuleInterop": true,
"paths": {
"🛠️": ["./helpers/index.ts"],
"⌨️": ["./types/index.ts"]
Expand Down
Loading

0 comments on commit c2b9afc

Please sign in to comment.