Skip to content

Commit

Permalink
Added docs support for github actions reusable workflows (#334)
Browse files Browse the repository at this point in the history
* Added docs support for github actions reusable workflows

* Updated README.md

* Sanitize reusable workflow name

* Sanitize reusable workflow name

* Added workflows

* Ignore build harness

* Added README

Co-authored-by: actions-bot <[email protected]>
  • Loading branch information
goruha and actions-bot authored Jan 23, 2023
1 parent 4dca0c1 commit 13cb1b5
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea
.project
build-harness.iml
build-harness
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Available targets:
docker/login Login into docker hub
docs/copyright-add Add copyright headers to source code
docs/github-action.md Update `docs/github-action.md` from `action.yaml`
docs/github-actions-reusable-workflows.md Update `docs/github-actions-reusable-workflows.md` from `.github/workflows/*.yaml`
docs/targets.md Update `docs/targets.md` from `make help`
docs/terraform.md Update `docs/terraform.md` from `terraform-docs`
geodesic/deploy Run a Jenkins Job to Deploy $(APP) with $(CANONICAL_TAG)
Expand Down
1 change: 1 addition & 0 deletions docs/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Available targets:
docker/login Login into docker hub
docs/copyright-add Add copyright headers to source code
docs/github-action.md Update `docs/github-action.md` from `action.yaml`
docs/github-actions-reusable-workflows.md Update `docs/github-actions-reusable-workflows.md` from `.github/workflows/*.yaml`
docs/targets.md Update `docs/targets.md` from `make help`
docs/terraform.md Update `docs/terraform.md` from `terraform-docs`
geodesic/deploy Run a Jenkins Job to Deploy $(APP) with $(CANONICAL_TAG)
Expand Down
8 changes: 8 additions & 0 deletions modules/docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ docs/github-action.md: docs/deps packages/install/gomplate
@echo "<!-- markdownlint-disable -->" > $@
@gomplate -d action=./action.yml -f $(BUILD_HARNESS_PATH)/templates/docs-github-action.gotmpl >> $@
@echo "<!-- markdownlint-restore -->" >> $@

.PHONY : docs/github-actions-reusable-workflows.md
## Update `docs/github-actions-reusable-workflows.md` from `.github/workflows/*.yaml`
docs/github-actions-reusable-workflows.md: docs/deps packages/install/gomplate packages/install/yq
@echo "<!-- markdownlint-disable -->" > $@
@yq eval-all --exit-status --no-colors [.] ./.github/workflows/* | \
gomplate -d workflows=stdin:?type=application/yaml -f $(BUILD_HARNESS_PATH)/templates/docs-github-actions-reusable-workflows.gotmpl >> $@
@echo "<!-- markdownlint-restore -->" >> $@
66 changes: 66 additions & 0 deletions templates/docs-github-actions-reusable-workflows.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{/* Inspired https://github.com/Dirrk/action-docs/blob/master/src/default_template.tpl */}}
{{- define "escape_chars" }}{{ . | strings.ReplaceAll "_" "\\_" | strings.ReplaceAll "|" "\\|" | strings.ReplaceAll "*" "\\*" }}{{- end }}
{{- define "sanatize_string" }}{{ . | strings.ReplaceAll "\n\n" "<br><br>" | strings.ReplaceAll " \n" "<br>" | strings.ReplaceAll "\n" "<br>" | tmpl.Exec "escape_chars" }}{{- end }}
{{- define "sanatize_gha_substitution" }}{{ . | strings.ReplaceAll "\\{" "{" | strings.ReplaceAll "\\}" "}" }}{{- end }}
{{- define "to_markdown_ref" }}#{{ . | strings.Trim " " | strings.ToLower | regexp.Replace "[^a-zA-Z0-9- ]" "" | strings.ReplaceAll " " "-" }}{{- end }}
{{- define "gha_reusable_workflow_name" }}{{ index ( . | strings.Split "\n" ) 0 | tmpl.Exec "escape_chars" }}{{- end }}
{{- define "gha_reusable_workflow_reference" }}{{ . | tmpl.Exec "gha_reusable_workflow_name" | tmpl.Exec "to_markdown_ref" }}{{- end }}
{{- define "gha_reusable_workflow_description" }}{{ index ( . | strings.Split "\n" ) 2 | tmpl.Exec "escape_chars" }}{{- end }}
{{- $workflows := (datasource "workflows") -}}

## Workflows

| Name | Description |
|------|-------------|

{{- range $index, $workflow := $workflows }}
{{- if has $workflow.on "workflow_call" }}
| [{{ tmpl.Exec "gha_reusable_workflow_name" $workflow.name }}]({{ tmpl.Exec "gha_reusable_workflow_reference" $workflow.name }}) | {{ tmpl.Exec "gha_reusable_workflow_description" $workflow.name }} |
{{- end }}
{{- end }}

{{ range $index, $workflow := $workflows }}
{{ if has $workflow.on "workflow_call" }}

## {{ tmpl.Exec "sanatize_gha_substitution" $workflow.name }}

{{ if has $workflow.on.workflow_call "inputs" }}

### Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|----------|
{{- range $key, $input := $workflow.on.workflow_call.inputs }}
| {{ tmpl.Exec "escape_chars" $key }} | {{ if (has $input "description") }}{{ tmpl.Exec "sanatize_string" $input.description }}{{ else }}{{ tmpl.Exec "escape_chars" $key }}{{ end }} | {{ tmpl.Exec "sanatize_string" $input.type }} | {{ if (has $input "default") }}{{ tmpl.Exec "sanatize_string" $input.default }}{{ else }}N/A{{ end }} | {{ if (has $input "required") }}{{ $input.required }}{{ else }}false{{ end }} |
{{- end }}

{{- end }}

{{ if has $workflow.on.workflow_call "secrets" }}

### Secrets

| Name | Description | Required |
|------|-------------|----------|
{{- range $key, $secret := $workflow.on.workflow_call.secrets }}
| {{ tmpl.Exec "escape_chars" $key }} | {{ if (has $secret "description") }}{{ tmpl.Exec "sanatize_string" $secret.description }}{{ else }}{{ tmpl.Exec "escape_chars" $key }}{{ end }} | {{ if (has $secret "required") }}{{ $secret.required }}{{ else }}false{{ end }} |
{{- end }}

{{- end }}


{{ if has $workflow.on.workflow_call "outputs" }}
### Outputs

| Name | Description |
|------|-------------|
{{- range $key, $output := $workflow.on.workflow_call.outputs }}
| {{ tmpl.Exec "escape_chars" $key }} | {{ if (has $output "description") }}{{ tmpl.Exec "sanatize_string" $output.description }}{{ else }}{{ tmpl.Exec "escape_chars" $key }}{{ end }} |
{{- end }}


{{- end }}

{{- end }}
{{ end }}

0 comments on commit 13cb1b5

Please sign in to comment.