Skip to content

Commit

Permalink
Merge pull request #8 from kikuomax/cicd
Browse files Browse the repository at this point in the history
Introduce continuous delivery
  • Loading branch information
kikuomax authored Jun 19, 2022
2 parents 7b9078e + 18fa1a6 commit 859a0ce
Show file tree
Hide file tree
Showing 34 changed files with 10,503 additions and 487 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build artifacts
/node_modules
# Node artifacts
node_modules

# editor artifacts
*.swp
Expand Down
7 changes: 6 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@

## コンテンツを管理する

サブフォルダ[`zola`](zola/README.ja.md)をご覧ください。
サブフォルダ[`zola`](zola/README.ja.md)をご覧ください。

## Continuous Delivery

このレポジトリの`main`ブランチが更新されると、codemongerウェブサイトを更新するためのワークフローが開始します。
詳しくはサブフォルダ[`cdk-ops`](cdk-ops/README.ja.md)をご覧ください。
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ Please refer to the subfolder [`cdk`](cdk).

## Managing contents

Please refer to the subfolder [`zola`](zola).
Please refer to the subfolder [`zola`](zola).

## Continuous delivery

When the `main` branch of this repository is updated, the workflow to update the codemonger website starts.
Please refer to the subfolder [`cdk-ops`](cdk-ops) for more details.
2 changes: 2 additions & 0 deletions cdk-common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# build artifacts
/dist
24 changes: 24 additions & 0 deletions cdk-common/README.ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[English](./README.md) / 日本語

# CDKスタックの共通ライブラリ

このレポジトリのCDKスタックで共有される型や関数を提供します。

## このライブラリの使い方

このライブラリはこのレポジトリのCDKスタックからローカルにリンクすることを意図しています。
今のところ以下のスタックがこのライブラリをリンクしています。
- [`../cdk`](../cdk/README.ja.md)
- [`../cdk-ops`](../cdk-ops/README.ja.md)

上記のCDKスタックは`dist`フォルダの中身をインポートします。

### このライブラリを更新する

このライブラリのコードを変更した際は、このフォルダで以下を実行しなければなりません。

```sh
npm run build
```

`dist`フォルダが更新されます。
24 changes: 24 additions & 0 deletions cdk-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
English / [日本語](./README.ja.md)

# Common library for CDK stacks

Provides types and functions shared among CDK stacks in this repository.

## How to use this library

This library is inteded to be locally linked from CDK stacks in this repository.
The following stacks link this library so far,
- [`../cdk`](../cdk)
- [`../cdk-ops`](../cdk-ops)

The above CDK stacks import the contents of the `dist` folder.

### Updating this library

If you change the code of this library, you have to run the following in this folder,

```sh
npm run build
```

You will find the `dist` folder updated.
56 changes: 56 additions & 0 deletions cdk-common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions cdk-common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "cdk-common",
"version": "0.1.0",
"description": "Common types and functions for CDK projects",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"files": ["dist/**/*"],
"private": true,
"scripts": {
"build": "tsc",
"prepare": "node scripts/prepare.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Kikuo Emoto ([email protected])",
"license": "MIT",
"devDependencies": {
"constructs": "^10.1.42",
"typescript": "^3.9.10"
},
"peerDependencies": {
"constructs": ">=10.0.0"
}
}
66 changes: 66 additions & 0 deletions cdk-common/scripts/prepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// This script will circumvent the situtation where no dependencies have been
// installed before running the `prepare` life cycle script.
//
// ## Background
//
// This subproject is inteded to be linked from other subprojects in the same
// repository using `npm link --save ../cdk-common`.
// This project transpiles TypeScript code, i.e., `npm run build`, during the
// `prepare` life cycle script.
// Unfortunately, `npm link` does not install dependencies of this project
// before running the `prepare` script.
// And the `prepare` script ends up with a "no such package" error.
//
// This error can be avoided by running `npm install` in this project before
// resolving dependencies of other subprojects depending on this project.
// However, this is not very intuitive that I want an automated solution.
//
// ## Workaround
//
// This script invokes `npm install` before running `npm run build` to make sure
// that dependencies are installed.
// But simply invoking `npm install` from the `prepare` script makes an infinite
// loop of `prepare` → `install` → `prepare` → ...
// So this script skips invoking `npm install` if a `node_module` folder already
// exists in this project.

const childProcess = require('child_process');
const fs = require('fs');
const process = require('process');
const util = require('util');

const promiseExec = util.promisify(childProcess.exec);

const NPM_INSTALL = 'npm install';
const NPM_BUILD = 'npm run build';

console.log('preparing...', process.cwd());

fs.stat('./node_modules', (err, stats) => {
if (err != null && err.code !== 'ENOENT') {
console.error('failed to stat', err);
process.exit(1);
}
let installation;
if (stats != null && stats.isDirectory()) {
// skips intallation because there is `node_modules` folder.
installation = Promise.resolve();
} else {
installation = promiseExec(NPM_INSTALL);
}
installation
.then(() => {
promiseExec(NPM_BUILD)
.then(() => {
process.exit(0);
})
.catch(err => {
console.error('failed to build', err);
process.exit(1);
});
})
.catch(err => {
console.error('failed to install', err);
process.exit(1);
});
});
File renamed without changes.
1 change: 1 addition & 0 deletions cdk-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './deployment-stage';
28 changes: 28 additions & 0 deletions cdk-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "ES2018",
"module": "commonjs",
"lib": [
"es2018"
],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"typeRoots": [
"./node_modules/@types"
],
"outDir": "./dist"
},
"include": ["src/**/*.ts"]
}
11 changes: 11 additions & 0 deletions cdk-ops/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.js
!jest.config.js
*.d.ts
node_modules

# CDK asset staging directory
.cdk.staging
cdk.out

# AWS config
/lib/github-connection-config.ts
6 changes: 6 additions & 0 deletions cdk-ops/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.ts
!*.d.ts

# CDK asset staging directory
.cdk.staging
cdk.out
Loading

0 comments on commit 859a0ce

Please sign in to comment.