Skip to content

Commit b6f45fe

Browse files
committed
document input/output and add a job to check that
1 parent 4322223 commit b6f45fe

File tree

3 files changed

+187
-0
lines changed

3 files changed

+187
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Check README.md Updates
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'action.yml'
7+
- 'README.md'
8+
- '.github/workflows/check-readme.yaml'
9+
10+
permissions: {}
11+
12+
jobs:
13+
check-readme:
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: read
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
23+
- name: Create temporary README
24+
run: |
25+
cp README.md README.md.original
26+
27+
- name: Update temporary README with current inputs/outputs
28+
shell: bash
29+
run: |
30+
./hack/update-inputs.sh
31+
32+
- name: Check for differences
33+
id: diff
34+
run: |
35+
if diff -q README.md README.md.original &>/dev/null; then
36+
echo "No differences found. README.md is up-to-date."
37+
echo "up_to_date=true" >> $GITHUB_OUTPUT
38+
else
39+
echo "Differences found. README.md needs to be updated."
40+
diff -u README.md.original README.md || true
41+
echo "up_to_date=false" >> $GITHUB_OUTPUT
42+
fi
43+
44+
- name: Fail if README.md is not updated
45+
if: steps.diff.outputs.up_to_date == 'false'
46+
run: |
47+
echo "::error::README.md needs to be updated to reflect the current inputs/outputs in action.yml"
48+
echo "Please run the ./hack/update-inputs.sh script and commit the changes."
49+
exit 1

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,33 @@ patchesJSON6902:
115115
value: cgr.dev/chainguard/cert-manager-controller:1.11.1@sha256:819a8714fc52fe3ecf3d046ba142e02ce2a95d1431b7047b358d23df6759de6c
116116
...
117117
```
118+
119+
## Inputs / Outputs
120+
121+
<!-- begin automated updates do not change -->
122+
### Inputs
123+
124+
| Name | Description | Default |
125+
|------|-------------|--------|
126+
| `working-dir` | Working directory to run the digestabot, to run in a specific path, if not set will run from the root | `.` |
127+
| `token` | GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT) | `${{ github.token }}` |
128+
| `signoff` | Add `Signed-off-by` line by the committer at the end of the commit log message. | `false` |
129+
| `author` | The author name and email address in the format `Display Name <email@address.com>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor_id }}+${{...` |
130+
| `committer` | The committer name and email address in the format `Display Name <email@address.com>`. Defaults to the GitHub Actions bot user. | `github-actions[bot] <41898282+github-actions[bo...` |
131+
| `labels-for-pr` | A comma or newline separated list of labels to be used in the pull request. | `automated pr, kind/cleanup, release-note-none` |
132+
| `branch-for-pr` | The pull request branch name. | `update-digests` |
133+
| `title-for-pr` | The title of the pull request. | `Update images digests` |
134+
| `description-for-pr` | The description of the pull request. | `Update images digests ...` |
135+
| `commit-message` | The message to use when committing changes. | `Update images digests` |
136+
| `create-pr` | Create a PR or just keep the changes locally. | `true` |
137+
| `use-gitsign` | Use gitsign to sign commits. | `true` |
138+
139+
### Outputs
140+
141+
| Name | Description |
142+
|------|-------------|
143+
| `pull_request_number` | Pull Request Number |
144+
| `json` | The changes made by this action, in JSON format. Contains information about updated files, images, and digests. |
145+
146+
> **Note:** For complete details on inputs and outputs, please refer to the [action.yml](./action.yml) file.
147+
<!-- end automated updates do not change -->

hack/update-inputs.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
3+
# Path to your action.yml file and README.md
4+
ACTION_YML="action.yml"
5+
README_MD="README.md"
6+
7+
# Check if yq is installed
8+
if ! command -v yq &> /dev/null; then
9+
echo "Error: yq is not installed. Please install it first."
10+
exit 1
11+
fi
12+
13+
# Generate table for inputs
14+
generate_inputs_table() {
15+
local table="| Name | Description | Default |\n"
16+
table+="|------|-------------|--------|\n"
17+
18+
# Get all input names
19+
local input_names=
20+
input_names=$(yq e '.inputs | keys | .[]' "${ACTION_YML}")
21+
22+
for name in ${input_names}; do
23+
# Get description and properly format it
24+
local description=
25+
description=$(yq e ".inputs.${name}.description" "${ACTION_YML}")
26+
# Compress multi-line descriptions and escape pipes
27+
description=$(echo "${description}" | tr '\n' ' ' | sed 's/|/\\|/g')
28+
29+
# Get default value
30+
local default=
31+
default=$(yq e ".inputs.${name}.default" "${ACTION_YML}")
32+
33+
# For multi-line default values, show only first line
34+
if [[ $(echo "${default}" | wc -l) -gt 1 ]]; then
35+
local first_line=
36+
first_line=$(echo "${default}" | head -n 1 | sed 's/|/\\|/g')
37+
default="${first_line} ..."
38+
else
39+
default=$(echo "${default}" | sed 's/|/\\|/g')
40+
fi
41+
42+
# Truncate long default values
43+
if [[ ${#default} -gt 50 ]]; then
44+
default="${default:0:47}..."
45+
fi
46+
47+
table+="| \`${name}\` | ${description} | \`${default}\` |\n"
48+
done
49+
50+
echo -e "${table}"
51+
}
52+
53+
# Generate table for outputs
54+
generate_outputs_table() {
55+
local table="| Name | Description |\n"
56+
table+="|------|-------------|\n"
57+
58+
# Get all output names
59+
local output_names=
60+
output_names=$(yq e '.outputs | keys | .[]' "${ACTION_YML}")
61+
62+
for name in ${output_names}; do
63+
local description=
64+
description=$(yq e ".outputs.${name}.description" "${ACTION_YML}")
65+
66+
# For complex descriptions like JSON examples, use a simplified approach
67+
if [[ "${name}" == "json" ]]; then
68+
description="The changes made by this action, in JSON format. Contains information about updated files, images, and digests."
69+
else
70+
# For regular descriptions, flatten them
71+
description=$(echo "${description}" | tr '\n' ' ' | sed 's/|/\\|/g')
72+
fi
73+
74+
table+="| \`${name}\` | ${description} |\n"
75+
done
76+
77+
echo -e "${table}"
78+
}
79+
80+
# Generate tables for inputs and outputs
81+
inputs_table=$(generate_inputs_table)
82+
outputs_table=$(generate_outputs_table)
83+
84+
# Combine the tables with headers
85+
markdown_table="### Inputs\n\n${inputs_table}\n\n### Outputs\n\n${outputs_table}\n\n> **Note:** For complete details on inputs and outputs, please refer to the [action.yml](./action.yml) file."
86+
87+
# Check if the end placeholder exists, if not add it
88+
if ! grep -q "<!-- end automated updates do not change -->" "${README_MD}"; then
89+
echo "<!-- end automated updates do not change -->" >> "${README_MD}"
90+
echo "Added missing end placeholder to README.md"
91+
fi
92+
93+
# Create a temporary file
94+
temp_file=$(mktemp)
95+
96+
# Extract the content before the begin placeholder
97+
sed -n '1,/<!-- begin automated updates do not change -->/p' "${README_MD}" > "${temp_file}"
98+
99+
# Add our markdown table
100+
echo -e "${markdown_table}" >> "${temp_file}"
101+
102+
# Extract the content after the end placeholder
103+
sed -n '/<!-- end automated updates do not change -->/,$p' "${README_MD}" >> "${temp_file}"
104+
105+
# Replace the original file with the temporary file
106+
mv "${temp_file}" "${README_MD}"
107+
108+
echo "README.md has been updated with the inputs and outputs tables."

0 commit comments

Comments
 (0)