Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shaybentk authored Jan 12, 2023
0 parents commit f1da6a7
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Use a clean tiny image to store artifacts in
FROM alpine

# Copy all needed files
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh

RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories

RUN set -x \
&& apk update \
&& apk add --no-cache \
bash \
git \
git-lfs \
jq \
openssh \
sed \
yq

RUN wget https://github.com/norwoodj/helm-docs/releases/download/v1.11.0/helm-docs_1.11.0_Linux_x86_64.tar.gz && \
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

ENTRYPOINT ["/entrypoint.sh"]
14 changes: 14 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MIT License

Copyright (c) 2021 Krzysztof Szyper aka ChristophShyper (https://shyper.pro/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to per
FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# helm-docs GitHub Actions

A Github action for generating Helm module documentation using helm-docs .
Fork from : https://github.com/norwoodj/helm-docs


## Usage

```yaml
name: Generate helm docs
on:
- pull_request
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Render helm docs inside the README.md and push changes back to PR branch
uses: shaybentk/[email protected]
with:
working-dir: mychart
git-push: "true"
```
### Inputs
| Name | Description | Default | Required |
|------|-------------|---------|----------|
| 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 |
| git-commit-message | Commit message | `helm-docs: automated action` | false |
| git-push | If true it will commit and push the changes | `false` | false |
| git-push-sign-off | If true it will sign-off commit | `false` | false |
| 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 |
| git-push-user-name | If empty the name of the GitHub Actions bot will be used (i.e. `github-actions[bot]`) | `""` | false |
| output-file | File in module directory where the docs should be placed | `README.md` | false |
| working-chart | Name of directory to generate docs for | `.` | false |
| working-dir | Comma separated list of directories to generate docs for | `.` | false |


#### Auto commit changes

To enable you need to ensure a few things first:

- set `git-push` to `true`
- use `actions/checkout@v3` with the head ref for PRs or branch name for pushes
- PR

```yaml
on:
- pull_request
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
```

- Push

```yaml
on:
push:
branches:
- master
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: master
```
## Examples

### Single folder

```yaml
- name: Generate Helm Docs
uses: shaybentk/[email protected]
with:
working-dir: mychart
git-push: "true"
```

### Multi folder

```yaml
- name: Generate Helm Docs
uses: shaybentk/[email protected]
with:
working-dir: mychart1,mychart2,mychart3
git-push: "true"
```

64 changes: 64 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: helm-docs-gh-actions
author: helm-docs ,ShayB.T
description: A Github action for generating helm documentation using helm-docs and gomplate.

inputs:
working-dir:
description: Comma separated list of directories to generate docs for (ignored if `atlantis-file` or `find-dir` is set)
required: false
default: "."
working-chart:
description: Comma separated list of directories to generate docs for (ignored if `atlantis-file` or `find-dir` is set)
required: false
default: "."
output-file:
description: File in module directory where the docs should be placed
required: false
default: "README.md"
git-push:
description: If true it will commit and push the changes
required: false
default: "false"
git-push-user-name:
description: If empty the name of the GitHub Actions bot will be used (i.e. `github-actions[bot]`)
required: false
default: ""
git-push-user-email:
description: If empty the no-reply email of the GitHub Actions bot will be used (i.e. `github-actions[bot]@users.noreply.github.com`)
required: false
default: ""
git-commit-message:
description: Commit message
required: false
default: "helm-docs: automated action"
git-push-sign-off:
description: If true it will sign-off commit
required: false
default: "false"
fail-on-diff:
description: Fail the job if there is any diff found between the generated output and existing file (ignored if `git-push` is set)
required: false
default: "false"

outputs:
num_changed:
description: Number of files changed

runs:
using: docker
image: Dockerfile
env:
INPUT_WORKING_DIR: ${{ inputs.working-dir }}
INPUT_CHART: ${{ inputs.working-chart}}
INPUT_OUTPUT_FILE: ${{ inputs.output-file }}
INPUT_OUTPUT_METHOD: ${{ inputs.output-method }}
INPUT_GIT_PUSH: ${{ inputs.git-push }}
INPUT_GIT_COMMIT_MESSAGE: ${{ inputs.git-commit-message }}
INPUT_FAIL_ON_DIFF: ${{ inputs.fail-on-diff }}
INPUT_GIT_PUSH_SIGN_OFF: ${{ inputs.git-push-sign-off }}
INPUT_GIT_PUSH_USER_NAME: ${{ inputs.git-push-user-name }}
INPUT_GIT_PUSH_USER_EMAIL: ${{ inputs.git-push-user-email }}

branding:
icon: file-text
color: gray-dark
129 changes: 129 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env bash
#
# Copyright 2021 The helm-docs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o pipefail
set -o errtrace


if [ -z "${INPUT_GIT_PUSH_USER_NAME}" ]; then
INPUT_GIT_PUSH_USER_NAME="github-actions[bot]"
fi

if [ -z "${INPUT_GIT_PUSH_USER_EMAIL}" ]; then
INPUT_GIT_PUSH_USER_EMAIL="github-actions[bot]@users.noreply.github.com"
fi

git_setup() {
# When the runner maps the $GITHUB_WORKSPACE mount, it is owned by the runner
# user while the created folders are owned by the container user, causing this
# error. Issue description here: https://github.com/actions/checkout/issues/766
git config --global --add safe.directory /github/workspace

git config --global user.name "${INPUT_GIT_PUSH_USER_NAME}"
git config --global user.email "${INPUT_GIT_PUSH_USER_EMAIL}"
git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
}

git_add() {
local file
file="$1"
git add "${file}"
if [ "$(git status --porcelain | grep "$file" | grep -c -E '([MA]\W).+')" -eq 1 ]; then
echo "::debug Added ${file} to git staging area"
else
echo "::debug No change in ${file} detected"
fi
}

git_status() {
git status --porcelain | grep -c -E '([MA]\W).+' || true
}

git_commit() {
if [ "$(git_status)" -eq 0 ]; then
echo "::debug No files changed, skipping commit"
exit 0
fi

echo "::debug Following files will be committed"
git status -s

local args=(
-m "${INPUT_GIT_COMMIT_MESSAGE}"
)

if [ "${INPUT_GIT_PUSH_SIGN_OFF}" = "true" ]; then
args+=("-s")
fi

git commit "${args[@]}"
}

update_doc() {
local working_dir
working_dir="$1"
echo "::debug working_dir=${working_dir}"

helm-docs --chart-to-generate ${working_dir}
success=$?

if [ $success -ne 0 ]; then
exit $success
fi

if [ $success -eq 0 ]; then
git_add "${working_dir}/${OUTPUT_FILE}"
fi

}

# go to github repo
cd "${GITHUB_WORKSPACE}"

git_setup


if [ -n "${INPUT_CHART}" ]; then
for project_dir in ${INPUT_CHART} ; do
update_doc "${project_dir}"
done
fi
if [ -n "${INPUT_WORKING_DIR}" ]; then
#Split INPUT_WORKING_DIR by commas
for project_dir in ${INPUT_WORKING_DIR//,/ }; do
update_doc "${project_dir}"
done
fi


# always set num_changed output
set +e
num_changed=$(git_status)
set -e
echo "num_changed=${num_changed}" >> $GITHUB_OUTPUT

if [ "${INPUT_GIT_PUSH}" = "true" ]; then
git_commit
git push
else
if [ "${INPUT_FAIL_ON_DIFF}" = "true" ] && [ "${num_changed}" -ne 0 ]; then
echo "::error ::Uncommitted change(s) has been found!"
exit 1
fi
fi

exit 0

0 comments on commit f1da6a7

Please sign in to comment.