Skip to content

Commit

Permalink
ci: use module template workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
saumitra-dev committed Aug 2, 2024
1 parent 8c7c218 commit 6a460ab
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 32 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/pr-title.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
name: 'Validate PR title'

on:
pull_request_target:
types:
- opened
- edited
- synchronize
workflow_call:

jobs:
main:
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: 'Module Release'

on:
push:
branches:
- main
workflow_call:

defaults:
run:
Expand All @@ -15,10 +13,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: 0
uses: actions/checkout@v4

- name: Git pull
run: git pull origin main

- name: Release
uses: cycjimmy/semantic-release-action@v2
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/terraform-checks.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
name: Terraform Checks

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
workflow_call:

env:
TERRAFORM_DOCS_VERSION: v0.18.0
Expand Down
64 changes: 52 additions & 12 deletions .github/workflows/terraform-docs.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
name: Terraform Docs

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
workflow_call:

env:
TERRAFORM_DOCS_VERSION: v0.18.0
Expand All @@ -20,18 +13,65 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
ref: ${{ github.ref }}

- name: Render and Push terraform docs for main and modules
- name: Render and Push terraform docs for main module
uses: terraform-docs/gh-actions@main
with:
working-dir: .
git-push: true
config-file: .terraform-docs.yaml
output-file: README.md
output-format: markdown table
output-method: replace
recursive: false
template: |
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->
{{- printf "\n" -}}
args: "--header-from .header.md"

- name: Check if modules folder exists
id: check_modules
run: echo "modules_exists=$(if [ -d modules ]; then echo true; else echo false; fi)" >> $GITHUB_ENV

- name: Render and Push terraform docs for sub modules
if: env.modules_exists == 'true'
uses: terraform-docs/gh-actions@main
with:
working-dir: .
git-push: true
output-file: README.md
output-format: markdown table
output-method: replace
recursive: true
recursive-path: modules
template: |
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->
{{- printf "\n" -}}
args: "--header-from .header.md"


- name: Check if examples folder exists
id: check_examples
run: echo "examples_exists=$(if [ -d examples ]; then echo true; else echo false; fi)" >> $GITHUB_ENV

- name: Render and Push terraform docs for examples
if: env.examples_exists == 'true'
uses: terraform-docs/gh-actions@main
with:
working-dir: .
git-push: true
config-file: .terraform-docs-example.yaml
output-file: README.md
output-format: markdown table
output-method: replace
recursive: true
recursive-path: examples
template: |
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->
{{- printf "\n" -}}
args: "--header-from .header.md"
36 changes: 36 additions & 0 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Terraform Master Workflow

on:
push:
branches:
- main
- master
pull_request_target:
types:
- opened
- edited
- synchronize
pull_request:
branches:
- main
- master
jobs:
prTitlecheck:
name: PR title check
if: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.base.ref == 'main' }}
uses: ./.github/workflows/pr-title.yaml

preCommitCheck:
name: Terraform Checks
uses: ./.github/workflows/terraform-checks.yaml

generateDocs:
name: Generate Terraform Docs
needs: preCommitCheck
uses: ./.github/workflows/terraform-docs.yaml

release:
name: Release module
needs: generateDocs
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: ./.github/workflows/release.yaml
45 changes: 45 additions & 0 deletions .github/workflows/update-configs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Update Configuration from Template

on:
workflow_dispatch:

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout template repository
uses: actions/checkout@v3
with:
repository: nimisha-gj/terraform-module-template
token: ${{ secrets.GITHUB_TOKEN }}
path: template-repo

- name: Checkout target repository
uses: actions/checkout@v3
with:
repository: ${{ github.repository }}
token: ${{ secrets.GITHUB_TOKEN }}
path: target-repo

- name: Set up Git
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
- name: Copy files from template repository
run: |
cp template-repo/.editorconfig target-repo/
cp template-repo/.pre-commit-config.yaml target-repo/
cp template-repo/LICENSE target-repo/
cp template-repo/.tflint.hcl target-repo/
cp template-repo/.releaserc.json target-repo/
cp template-repo/CODE_OF_CONDUCT.md target-repo/
cp template-repo/CONTRIBUTING.md target-repo/
- name: Commit and push changes
run: |
cd target-repo
git add .
git commit -m "Update files from terraform-module-template"
git push

0 comments on commit 6a460ab

Please sign in to comment.