Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gh-action): ensures generated files are up-to-date in PR #917

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/check-file-updates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Check config and readme updates
on:
pull_request:
paths:
- "apis/**"
bartoszmajsak marked this conversation as resolved.
Show resolved Hide resolved
jobs:
file-updates:
permissions: write-all
name: Test file updates
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run make commands
run: |
make generate && make manifests && make api-docs
AjayJagan marked this conversation as resolved.
Show resolved Hide resolved
AjayJagan marked this conversation as resolved.
Show resolved Hide resolved
- name: Check git status and find new files
id: git_status
run : |
if [[ -n $(git status -s) ]]
then
echo "New files to commit available"
echo "is_files_to_commit_present=true" >> $GITHUB_OUTPUT
AjayJagan marked this conversation as resolved.
Show resolved Hide resolved
delim=""
config_files_joined=""
files=$(git status --porcelain | egrep "apis|config" | cut -b4-)
for file in $files; do
config_files_joined="$config_files_joined$delim$file"
delim=","
done
echo "config_files=$config_files_joined" >> $GITHUB_OUTPUT
delim=""
docs_files_joined=""
files=$(git status --porcelain | egrep "docs" | cut -b4-)
for file in $files; do
docs_files_joined="$docs_files_joined$delim$file"
delim=","
done
AjayJagan marked this conversation as resolved.
Show resolved Hide resolved
echo "docs_files=$docs_files_joined" >> $GITHUB_OUTPUT
else
echo "No new files to commit"
echo "is_files_to_commit_present=false" >> $GITHUB_OUTPUT
fi
- uses: actions/github-script@v7
if: ${{ steps.git_status.outputs.is_files_to_commit_present == 'true' }}
name: Generate failure comments
env:
DOCS_FILES: ${{ steps.git_status.outputs.docs_files }}
CONFIG_FILES: ${{ steps.git_status.outputs.config_files }}
BRANCH_NAME: ${{ github.head_ref }}
with:
script: |
const { DOCS_FILES, CONFIG_FILES, BRANCH_NAME } = process.env
function getFileList(fileStr){
return fileStr.split(",").reduce((acc, curr)=>{
acc += `- https://github.com/${context.actor}/${context.repo.repo}/tree/${BRANCH_NAME}/${curr}\n`
return acc
},"")
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## Important Message ❌\nThis PR cannot be merged as some files need to be updated.\n\nPlease run \`make generate && make manifests\` to update the following file(s):\n\n ${getFileList(CONFIG_FILES)}\nPlease run \`make api-docs\` to update the following file(s):\n\n${getFileList(DOCS_FILES)}`
})
core.setFailed("Please update the config and readme files using make commands")
AjayJagan marked this conversation as resolved.
Show resolved Hide resolved
Loading