├── .github └── workflows │ └── ci-test.yml ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── entrypoint.sh /.github/workflows/ci-test.yml: -------------------------------------------------------------------------------- 1 | name: Generate Helm README docs 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | 6 | permissions: 7 | contents: read 8 | pull-requests: write 9 | 10 | jobs: 11 | docs: 12 | permissions: 13 | contents: write 14 | pull-requests: write 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | with: 20 | ref: ${{ github.event.pull_request.head.ref }} 21 | 22 | - name: Helm create 23 | run: | 24 | helm create test 25 | helm create test1 26 | helm create test2 27 | mkdir dir 28 | helm create dir/test4 29 | 30 | - name: Render helm docs singal 31 | uses: shaybentk/helm-docs-action@v0.0.1 32 | with: 33 | working-chart: test 34 | git-push: "true" 35 | 36 | - name: Render helm docs multie 37 | uses: shaybentk/helm-docs-action@v0.0.1 38 | with: 39 | working-dir: test1,test2 40 | git-push: "true" 41 | 42 | - name: Render helm docs multie 43 | uses: shaybentk/helm-docs-action@v0.0.1 44 | with: 45 | working-dir: dir/test4 46 | git-push: "true" 47 | 48 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Use a clean tiny image to store artifacts in 2 | FROM alpine 3 | 4 | # Copy all needed files 5 | COPY entrypoint.sh / 6 | RUN chmod +x /entrypoint.sh 7 | 8 | RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories 9 | 10 | RUN set -x \ 11 | && apk update \ 12 | && apk add --no-cache \ 13 | bash \ 14 | git \ 15 | git-lfs \ 16 | jq \ 17 | openssh \ 18 | sed \ 19 | yq 20 | 21 | RUN wget https://github.com/norwoodj/helm-docs/releases/download/v1.11.0/helm-docs_1.11.0_Linux_x86_64.tar.gz && \ 22 | tar -xvf helm-docs_1.11.0_Linux_x86_64.tar.gz && mv helm-docs /usr/local/bin/ && chmod +x /usr/local/bin/helm-docs 23 | 24 | ENTRYPOINT ["/entrypoint.sh"] 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Krzysztof Szyper aka ChristophShyper (https://shyper.pro/) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to per 10 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE 11 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 12 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 13 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 14 | SOFTWARE. 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # helm-docs GitHub Actions 2 | 3 | A Github action for generating Helm module documentation using helm-docs . 4 | Fork from : https://github.com/norwoodj/helm-docs 5 | 6 | 7 | ## Usage 8 | 9 | ```yaml 10 | name: Generate helm docs 11 | on: 12 | - pull_request 13 | jobs: 14 | docs: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v3 18 | with: 19 | ref: ${{ github.event.pull_request.head.ref }} 20 | 21 | - name: Render helm docs inside the README.md and push changes back to PR branch 22 | uses: shaybentk/helm-docs-action@v0.0.1 23 | with: 24 | working-dir: mychart 25 | git-push: "true" 26 | ``` 27 | 28 | 29 | ### Inputs 30 | 31 | | Name | Description | Default | Required | 32 | |------|-------------|---------|----------| 33 | | fail-on-diff | Fail the job if there is any diff found between the generated output and existing file (ignored if `git-push` is set) | `false` | false | 34 | | git-commit-message | Commit message | `helm-docs: automated action` | false | 35 | | git-push | If true it will commit and push the changes | `false` | false | 36 | | git-push-sign-off | If true it will sign-off commit | `false` | false | 37 | | git-push-user-email | If empty the no-reply email of the GitHub Actions bot will be used (i.e. `github-actions[bot]@users.noreply.github.com`) | `""` | false | 38 | | git-push-user-name | If empty the name of the GitHub Actions bot will be used (i.e. `github-actions[bot]`) | `""` | false | 39 | | output-file | File in module directory where the docs should be placed | `README.md` | false | 40 | | working-chart | Name of directory to generate docs for | `.` | false | 41 | | working-dir | Comma separated list of directories to generate docs for | `.` | false | 42 | 43 | 44 | #### Auto commit changes 45 | 46 | To enable you need to ensure a few things first: 47 | 48 | - set `git-push` to `true` 49 | - use `actions/checkout@v3` with the head ref for PRs or branch name for pushes 50 | - PR 51 | 52 | ```yaml 53 | on: 54 | - pull_request 55 | jobs: 56 | docs: 57 | runs-on: ubuntu-latest 58 | steps: 59 | - uses: actions/checkout@v3 60 | with: 61 | ref: ${{ github.event.pull_request.head.ref }} 62 | ``` 63 | 64 | - Push 65 | 66 | ```yaml 67 | on: 68 | push: 69 | branches: 70 | - master 71 | jobs: 72 | docs: 73 | runs-on: ubuntu-latest 74 | steps: 75 | - uses: actions/checkout@v3 76 | with: 77 | ref: master 78 | ``` 79 | ## Examples 80 | 81 | ### Single folder 82 | 83 | ```yaml 84 | - name: Generate Helm Docs 85 | uses: shaybentk/helm-docs-action@v0.0.1 86 | with: 87 | working-dir: mychart 88 | git-push: "true" 89 | ``` 90 | 91 | ### Multi folder 92 | 93 | ```yaml 94 | - name: Generate Helm Docs 95 | uses: shaybentk/helm-docs-action@v0.0.1 96 | with: 97 | working-dir: mychart1,mychart2,mychart3 98 | git-push: "true" 99 | ``` 100 | 101 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: helm-docs-gh-actions 2 | author: helm-docs ,ShayB.T 3 | description: A Github action for generating helm documentation using helm-docs and gomplate. 4 | 5 | inputs: 6 | working-dir: 7 | description: Comma separated list of directories to generate docs for (ignored if `atlantis-file` or `find-dir` is set) 8 | required: false 9 | default: "." 10 | working-chart: 11 | description: Comma separated list of directories to generate docs for (ignored if `atlantis-file` or `find-dir` is set) 12 | required: false 13 | default: "." 14 | output-file: 15 | description: File in module directory where the docs should be placed 16 | required: false 17 | default: "README.md" 18 | git-push: 19 | description: If true it will commit and push the changes 20 | required: false 21 | default: "false" 22 | git-push-user-name: 23 | description: If empty the name of the GitHub Actions bot will be used (i.e. `github-actions[bot]`) 24 | required: false 25 | default: "" 26 | git-push-user-email: 27 | description: If empty the no-reply email of the GitHub Actions bot will be used (i.e. `github-actions[bot]@users.noreply.github.com`) 28 | required: false 29 | default: "" 30 | git-commit-message: 31 | description: Commit message 32 | required: false 33 | default: "helm-docs: automated action" 34 | git-push-sign-off: 35 | description: If true it will sign-off commit 36 | required: false 37 | default: "false" 38 | fail-on-diff: 39 | description: Fail the job if there is any diff found between the generated output and existing file (ignored if `git-push` is set) 40 | required: false 41 | default: "false" 42 | 43 | outputs: 44 | num_changed: 45 | description: Number of files changed 46 | 47 | runs: 48 | using: docker 49 | image: Dockerfile 50 | env: 51 | INPUT_WORKING_DIR: ${{ inputs.working-dir }} 52 | INPUT_CHART: ${{ inputs.working-chart}} 53 | INPUT_OUTPUT_FILE: ${{ inputs.output-file }} 54 | INPUT_OUTPUT_METHOD: ${{ inputs.output-method }} 55 | INPUT_GIT_PUSH: ${{ inputs.git-push }} 56 | INPUT_GIT_COMMIT_MESSAGE: ${{ inputs.git-commit-message }} 57 | INPUT_FAIL_ON_DIFF: ${{ inputs.fail-on-diff }} 58 | INPUT_GIT_PUSH_SIGN_OFF: ${{ inputs.git-push-sign-off }} 59 | INPUT_GIT_PUSH_USER_NAME: ${{ inputs.git-push-user-name }} 60 | INPUT_GIT_PUSH_USER_EMAIL: ${{ inputs.git-push-user-email }} 61 | 62 | branding: 63 | icon: file-text 64 | color: gray-dark -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2021 The helm-docs Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -o errexit 18 | set -o pipefail 19 | set -o errtrace 20 | 21 | 22 | if [ -z "${INPUT_GIT_PUSH_USER_NAME}" ]; then 23 | INPUT_GIT_PUSH_USER_NAME="github-actions[bot]" 24 | fi 25 | 26 | if [ -z "${INPUT_GIT_PUSH_USER_EMAIL}" ]; then 27 | INPUT_GIT_PUSH_USER_EMAIL="github-actions[bot]@users.noreply.github.com" 28 | fi 29 | 30 | git_setup() { 31 | # When the runner maps the $GITHUB_WORKSPACE mount, it is owned by the runner 32 | # user while the created folders are owned by the container user, causing this 33 | # error. Issue description here: https://github.com/actions/checkout/issues/766 34 | git config --global --add safe.directory /github/workspace 35 | 36 | git config --global user.name "${INPUT_GIT_PUSH_USER_NAME}" 37 | git config --global user.email "${INPUT_GIT_PUSH_USER_EMAIL}" 38 | git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true 39 | } 40 | 41 | git_add() { 42 | local file 43 | file="$1" 44 | git add "${file}" 45 | if [ "$(git status --porcelain | grep "$file" | grep -c -E '([MA]\W).+')" -eq 1 ]; then 46 | echo "::debug Added ${file} to git staging area" 47 | else 48 | echo "::debug No change in ${file} detected" 49 | fi 50 | } 51 | 52 | git_status() { 53 | git status --porcelain | grep -c -E '([MA]\W).+' || true 54 | } 55 | 56 | git_commit() { 57 | if [ "$(git_status)" -eq 0 ]; then 58 | echo "::debug No files changed, skipping commit" 59 | exit 0 60 | fi 61 | 62 | echo "::debug Following files will be committed" 63 | git status -s 64 | 65 | local args=( 66 | -m "${INPUT_GIT_COMMIT_MESSAGE}" 67 | ) 68 | 69 | if [ "${INPUT_GIT_PUSH_SIGN_OFF}" = "true" ]; then 70 | args+=("-s") 71 | fi 72 | 73 | git commit "${args[@]}" 74 | } 75 | 76 | update_doc() { 77 | local working_dir 78 | working_dir="$1" 79 | echo "::debug working_dir=${working_dir}" 80 | 81 | helm-docs --chart-to-generate ${working_dir} 82 | success=$? 83 | 84 | if [ $success -ne 0 ]; then 85 | exit $success 86 | fi 87 | 88 | if [ $success -eq 0 ]; then 89 | git_add "${working_dir}/${OUTPUT_FILE}" 90 | fi 91 | 92 | } 93 | 94 | # go to github repo 95 | cd "${GITHUB_WORKSPACE}" 96 | 97 | git_setup 98 | 99 | 100 | if [ -n "${INPUT_CHART}" ]; then 101 | for project_dir in ${INPUT_CHART} ; do 102 | update_doc "${project_dir}" 103 | done 104 | fi 105 | if [ -n "${INPUT_WORKING_DIR}" ]; then 106 | #Split INPUT_WORKING_DIR by commas 107 | for project_dir in ${INPUT_WORKING_DIR//,/ }; do 108 | update_doc "${project_dir}" 109 | done 110 | fi 111 | 112 | 113 | # always set num_changed output 114 | set +e 115 | num_changed=$(git_status) 116 | set -e 117 | echo "num_changed=${num_changed}" >> $GITHUB_OUTPUT 118 | 119 | if [ "${INPUT_GIT_PUSH}" = "true" ]; then 120 | git_commit 121 | git push 122 | else 123 | if [ "${INPUT_FAIL_ON_DIFF}" = "true" ] && [ "${num_changed}" -ne 0 ]; then 124 | echo "::error ::Uncommitted change(s) has been found!" 125 | exit 1 126 | fi 127 | fi 128 | 129 | exit 0 130 | --------------------------------------------------------------------------------