Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Commit 5406ce5

Browse files
Merge pull request #1 from suzuki-shunsuke/feat/first-pr
feat: implement basic function
2 parents d9585b1 + 5bcd4b7 commit 5406ce5

18 files changed

+21862
-1
lines changed

.github/workflows/deploy.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Deploy
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: '17'
17+
cache: 'npm'
18+
- run: npm install
19+
- run: npm run build
20+
21+
- name: Generate token
22+
id: generate_token
23+
uses: tibdex/github-app-token@v1
24+
if: github.event_name != 'pull_request'
25+
with:
26+
app_id: ${{ secrets.APP_ID }}
27+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
28+
29+
- uses: peaceiris/actions-gh-pages@v3
30+
if: github.event_name != 'pull_request'
31+
with:
32+
personal_token: ${{ steps.generate_token.outputs.token }}
33+
external_repository: suzuki-shunsuke/gha-trigger
34+
publish_dir: ./build
35+
destination_dir: ./docs
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: renovate-config-validator
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- .github/workflows/renovate-config-validator.yaml
9+
- renovate.json
10+
push:
11+
branches:
12+
- main
13+
paths:
14+
- .github/workflows/renovate-config-validator.yaml
15+
- renovate.json
16+
17+
jobs:
18+
validate:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: suzuki-shunsuke/[email protected]

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.17.0

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
# gha-trigger-docs
2-
Document of gha-trigger
2+
3+
Document of [gha-trigger](https://github.com/suzuki-shunsuke/gha-trigger)
4+
5+
https://suzuki-shunsuke.github.io/gha-trigger/
6+
7+
## Launch at localhost
8+
9+
```console
10+
$ npm i
11+
$ npm start
12+
```
13+
14+
## LICENSE
15+
16+
[MIT](LICENSE)

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
};

docs/config/_category_.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Configuration",
3+
"position": 200
4+
}

docs/config/ci-repository.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
sidebar_position: 200
3+
---
4+
5+
# CI Repository
6+
7+
## CI Repository's GitHub Actions Workflow
8+
9+
- Workflow Dispatch's inputs
10+
- Checkout `CI Repository` and `Main Repository`
11+
- Use GitHub App instead of `${{ github.token }}`
12+
- Update commit statuses
13+
14+
```yaml
15+
---
16+
name: Format Rego files
17+
on:
18+
workflow_dispatch:
19+
inputs:
20+
# payload:
21+
# required: true
22+
repo:
23+
required: true
24+
ref:
25+
required: true
26+
jobs:
27+
build:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Generate token
31+
id: generate_token
32+
uses: tibdex/github-app-token@v1
33+
with:
34+
app_id: ${{ secrets.APP_ID }}
35+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
36+
- uses: actions/checkout@v3
37+
with:
38+
repository: ${{ github.event.inputs.repo }}
39+
ref: ${{ github.event.inputs.ref }}
40+
token: ${{ steps.generate_token.outputs.token }}
41+
- uses: actions/checkout@v2
42+
with:
43+
path: .test-isolation
44+
45+
- uses: ./.test-isolation/.github/actions/aqua
46+
- uses: suzuki-shunsuke/[email protected]
47+
with:
48+
github_token: ${{ steps.generate_token.outputs.token }}
49+
```
50+
51+
## Workflow Dispatch's inputs
52+
53+
```yaml
54+
on:
55+
workflow_dispatch:
56+
inputs:
57+
# payload:
58+
# required: true
59+
repo:
60+
required: true
61+
ref:
62+
required: true
63+
```
64+
65+
- repo:
66+
- payload:
67+
68+
## Checkout `CI Repository` and `Main Repository`
69+
70+
```yaml
71+
- uses: actions/checkout@v3
72+
with:
73+
repository: ${{ github.event.inputs.repo }}
74+
ref: ${{ github.event.inputs.ref }}
75+
token: ${{ steps.generate_token.outputs.token }}
76+
- uses: actions/checkout@v2
77+
with:
78+
path: .test-isolation
79+
```
80+
81+
## Use GitHub App instead of `${{ github.token }}`
82+
83+
https://github.com/tibdex/github-app-token
84+
85+
```yaml
86+
- name: Generate token
87+
id: generate_token
88+
uses: tibdex/github-app-token@v1
89+
with:
90+
app_id: ${{ secrets.APP_ID }}
91+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
92+
- uses: actions/checkout@v3
93+
with:
94+
repository: ${{ github.event.inputs.repo }}
95+
ref: ${{ github.event.inputs.ref }}
96+
token: ${{ steps.generate_token.outputs.token }}
97+
```
98+
99+
## Update commit statuses
100+
101+
https://github.com/suzuki-shunsuke/update-commit-status-action

