Skip to content

Commit

Permalink
fix jest error2
Browse files Browse the repository at this point in the history
  • Loading branch information
RyosukeDTomita committed Aug 4, 2024
1 parent 1dd2699 commit 123b8fa
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
1 change: 0 additions & 1 deletion .env.stating

This file was deleted.

19 changes: 17 additions & 2 deletions .github/workflows/react-jest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
node_version: [20, 22]
env_type: ["dev", "stg", "prod"]
environment_type: ["development", "staging", "production"]

steps:
# checkout repository to runner
Expand All @@ -43,4 +43,19 @@ jobs:

# 3環境まとめてテスト
- name: run npm test
run: github-comment exec --token ${{ secrets.token }} -- npm run test-${{ matrix.env_type }} -- --watchall=false
run: |
if [ ${{ matrix.environment_type }} = "development" ]; then
npm_type="dev"
elif [ ${{ matrix.environment_type }} = "staging" ]; then
npm_type="stg"
elif [ ${{ matrix.environment_type }} = "production" ]; then
npm_type="prod"
else
echo "invalid environment_type"
exit 1
fi
# github actions environment variableから.envファイルを作成
cat <<EOF >> .env.${{ matrix.environment_type }}
gh variable list --env ${{ matrix.environment_type }} | awk '{print $1"="$2}'
EOF
github-comment exec --token ${{ secrets.token }} -- npm run test-$npm_type -- --watchall=false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
.env.development
.env.test.local
.env.production
.env.staging

npm-debug.log*
yarn-debug.log*
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ Sample React application for Trying to Use DevSecOps tools.

- Repositoryに[Environment](https://github.com/RyosukeDTomita/devsecops-demo-aws-ecs/settings/environments)を作る。
![Environment例](./doc/fig/github-environment.png)
- ローカルに3環境分の.envファイルをを作成する。

```shell
# 作成
for environment in development staging production;
do
touch .env.${environment}
echo $REACT_APP_MESSAGE=${environment} > .env.${environment}
done
```

- github actions enrironment variablesに登録/更新する。

```shell
source ./update_github_actions_variables.sh
```

### GitHub Actionsで実行したスキャン結果をアップロードできるようにGitHubリポジトリの設定を変更する

Expand Down
20 changes: 17 additions & 3 deletions doc/github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ actions/setup-python@コミットハッシュ

---

## GitHub ActionsでSecretを扱う
## GitHub ActionsでSecret,variablesを扱う

> GUIの場合は[公式ドキュメント](https://docs.github.com/ja/actions/security-guides/using-secrets-in-github-actions)参照。
### 2種類のシークレット
### Secret

#### 2種類のシークレット

- Environment Secret: Environmentを作成して値を区別して使用できる。Environmentはリポジトリに対して複数作成できる。
- Repository Secret: リポジトリで共通の値を使う。

### 使用方法(CLI)
#### 使用方法(CLI)

> [GitHub CLIでリポジトリへsecretを設定する方法](https://zenn.dev/hankei6km/articles/set-secret-to-repo-with-githubcli)
> [GitHub ActionsでEnvironment Secretを扱うサンプル](https://qiita.com/ak2ie/items/4fbcdf74e7760c49c1af)
Expand All @@ -66,6 +68,18 @@ jobs:
echo ${{ secrets.API_TOKEN }}
```
### variables
- 基本はsecretと同じでenvironment variablesとrepository variablesがある。
- secretと異なり,値を確認することができる。
#### 使用例
```shell
environment=development
gh variable set --env $environment --env-file .env.$environment
gh variable list --env $environment
```

---

## path filterを使って特定のファイル変更時のみCIを走らせる
Expand Down
7 changes: 4 additions & 3 deletions update_github_actoins_variables.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
for env in "development" "staging" "production";
for environment in "development" "staging" "production";
do
echo $env
gh
echo $environment
gh variable set --env $environment --env-file .env.$environment
gh variable list --env $environment
done

0 comments on commit 123b8fa

Please sign in to comment.