Skip to content

Commit

Permalink
Merge pull request #28 from ponkio-o/update_readme
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
ponkio-o authored Nov 12, 2022
2 parents b3bc21a + e22dcd7 commit 3cf4c9a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
66 changes: 43 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,54 @@
Configure the matrix job directory in GitHub Label.

## Setup
### GitHub Label
For example, create the following labels.

- `target:all`
- `target:develop`
- `target:staging`
- `target:production`

https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels#creating-a-label

### Configuration file
### 1. Create configuration file
Create a json file in the following format. Specify the label name as key and target directory as value.
The config file name or directory can be specified, but `.deploy_target.json` is used by default.

```json
{
"target:develop": [
"envs/dev"
"envs/development"
],
"target:staging": [
"envs/stg"
"envs/staging"
],
"target:production": [
"envs/prod"
"envs/production"
],
"target:all" : [
"envs/dev",
"envs/stg",
"envs/prod"
"envs/development",
"envs/staging",
"envs/production"
]
}
```

### Workflow
### 2. Create GitHub Labels
#### CUI
If the `jq` and `gh` commands are installed, the following commands are useful.
```bash
export REPO=ponkio-o/select-target-action
export COLOR=5319E7
cat .deploy_target.json | jq -r 'keys | .[]' | xargs -I @ gh label create @ --color $COLOR --repo $REPO
```

ref. https://cli.github.com/manual/gh_label_create

Example
```console
$ cat .deploy_target.json | jq -r 'keys | .[]' | xargs -I @ gh label create @ --color $COLOR --repo $REPO
✓ Label "target:all" created in ponkio-o/select-target-action
✓ Label "target:develop" created in ponkio-o/select-target-action
✓ Label "target:production" created in ponkio-o/select-target-action
✓ Label "target:staging" created in ponkio-o/select-target-action
```

#### GUI
Please refer to following doc.
https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels#creating-a-label

### 3. Setup Workflow
GitHub Actions are configured as follows:
```yaml
name: Terraform PR check
Expand All @@ -48,6 +62,7 @@ on:

jobs:
set-matrix:
name: Set matrix job
runs-on: ubuntu-latest

outputs:
Expand All @@ -63,7 +78,7 @@ jobs:

plan:
needs: [set-matrix]
name: terraform plan
name: Plan
runs-on: ubuntu-latest

strategy:
Expand All @@ -87,11 +102,16 @@ jobs:
The directories set in the key of the given label are merged and returned as an array.

### Deployment
Deploy to all enviornment.
![image](./images/deploy_to_all.png)
Assign a label to the Pull Request. Multiple lables can be assigned.

#### Example: `target:all`
![image](./images/deploy_to_all_job.png)

#### Example: `target:develop` & `target:staging`
![image](./images/deploy_to_dev_and_stg_job.png)

If multiple labels are selected, the values are merged.
![image](./images/deploy_to_dev_and_stg.png)
#### Example: `target:all` & `target:staging`
![image](./images/deploy_to_all_job.png)

### Inputs
All inputs are optional.
Expand Down
Binary file removed images/deploy_to_all.png
Binary file not shown.
Binary file added images/deploy_to_all_job.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/deploy_to_dev_and_stg.png
Binary file not shown.
Binary file added images/deploy_to_dev_and_stg_job.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3cf4c9a

Please sign in to comment.