diff --git a/.commitlintrc.yml b/.commitlintrc.yml deleted file mode 100644 index 9f17590d..00000000 --- a/.commitlintrc.yml +++ /dev/null @@ -1,4 +0,0 @@ -extends: - - '@commitlint/config-angular' -rules: - 'header-max-length': [2, 'always', 100] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e52ddc27..dd6f2020 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,48 +16,22 @@ on: tags-ignore: - '**' jobs: - checkExecution: - runs-on: ubuntu-latest - outputs: - shouldExecute: ${{ steps.stepCheckExecution.outputs.shouldExecute }} - steps: - - name: Dump GitHub context - run: | - echo "::group::github context" - echo "$GITHUB_CONTEXT" - echo "::endgroup::" - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - - id: stepCheckExecution - name: Check for execution - uses: shiftcode/github-action-skip@v4.0.0 - with: - skipOnCommitMsg: '[skip_build]' - githubToken: ${{ secrets.GITHUB_TOKEN }} test: runs-on: ubuntu-latest - needs: checkExecution - # only execute if not skipped by commit message - if: needs.checkExecution.outputs.shouldExecute == 'true' strategy: matrix: - # Test with Node.js v20 and v22 + # Test with Node.js 24 and v25 node: - - 20 - - 22 + - 24 + - 25 name: Node.js v${{ matrix.node }} steps: # checkout branch - name: Checkout - uses: actions/checkout@v4 - with: - # 0 indicates all history, because publish requires tag information - fetch-depth: 0 - # we need privileged access to publish to protected branch - token: ${{ secrets.GH_TOKEN_PUBLIC_REPO }} + uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd #v5.0.1 # setup node and dependency cache - name: Setup Node and NPM Cache - uses: actions/setup-node@v4 + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 with: node-version: ${{ matrix.node }} cache: 'npm' @@ -69,21 +43,20 @@ jobs: run: npm run test:ci build: runs-on: ubuntu-latest - needs: [checkExecution, test] - # only execute if not skipped by commit message - if: needs.checkExecution.outputs.shouldExecute == 'true' + permissions: + contents: write + packages: write + needs: test steps: # checkout branch - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd #v5.0.1 with: # 0 indicates all history, because publish requires tag information fetch-depth: 0 - # we need privileged access to publish to protected branch - token: ${{ secrets.GH_TOKEN_PUBLIC_REPO }} # setup node and dependency cache - name: Setup Node and NPM Cache - uses: actions/setup-node@v4 + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 with: node-version-file: .nvmrc cache: 'npm' @@ -105,11 +78,9 @@ jobs: # publish - name: Publish run: | - npm config set //npm.pkg.github.com/:_authToken=$REGISTRY_TOKEN + npm config set //npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }} git config user.email "actions@github.com" git config user.name "Github Actions" npm run publish-libs env: GITHUB_CONTEXT: ${{ toJson(github) }} - REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GH_TOKEN: ${{ secrets.GH_TOKEN_PUBLIC_REPO }} # necessary for publish-libs script diff --git a/.lintstagedrc.yml b/.lintstagedrc.yml deleted file mode 100644 index 5c35b407..00000000 --- a/.lintstagedrc.yml +++ /dev/null @@ -1,5 +0,0 @@ -./package.json: - - npx sort-package-json - -'*': - - npm run format:staged diff --git a/.nvmrc b/.nvmrc index deed13c0..b03f4086 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -lts/jod +lts/krypton diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index 849ddff3..00000000 --- a/.prettierignore +++ /dev/null @@ -1 +0,0 @@ -dist/ diff --git a/.prettierrc.yml b/.prettierrc.yml deleted file mode 100644 index d86a7056..00000000 --- a/.prettierrc.yml +++ /dev/null @@ -1,5 +0,0 @@ -# https://github.com/prettier/prettier/blob/master/docs/options.md -printWidth: 120 -singleQuote: true -semi: false -trailingComma: all diff --git a/README.md b/README.md index 1a0e7ee3..8d3ba9ae 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,43 @@ Public helper packages with commonly used utilities / helpers. +
= {
+ [Key in keyof P]: P[Key] extends ProdSwitchable = {
+ [Key in keyof P]: P[Key] extends StageSwitchable {
+ readonly props: P
+ readonly configService: IacStackConfigService
+
+ getProdDependantProp [K]
+
+ getStageDependantProp [K]
+}
+
+/** the IacUtils constructable type used as return type when calling the {@link extendWithIacUtils} function */
+export type IacUtilsConstructable any> = new (
+ superArgs: ConstructorParameters
+
+/** the actual Utilities function which takes any class to extend */
+export function extendWithIacUtils any>(clazz: T): IacUtilsConstructable {
+ // The Utilities class which implements the Utilities interface */
+ class IacUtilsClazz extends ( {
+ constructor(
+ superArgs: ConstructorParameters [K] {
+ return this.configService.switchProdDependant( [K] {
+ return this.configService.switchStageDependant(
+}
diff --git a/packages/iac-utilities/src/base/utils/iac-stack-config.service.ts b/packages/iac-utilities/src/base/utils/iac-stack-config.service.ts
new file mode 100644
index 00000000..223c6d8c
--- /dev/null
+++ b/packages/iac-utilities/src/base/utils/iac-stack-config.service.ts
@@ -0,0 +1,134 @@
+import { StageInfo } from '@shiftcode/branch-utilities'
+
+import { IacStackNameStrategy } from '../commons/iac-stack-name-strategy.enum.js'
+import { ProdSwitchable } from '../commons/prod-switchable.model.js'
+import { StageSwitchable } from '../commons/stage-switchable.model.js'
+import { BaseRuntimeConfig } from './base-runtime-config.type.js'
+
+export type BaseRuntimeConfigProviderFn = () => BaseRuntimeConfig
+
+export class IacStackConfigService {
+ /* eslint-disable-next-line @typescript-eslint/naming-convention */
+ static readonly envBaseRuntimeConfig = 'SC_BASE_RUNTIME_CONFIG'
+
+ readonly stackName: string
+
+ constructor(
+ readonly stackBaseName: string,
+ private readonly nameStrategy: IacStackNameStrategy,
+ readonly stageInfo: StageInfo,
+ readonly region: string,
+ ) {
+ this.stackName = this.nameByStrategy(stackBaseName)
+ }
+
+ /**
+ * concatenates given propertyToName according to defined nameStrategy.
+ * default mode is 'append'
+ */
+ nameByStrategy(propertyToName: string, mode: 'append' | 'prepend' = 'append') {
+ switch (this.nameStrategy) {
+ case IacStackNameStrategy.PROD_DEPENDANT:
+ return this.prodDependantNaming('master', propertyToName, mode)
+ case IacStackNameStrategy.PROD_DEPENDANT_MAIN:
+ return this.prodDependantNaming('main', propertyToName, mode)
+ case IacStackNameStrategy.STAGE_DEPENDANT:
+ return this.stageDependantNaming(propertyToName, mode)
+ default:
+ throw new Error('Unsupported enum value for IacStackNameStrategy')
+ }
+ }
+
+ /**
+ * create name by defined {@link nameByStrategy} and given region
+ * mode defaults to append
+ * @example
+ * nameByStrategyAndRegion('abc') =>
+ */
+ nameByStrategyAndRegion(propertyToName: string, mode: 'append' | 'prepend' = 'append') {
+ switch (this.nameStrategy) {
+ case IacStackNameStrategy.PROD_DEPENDANT:
+ return this.prodDependantNaming('master', this.regionDependantNaming(propertyToName, mode), mode)
+ case IacStackNameStrategy.PROD_DEPENDANT_MAIN:
+ return this.prodDependantNaming('main', this.regionDependantNaming(propertyToName, mode), mode)
+ case IacStackNameStrategy.STAGE_DEPENDANT:
+ return this.stageDependantNaming(this.regionDependantNaming(propertyToName, mode), mode)
+ default:
+ throw new Error('Unsupported enum value for IacStackNameStrategy')
+ }
+ }
+
+ /** prepends the {@link stackName} to proveided propertyName */
+ stackDependantNaming(propertyToName: string) {
+ return `${this.stackName}-${propertyToName}`
+ }
+
+ /**
+ * get prod or nonProd value of a prodSwitchable property
+ */
+ switchProdDependant