Skip to content

Commit 3a54e0b

Browse files
committed
ci: add workflows for generating docs, validating pr titles, pre-commit, and creating releases with semantic versioning
1 parent ef1ce4d commit 3a54e0b

File tree

4 files changed

+225
-0
lines changed

4 files changed

+225
-0
lines changed

.github/workflows/documentation.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Generate terraform docs
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
docs:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v4
12+
with:
13+
ref: ${{ github.event.pull_request.head.ref }}
14+
15+
- name: Render terraform docs and push changes back to PR
16+
uses: terraform-docs/gh-actions@main
17+
with:
18+
working-dir: .
19+
recursive: true
20+
recursive-path: modules
21+
output-file: README.md
22+
output-method: replace
23+
git-push: true
24+
25+
- name: Ensure newline at end of README files
26+
run: |
27+
find . -type f -name 'README.md' -exec sh -c 'echo >> "{}"' \;
28+
working-directory: ${{ github.workspace }}
29+
30+
- name: Commit changes
31+
run: |
32+
git config --local user.email "action@github.com"
33+
git config --local user.name "GitHub Action"
34+
git add .
35+
git commit -m "Fix newline at end of README.md files"
36+
git push origin ${{ github.event.pull_request.head.ref }}
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pr-title.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'Validate PR title'
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
main:
12+
name: Validate PR title
13+
runs-on: ubuntu-latest
14+
steps:
15+
# Please look up the latest version from
16+
# https://github.com/amannn/action-semantic-pull-request/releases
17+
- uses: amannn/action-semantic-pull-request@v5.4.0
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
with:
21+
# Configure which types are allowed.
22+
# Default: https://github.com/commitizen/conventional-commit-types
23+
types: |
24+
fix
25+
feat
26+
docs
27+
ci
28+
chore
29+
# Configure that a scope must always be provided.
30+
requireScope: false
31+
# Configure additional validation for the subject based on a regex.
32+
# This example ensures the subject starts with an uppercase character.
33+
subjectPattern: ^[A-Z].+$
34+
# If `subjectPattern` is configured, you can use this property to override
35+
# the default error message that is shown when the pattern doesn't match.
36+
# The variables `subject` and `title` can be used within the message.
37+
subjectPatternError: |
38+
The subject "{subject}" found in the pull request title "{title}"
39+
didn't match the configured pattern. Please ensure that the subject
40+
starts with an uppercase character.
41+
# For work-in-progress PRs you can typically use draft pull requests
42+
# from Github. However, private repositories on the free plan don't have
43+
# this option and therefore this action allows you to opt-in to using the
44+
# special "[WIP]" prefix to indicate this state. This will avoid the
45+
# validation of the PR title and the pull request checks remain pending.
46+
# Note that a second check will be reported if this is enabled.
47+
wip: true
48+
# When using "Squash and merge" on a PR with only one commit, GitHub
49+
# will suggest using that commit message instead of the PR title for the
50+
# merge commit, and it's easy to commit this by mistake. Enable this option
51+
# to also validate the commit message for one commit PRs.
52+
validateSingleCommit: false

.github/workflows/pre-commit.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Pre-Commit
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
13+
env:
14+
TERRAFORM_DOCS_VERSION: v0.18.0
15+
TFLINT_VERSION: v0.52.0
16+
17+
jobs:
18+
collectInputs:
19+
name: Collect workflow inputs
20+
runs-on: ubuntu-latest
21+
outputs:
22+
directories: ${{ steps.dirs.outputs.directories }}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Get root directories
28+
id: dirs
29+
uses: clowdhaus/terraform-composite-actions/directories@v1.9.0
30+
31+
preCommitMinVersions:
32+
name: Min TF pre-commit
33+
needs: collectInputs
34+
runs-on: ubuntu-latest
35+
strategy:
36+
matrix:
37+
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
38+
steps:
39+
# https://github.com/orgs/community/discussions/25678#discussioncomment-5242449
40+
- name: Delete huge unnecessary tools folder
41+
run: |
42+
rm -rf /opt/hostedtoolcache/CodeQL
43+
rm -rf /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk
44+
rm -rf /opt/hostedtoolcache/Ruby
45+
rm -rf /opt/hostedtoolcache/go
46+
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
50+
- name: Terraform min/max versions
51+
id: minMax
52+
uses: clowdhaus/terraform-min-max@v1.3.0
53+
with:
54+
directory: ${{ matrix.directory }}
55+
56+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
57+
# Run only validate pre-commit check on min version supported
58+
if: ${{ matrix.directory != '.' }}
59+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.9.0
60+
with:
61+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
62+
tflint-version: ${{ env.TFLINT_VERSION }}
63+
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
64+
65+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
66+
# Run only validate pre-commit check on min version supported
67+
if: ${{ matrix.directory == '.' }}
68+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.9.0
69+
with:
70+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
71+
tflint-version: ${{ env.TFLINT_VERSION }}
72+
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
73+
74+
preCommitMaxVersion:
75+
name: Max TF pre-commit
76+
runs-on: ubuntu-latest
77+
needs: collectInputs
78+
steps:
79+
# https://github.com/orgs/community/discussions/25678#discussioncomment-5242449
80+
- name: Delete huge unnecessary tools folder
81+
run: |
82+
rm -rf /opt/hostedtoolcache/CodeQL
83+
rm -rf /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk
84+
rm -rf /opt/hostedtoolcache/Ruby
85+
rm -rf /opt/hostedtoolcache/go
86+
87+
- name: Checkout
88+
uses: actions/checkout@v4
89+
with:
90+
ref: ${{ github.event.pull_request.head.ref }}
91+
repository: ${{github.event.pull_request.head.repo.full_name}}
92+
93+
- name: Terraform min/max versions
94+
id: minMax
95+
uses: clowdhaus/terraform-min-max@v1.3.0
96+
97+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
98+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.9.0
99+
with:
100+
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
101+
tflint-version: ${{ env.TFLINT_VERSION }}
102+
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
103+
install-hcledit: true

.github/workflows/release.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: 'Module Release'
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
jobs:
13+
release:
14+
name: Release
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
with:
20+
persist-credentials: false
21+
fetch-depth: 0
22+
23+
- name: Release
24+
uses: cycjimmy/semantic-release-action@v2
25+
with:
26+
semantic_version: 18.0.0
27+
extra_plugins: |
28+
@semantic-release/changelog@6.0.0
29+
@semantic-release/git@10.0.0
30+
conventional-changelog-conventionalcommits@4.6.3
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)