From 71d37dd8422d9e74028237caf9e393d88ff41a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Heleno?= Date: Fri, 21 Oct 2022 15:47:35 +0200 Subject: [PATCH] ci: add centralized workflows for the devops-stack modules docs: shortened comment feat: change version on the variable file --- .github/workflows/modules-linters.yaml | 38 +++++++++ .github/workflows/modules-release-please.yaml | 22 +++++ .github/workflows/modules-terraform-docs.yaml | 82 +++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 .github/workflows/modules-linters.yaml create mode 100644 .github/workflows/modules-release-please.yaml create mode 100644 .github/workflows/modules-terraform-docs.yaml diff --git a/.github/workflows/modules-linters.yaml b/.github/workflows/modules-linters.yaml new file mode 100644 index 0000000000..2832405657 --- /dev/null +++ b/.github/workflows/modules-linters.yaml @@ -0,0 +1,38 @@ +--- +# GitHub Actions workflow to check that the Terraform code is well formatted and if the commits have the conventional +# commit message structure (the latter is needed to properly create automatic releases with Release Please). +# +# IMPORTANT: This workflow is called by other workflows in our DevOps Stack repositories and it is centralized here in +# order to be easily maintained across modules. Because of this, please make sure you're not introducing any breaking +# changes when modifying this workflow. + +name: "Linters" + +on: + workflow_call: + +jobs: + terraform-format: + runs-on: ubuntu-latest + + steps: + - name: "Check out the repository" + uses: actions/checkout@v3 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + + - name: "Run terraform fmt -check" + run: "terraform fmt -check" + + commits-checks: + runs-on: ubuntu-latest + + steps: + - name: "Check out the repository" + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Fetch all history for all tags and branches + + - name: "Check commit messages" + uses: docker://aevea/commitsar diff --git a/.github/workflows/modules-release-please.yaml b/.github/workflows/modules-release-please.yaml new file mode 100644 index 0000000000..3b08794569 --- /dev/null +++ b/.github/workflows/modules-release-please.yaml @@ -0,0 +1,22 @@ +--- +# GitHub Actions workflow to automatically create releases and changelogs in our DevOps Stack repositories. +# +# IMPORTANT: This workflow is called by other workflows in our DevOps Stack repositories and it is centralized here in +# order to be easily maintained across modules. Because of this, please make sure you're not introducing any breaking +# changes when modifying this workflow. + +name: "Release Modules" + +on: + workflow_call: + +jobs: + release-please: + runs-on: "ubuntu-latest" + steps: + - uses: "google-github-actions/release-please-action@v3" + with: + release-type: "simple" + bump-minor-pre-major: true + extra-files: | + variables.tf diff --git a/.github/workflows/modules-terraform-docs.yaml b/.github/workflows/modules-terraform-docs.yaml new file mode 100644 index 0000000000..f3107fe0d6 --- /dev/null +++ b/.github/workflows/modules-terraform-docs.yaml @@ -0,0 +1,82 @@ +--- +# GitHub Actions workflow to automatically generate documentation from the .tf files of the module. +# The generated documentation will be injected between AsciiDoc comments on the README.adoc. +# +# IMPORTANT: This workflow is called by other workflows in our DevOps Stack repositories and it is centralized here in +# order to be easily maintained across modules. Because of this, please make sure you're not introducing any breaking +# changes when modifying this workflow. + +name: "Terraform Docs" + +on: + workflow_call: + inputs: + variants: + # List of the variants folders as a comma-separated list inside a string (i.e. "eks,aks,sks"). + type: string + required: false + default: "" + +jobs: + terraform-docs: + runs-on: ubuntu-latest + + steps: + - name: "Check out the repository" + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.ref }} + + - name: "Generate Terraform docs" + uses: terraform-docs/gh-actions@v1.0.0 + with: + working-dir: . + indention: 3 + output-format: asciidoc document + output-file: README.adoc + output-method: inject + template: "// BEGIN_TF_DOCS\n{{ .Content }}\n// END_TF_DOCS" # Define template compatible with AsciiDoc + git-push: false + + - name: "Generate Terraform tables" + uses: terraform-docs/gh-actions@v1.0.0 + with: + working-dir: . + indention: 1 # Since the headings are not read inside the collapsible block we can indent as 1 + output-format: asciidoc table + output-file: README.adoc + output-method: inject + template: "// BEGIN_TF_TABLES\n{{ .Content }}\n// END_TF_TABLES" # Define template compatible with AsciiDoc + args: "--hide-empty=true" # Do not show empty sections + git-push: false + + - name: "Generate Terraform docs for the variants" + if: ${{ inputs.variants != '' }} + uses: terraform-docs/gh-actions@v1.0.0 + with: + working-dir: ${{ inputs.variants }} + indention: 3 + output-format: asciidoc document + output-file: README.adoc + output-method: inject + template: "// BEGIN_TF_DOCS\n{{ .Content }}\n// END_TF_DOCS" # Define template compatible with AsciiDoc + git-push: false + + - name: "Generate Terraform tables for the variants" + if: ${{ inputs.variants != '' }} + uses: terraform-docs/gh-actions@v1.0.0 + with: + working-dir: ${{ inputs.variants }} + indention: 1 # Since the headings are not read inside the collapsible block we can indent as 1 + output-format: asciidoc table + output-file: README.adoc + output-method: inject + template: "// BEGIN_TF_TABLES\n{{ .Content }}\n// END_TF_TABLES" # Define template compatible with AsciiDoc + args: "--hide-empty=true" # Do not show empty sections + git-push: false + + # This step avoids a commit for each previous step and instead commits everything on a single commit + - name: "Commit changes done in the previous steps" + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "docs(terraform-docs): generate docs and write to README.adoc"