docs/config/index.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
sidebar_position: 100
3+
---
4+
5+
# Configuration
6+
7+
`gha-trigger` supports only environment variables as source of configuration,
8+
but we are considering other sources such as S3, DynamoDB, AWS AppConfig, and so on.
9+
10+
e.g.
11+
12+
```yaml
13+
---
14+
aws:
15+
region: us-east-1
16+
secretsmanager:
17+
region: us-east-1
18+
secret_id: test-gha-trigger
19+
github_app:
20+
app_id: 123456789
21+
events:
22+
- matches:
23+
- repo_owner: suzuki-shunsuke
24+
repo_name: example-terraform-monorepo-2
25+
events:
26+
- pull_request
27+
branches:
28+
- main
29+
workflows:
30+
- repo_owner: suzuki-shunsuke
31+
repo_name: example-terraform-monorepo-2-ci
32+
workflow_file_name: test_pull_request.yaml
33+
ref: pull_request
34+
- matches:
35+
- repo_owner: suzuki-shunsuke
36+
repo_name: example-terraform-monorepo-2
37+
events:
38+
- push
39+
branches:
40+
- main
41+
workflows:
42+
- repo_owner: suzuki-shunsuke
43+
repo_name: example-terraform-monorepo-2-ci
44+
workflow_file_name: test.yaml
45+
ref: main
46+
```
47+
48+
## Secrets
49+
50+
`gha-trigger` requires the following secrets.
51+
52+
- webhook_secret: GitHub App's Webhook Secret
53+
- github_app_private_key: GitHub App's private key
54+
55+
`gha-trigger` supports only AWS SecretsManager at the moment.

docs/getting-started.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
sidebar_position: 100
3+
---
4+
5+
# Getting Started
6+
7+
In the Getting Started, you can set up gha-trigger and experience CI with gha-trigger.
8+
9+
## Requirement
10+
11+
- Git
12+
- Terraform
13+
- GitHub Account
14+
- AWS Account
15+
16+
## Steps
17+
18+
1. Create GitHub Repositories from template repositories
19+
1. Create Webhook Secret
20+
1. Create GitHub App(s)
21+
1. Set up Terraform Configuration
22+
1. Apply Terraform
23+
1. Try to run CI
24+
1. Clean up
25+
26+
### Create GitHub Repositories from template repositories
27+
28+
- Main Repository:
29+
- CI Repository:
30+
31+
### Create Webhook Secret
32+
33+
- https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks
34+
35+
### Create GitHub App(s)
36+
37+
- https://docs.github.com/en/developers/apps/building-github-apps/creating-a-github-app
38+
39+
You have to create GitHub App for two purposes.
40+
41+
1. Receive webhook and trigger GitHub Actions Workflow
42+
2. Access Main Repository in CI of CI Repository
43+
44+
You can use one GitHub App for the above purposes or can create two GitHub Apps for each purpose.
45+
46+
You have to install GitHub App in Main Repository and CI Repository.
47+
You can either use the same GitHub App or create GitHub Apps per repository.
48+
49+
In this Getting Started, let's use the same GitHub App for simplicity.
50+
51+
#### 1. Receive webhook and trigger GitHub Actions Workflow
52+
53+
The minimum setting of GitHub App (1).
54+
55+
- Webhook: Active
56+
- Permissions
57+
- Actions: Read and write
58+
- Issues: Read-only
59+
- Pull requests: Read and write
60+
- Install this App in both Main Repository and CI Repository
61+
62+
#### 2. Receive webhook and trigger GitHub Actions Workflow
63+
64+
The minimum setting of GitHub App (2).
65+
66+
- Webhook: Inactive
67+
- Permissions
68+
- Commit statuses: Read and write
69+
- Contents: Read
70+
- Install this App in both Main Repository and CI Repository
71+
- Register GitHub App ID and Private Key as CI Repository's GitHub Secrets
72+
73+
### Set up Terraform Configuration
74+
75+
```console
76+
$ git clone https://github.com/suzuki-shunsuke/gha-trigger
77+
$ cd gha-trigger/terraform
78+
```
79+
80+
[Download a zip file from Release page](https://github.com/suzuki-shunsuke/gha-trigger/releases) on this directory.
81+
82+
Create `config.yaml`, `secret.yaml`, and `terraform.tfvars` from templates.
83+
84+
```console
85+
$ cp config.yaml.tmpl config.yaml
86+
$ vi config.yaml
87+
88+
$ cp secret.yaml.tmpl secret.yaml
89+
$ vi secret.yaml
90+
91+
$ cp terraform.tfvars.tmpl terraform.tfvars
92+
$ vi terraform.tfvars
93+
```
94+
95+
### Apply Terraform
96+
97+
Create resources.
98+
99+
```console
100+
$ terraform apply [-refresh=false]
101+
```
102+
103+
`-refresh=false` is useful to make terraform commands fast.
104+
105+
### Try
106+
107+
Create a pull request to source repository to test CI.
108+
109+
## Clean up
110+
111+
```
112+
$ terraform destroy
113+
```

0 commit comments

Comments
 (0)