Skip to content

Commit b9bc56c

Browse files
authored
update plugins, terraform, and python unittest (#4)
1 parent 982deac commit b9bc56c

File tree

7 files changed

+161
-4
lines changed

7 files changed

+161
-4
lines changed

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Provides GitHub Workflow and Action samples.
99

1010
## Sample Repositories
1111

12-
| Repository | Workflow File | Actions |
13-
|---|--------------------------------|------|
14-
| gke-workload-identity | [build.yml](https://github.com/DevSecOpsSamples/gke-workload-identity/blob/master/.github/workflows/build.yml) | [actions](https://github.com/DevSecOpsSamples/gke-workload-identity/actions/workflows/build.yml) | GCP, gcloud, Docker, Terraform, Python, pytest, Sonarqube |
15-
| jenkins-fargate-cdk | [build.yml](https://github.com/DevSecOpsSamples/jenkins-fargate-cdk/blob/master/.github/workflows/build.yml) | [actions](https://github.com/DevSecOpsSamples/jenkins-fargate-cdk/actions/workflows/build.yml) | Docker, CDK, Sonarqube |
12+
| Repository | Workflow File | Actions | Description | Plugins |
13+
|---|--------------------------------|------|--------------------------------|---------------|
14+
| gke-workload-identity | [build.yml](https://github.com/DevSecOpsSamples/gke-workload-identity/blob/master/.github/workflows/build.yml) | [actions](https://github.com/DevSecOpsSamples/gke-workload-identity/actions/workflows/build.yml) | GCP, gcloud, Docker, Terraform <br/> Python, pytest, publish unittest result, Sonarqube | hashicorp/[email protected] <br/>jacobtomlinson/gha-find-replace@v2 <br/> actions/github-script@v6 <br/>actions/setup-java@v1 <br/>actions/setup-python@v4 <br/> google-github-actions/auth@v1 <br/> EnricoMi/publish-unit-test-result-action/composite@v2 <br/> actions/cache@v3 <br/> |
15+
| jenkins-fargate-cdk | [build.yml](https://github.com/DevSecOpsSamples/jenkins-fargate-cdk/blob/master/.github/workflows/build.yml) | [actions](https://github.com/DevSecOpsSamples/jenkins-fargate-cdk/actions/workflows/build.yml) | Docker, CDK, Sonarqube | |
1616

1717
## Docker
1818

@@ -30,6 +30,28 @@ Provides GitHub Workflow and Action samples.
3030

3131
- [gke-workload-identity](https://github.com/DevSecOpsSamples/gke-workload-identity/blob/master/.github/workflows/build.yml)
3232

33+
## Terraform
34+
35+
- [terraform.yml](terraform.yml)
36+
37+
<details><summary>Terraform Plan</summary>
38+
39+
![terraform-plan.png](./screenshots/terraform-plan.png?raw=true)
40+
41+
</details>
42+
43+
## Python Unittest
44+
45+
- [python-unittest.yml](python-unittest.yml) [setup.cfg](setup.cfg)
46+
47+
<details><summary>Unittest Results</summary>
48+
49+
![test-failed.png](./screenshots/test-failed.png?raw=true)
50+
51+
![test-failed-details.png](./screenshots/test-failed-details.png?raw=true)
52+
53+
</details>
54+
3355
## Reference
3456

3557
- [GitHub Actions /Using workflows / Cache dependencies / Caching dependencies to speed up workflows](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#managing-caches)

python-unittest.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- develop
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
- name: Set up Python 3.9
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: 3.9
21+
cache: 'pip'
22+
- run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
pip install --upgrade google-cloud-storage google-cloud-pubsub
26+
- name: 'Authenticate to Google Cloud'
27+
uses: 'google-github-actions/auth@v1'
28+
with:
29+
credentials_json: '${{ secrets.SA }}'
30+
- run: pytest
31+
- name: Publish Test Results
32+
uses: EnricoMi/publish-unit-test-result-action/composite@v2
33+
if: always()
34+
with:
35+
junit_files: "build/test-result.xml"
36+

screenshots/terraform-plan.png

346 KB
Loading
286 KB
Loading

screenshots/test-failed.png

230 KB
Loading

setup.cfg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[flake8]
2+
max-line-length = 200
3+
ignore = F123, E456
4+
exclude = .terraform
5+
6+
[tool:pytest]
7+
log_cli=True
8+
log_cli_level=DEBUG
9+
; --html=report.html = pip install pytest-html
10+
addopts=--failed-first --cov=src/bucket-api --cov=src/pubsub-api --junit-xml=build/test-result.xml --html=build/test-report.html --cov-report=xml:build/test-coverage.xml
11+
junit_family=legacy
12+
; --cov-branch
13+
; norecursedirs=.pyenv-python
14+
env =
15+
D:GOOGLE_APPLICATION_CREDENTIALS=.sa
16+
D:GCS_BUCKET_NAME={PROJECT_ID}-bucket-api
17+
D:GOOGLE_CLOUD_PROJECT={PROJECT_ID}

terraform.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- develop
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
terraform:
11+
strategy:
12+
matrix:
13+
path: [src/terraform/cluster, src/terraform/workload-identity]
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: HashiCorp - Setup Terraform
18+
uses: hashicorp/[email protected]
19+
- run: terraform fmt -check
20+
id: fmt
21+
working-directory: ${{ matrix.path }}
22+
- run: terraform init
23+
working-directory: ${{ matrix.path }}
24+
id: init
25+
- run: terraform validate -no-color
26+
working-directory: ${{ matrix.path }}
27+
id: validate
28+
- name: 'Authenticate to Google Cloud'
29+
uses: 'google-github-actions/auth@v1'
30+
with:
31+
credentials_json: '${{ secrets.SA }}'
32+
- name: Replace project-id
33+
uses: jacobtomlinson/gha-find-replace@v2
34+
with:
35+
find: "<dev-stage-project-id>"
36+
replace: ${{ secrets.PROJECT_ID }}
37+
include: "src/terraform/**"
38+
regex: false
39+
- name: Terraform Plan
40+
id: plan
41+
if: matrix.path == 'src/terraform/cluster'
42+
run: terraform plan -var-file=vars/dev.tfvars -no-color
43+
working-directory: ${{ matrix.path }}
44+
- uses: actions/github-script@v6
45+
if: github.event_name == 'pull_request'
46+
with:
47+
github-token: ${{ secrets.GITHUB_TOKEN }}
48+
script: |
49+
const output = `#### Working Directory: ${{ matrix.path }}
50+
51+
#### Terraform Format and Style \`${{ steps.fmt.outcome }}\`
52+
53+
#### Terraform Initialization \`${{ steps.init.outcome }}\`
54+
55+
#### Terraform Validation \`${{ steps.validate.outcome }}\`
56+
57+
<details><summary>Validation Output</summary>
58+
59+
\`\`\`\n
60+
${{ steps.validate.outputs.stdout }}
61+
\`\`\`
62+
63+
</details>
64+
65+
#### Terraform Plan \`${{ steps.plan.outcome }}\`
66+
67+
<details><summary>Show Plan</summary>
68+
69+
\`\`\`\n
70+
${{ steps.plan.outputs.stdout }}
71+
\`\`\`
72+
73+
</details>`;
74+
75+
github.rest.issues.createComment({
76+
issue_number: context.issue.number,
77+
owner: context.repo.owner,
78+
repo: context.repo.repo,
79+
body: output
80+
});
81+
82+

0 commit comments

Comments
 (0)