8000 ci: use module template workflows · infraspecdev/terraform-aws-ecs@6a460ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a460ab

Browse files
committed
ci: use module template workflows
1 parent 8c7c218 commit 6a460ab

File tree

6 files changed

+140
-32
lines changed

6 files changed

+140
-32
lines changed

.github/workflows/pr-title.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
name: 'Validate PR title'
22

33
on:
4-
pull_request_target:
5-
types:
6-
- opened
7-
- edited
8-
- synchronize
4+
workflow_call:
95

106
jobs:
117
main:

.github/workflows/release.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: 'Module Release'
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
workflow_call:
75

86
defaults:
97
run:
@@ -15,10 +13,10 @@ jobs:
1513
runs-on: ubuntu-latest
1614
steps:
1715
- name: Checkout
18-
uses: actions/checkout@v2
19-
with:
20-
persist-credentials: false
21-
fetch-depth: 0
16+
uses: actions/checkout@v4
17+
18+
- name: Git pull
19+
run: git pull origin main
2220

2321
- name: Release
2422
uses: cycjimmy/semantic-release-action@v2

.github/workflows/terraform-checks.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
name: Terraform Checks
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- master
8-
pull_request:
9-
branches:
10-
- main
11-
- master
4+
workflow_call:
125

136
env:
147
TERRAFORM_DOCS_VERSION: v0.18.0

.github/workflows/terraform-docs.yaml

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
name: Terraform Docs
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- master
8-
pull_request:
9-
branches:
10-
- main
11-
- master
4+
workflow_call:
125

136
env:
147
TERRAFORM_DOCS_VERSION: v0.18.0
@@ -20,18 +13,65 @@ jobs:
2013
- name: Checkout repository
2114
uses: actions/checkout@v4
2215
with:
23-
ref: ${{ github.event.pull_request.head.ref }}
16+
ref: ${{ github.ref }}
2417

25-
- name: Render and Push terraform docs for main and modules
18+
- name: Render and Push terraform docs for main module
2619
uses: terraform-docs/gh-actions@main
2720
with:
2821
working-dir: .
2922
git-push: true
30-
config-file: .terraform-docs.yaml
23+
output-file: README.md
24+
output-format: markdown table
25+
output-method: replace
26+
recursive: false
27+
template: |
28+
<!-- BEGIN_TF_DOCS -->
29+
{{ .Content }}
30+
<!-- END_TF_DOCS -->
31+
{{- printf "\n" -}}
32+
args: "--header-from .header.md"
33+
34+
- name: Check if modules folder exists
35+
id: check_modules
36+
run: echo "modules_exists=$(if [ -d modules ]; then echo true; else echo false; fi)" >> $GITHUB_ENV
37+
38+
- name: Render and Push terraform docs for sub modules
39+
if: env.modules_exists == 'true'
40+
uses: terraform-docs/gh-actions@main
41+
with:
42+
working-dir: .
43+
git-push: true
44+
output-file: README.md
45+
output-format: markdown table
46+
output-method: replace
47+
recursive: true
48+
recursive-path: modules
49+
template: |
50+
<!-- BEGIN_TF_DOCS -->
51+
{{ .Content }}
52+
<!-- END_TF_DOCS -->
53+
{{- printf "\n" -}}
54+
args: "--header-from .header.md"
55+
56+
57+
- name: Check if examples folder exists
58+
id: check_examples
59+
run: echo "examples_exists=$(if [ -d examples ]; then echo true; else echo false; fi)" >> $GITHUB_ENV
3160

3261
- name: Render and Push terraform docs for examples
62+
if: env.examples_exists == 'true'
3363
uses: terraform-docs/gh-actions@main
3464
with:
3565
working-dir: .
3666
git-push: true
37-
config-file: .terraform-docs-example.yaml
67+
output-file: README.md
68+
output-format: markdown table
69+
output-method: replace
70+
recursive: true
71+
recursive-path: examples
72+
template: |
73+
<!-- BEGIN_TF_DOCS -->
74+
{{ .Content }}
75+
<!-- END_TF_DOCS -->
76+
{{- printf "\n" -}}
77+
args: "--header-from .header.md"

.github/workflows/terraform.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Terraform Master Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request_target:
9+
types:
10+
- opened
11+
- edited
12+
- synchronize
13+
pull_request:
14+
branches:
15+
- main
16+
- master
17+
jobs:
18+
prTitlecheck:
19+
name: PR title check
20+
if: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.base.ref == 'main' }}
21+
uses: ./.github/workflows/pr-title.yaml
22+
23+
preCommitCheck:
24+
name: Terraform Checks
25+
uses: ./.github/workflows/terraform-checks.yaml
26+
27+
generateDocs:
28+
name: Generate Terraform Docs
29+
needs: preCommitCheck
30+
uses: ./.github/workflows/terraform-docs.yaml
31+
32+
release:
33+
name: Release module
34+
needs: generateDocs
35+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
36+
uses: ./.github/workflows/release.yaml

.github/workflows/update-configs.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Update Configuration from Template
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
update:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout template repository
12+
uses: actions/checkout@v3
13+
with:
14+
repository: nimisha-gj/terraform-module-template
15+
token: ${{ secrets.GITHUB_TOKEN }}
16+
path: template-repo
17+
18+
- name: Checkout target repository
19+
uses: actions/checkout@v3
20+
with:
21+
repository: ${{ github.repository }}
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
path: target-repo
24+
25+
- name: Set up Git
26+
run: |
27+
git config --global user.name "github-actions"
28+
git config --global user.email "github-actions@github.com"
29+
30+
- name: Copy files from template repository
31+
run: |
32+
cp template-repo/.editorconfig target-repo/
33+
cp template-repo/.pre-commit-config.yaml target-repo/
34+
cp template-repo/LICENSE target-repo/
35+
cp template-repo/.tflint.hcl target-repo/ 6AE1
36+
cp template-repo/.releaserc.json target-repo/
37+
cp template-repo/CODE_OF_CONDUCT.md target-repo/
38+
cp template-repo/CONTRIBUTING.md target-repo/
39+
40+
- name: Commit and push changes
41+
run: |
42+
cd target-repo
43+
git add .
44+
git commit -m "Update files from terraform-module-template"
45+
git push

0 commit comments

Comments
 (0)
0