terraform-docs / gh-actions

A Github action for generating Terraform module documentation using terraform-docs and gomplate
Apache License 2.0
144 stars 61 forks source link

Migrate to setup-terraform-docs style action #89

Open btkostner opened 2 years ago

btkostner commented 2 years ago

What problem are you facing?

I am personally running into permission issues (https://github.com/terraform-docs/gh-actions/issues/50), but I also see a lot of issues filed here about adding functionality to the git logic. These feature requests are just going to get more and more because this action tries to do too much.

How could terraform-docs help solve your problem?

This action should be renamed to terraform-docs/setup-action and instead of running a docker container, should install the binary file. This is similar to how setup-node, setup-go, and setup-terraform works. This allows the action to do very little, but be extremely powerful because it's composable with other actions in the workflow file.

nikolaik commented 1 year ago

YES to this!

bodgit commented 1 year ago

Instead of renaming the current action, just create a new one that DTRT.

I'd look at doing it myself but it will likely take someone more familiar with writing actions far less time than me blundering about.

bodgit commented 1 year ago

So, it turns out it's not too difficult, even for a JavaScript n00b like me!

An action is available here: bodgit/setup-terraform-docs

I started with a new repository using actions/javascript-action as a template and then used terraform-linters/setup-tflint and a few other similar actions as inspiration.

It's only slightly trickier logic as terraform-docs is released in a .zip archive on Windows and a .tar.gz on all other platforms so I need to handle that scenario.

The following works:

name: Docs
on:
  pull_request:

jobs:
  terraform-docs:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
        name: Checkout source code

      - uses: bodgit/setup-terraform-docs@main
        name: Setup Terraform Docs

      - name: Show location
        run: which terraform-docs

      - name: Show version
        run: terraform-docs --version

I need to test it on Windows to make sure it works there and replace the original generic action documentation. If anyone wants to kick the tyres on it try using main for now and I'll cut a v1 release soon.

bodgit commented 1 year ago

So I got to the point of publishing this to the marketplace and it flagged that there was an action that already existed. Sure enough there's https://github.com/lablabs/setup-terraform-docs which hadn't turned up when I tried looking for such an action.

It's deprecated in favour of the more generic https://github.com/jaxxstorm/action-install-gh-release so while this has been a fun voyage of discovery, I'm just going to use that action instead :smile: