-
Notifications
You must be signed in to change notification settings - Fork 0
chore: Rewriting the workflow to use push instead of PR #4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,331 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Reverse Sync on Push | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TARGET_REPO: alaudadevops/tektoncd-operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Ignoring the files or folders in this prefix (uses comma to split) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IGNORE_PATHS: .github/,README.md | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # will check these files change to create a new patch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SYNCED_PATHS: "docs/ theme/ .yarn/ doom.config.yml yarn.lock tsconfig.json package.json sites.yaml" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| branches: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - main | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - release-* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Limit token capabilities to what the job really needs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: read # checkout / git diff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pull-requests: write # create PR in target repo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # (Optional) Prevent multiple syncs of the same ref running in parallel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| concurrency: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group: reverse-sync-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reverse-sync: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Checkout devops-pipelines-docs repository | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| token: ${{ secrets.GH_TOKEN }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| token: ${{ secrets.GH_TOKEN }} | |
| token: ${{ secrets.GITHUB_TOKEN }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use a single built-in token instead of a custom GH_TOKEN secret
actions/checkout@v4 and the GitHub REST API work seamlessly with the auto-generated GITHUB_TOKEN, which is already scoped by the permissions: block.
Relying on an extra secret increases maintenance, requires additional repository settings, and exposes one more credential.
- with:
- token: ${{ secrets.GH_TOKEN }}
+ with:
+ token: ${{ secrets.GITHUB_TOKEN }}Make the same replacement in all other occurrences (checkout of target-docs, curl … /pulls, and the git push remote URL).
After the change you can remove the GH_TOKEN secret from the repo settings.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GH_TOKEN }} | |
| fetch-depth: 0 | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 |
🤖 Prompt for AI Agents
In .github/workflows/reverse-sync-push.yml around lines 22 to 26, replace the
custom secret token `${{ secrets.GH_TOKEN }}` used in the `actions/checkout@v4`
step with the built-in `${{ secrets.GITHUB_TOKEN }}`. Also update all other
occurrences where `GH_TOKEN` is used, including checkout steps for
`target-docs`, any `curl` commands accessing pull requests, and the `git push`
remote URL, to use `GITHUB_TOKEN` instead. After these changes, remove the
`GH_TOKEN` secret from the repository settings to reduce maintenance and
exposure of credentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
PR-number detection misses regular merge commits
The current regex only matches squash-merge titles ending in “(#123)”.
Regular merge commits created by the GitHub UI have the form “Merge pull request #123 …” and will bypass the reverse-sync logic.
- if [[ "$commit_message" =~ \(#([0-9]+)\)$ ]]; then
+ if [[ "$commit_message" =~ \(#([0-9]+)\)$ ]] || [[ "$commit_message" =~ [Pp]ull[[:space:]]request[[:space:]]#([0-9]+) ]]; thenConsider extracting the regex into a variable for readability and unit-testing the pattern with typical commit messages to avoid future regressions.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Look for PR number in commit message (GitHub automatically adds this) | |
| if [[ "$commit_message" =~ \(#([0-9]+)\)$ ]]; then | |
| pr_number="${BASH_REMATCH[1]}" | |
| echo "pr_number=$pr_number" >> $GITHUB_OUTPUT | |
| echo "is_pr_commit=true" >> $GITHUB_OUTPUT | |
| echo "✅ Detected commit from PR #$pr_number" | |
| else | |
| echo "is_pr_commit=false" >> $GITHUB_OUTPUT | |
| echo "ℹ️ Not a PR commit - skipping reverse sync" | |
| fi | |
| # Look for PR number in commit message (GitHub automatically adds this) | |
| - if [[ "$commit_message" =~ \(#([0-9]+)\)$ ]]; then | |
| + if [[ "$commit_message" =~ \(#([0-9]+)\)$ ]] || [[ "$commit_message" =~ [Pp]ull[[:space:]]request[[:space:]]#([0-9]+) ]]; then | |
| pr_number="${BASH_REMATCH[1]}" | |
| echo "pr_number=$pr_number" >> $GITHUB_OUTPUT | |
| echo "is_pr_commit=true" >> $GITHUB_OUTPUT | |
| echo "✅ Detected commit from PR #$pr_number" | |
| else | |
| echo "is_pr_commit=false" >> $GITHUB_OUTPUT | |
| echo "ℹ️ Not a PR commit - skipping reverse sync" | |
| fi |
🤖 Prompt for AI Agents
In .github/workflows/reverse-sync-push.yml around lines 49 to 58, the regex only
matches squash-merge commit messages ending with (#123), missing regular merge
commits like "Merge pull request #123 ...". Update the regex to also detect
these regular merge commit formats. Extract the regex pattern into a variable
for clarity and maintainability, and consider adding unit tests for the regex
against typical commit message formats to prevent future detection issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Patch application nearly always fails because of directory mismatch
git format-patch … > changes.patch is generated from the repo root, but git apply is executed inside target-docs/.
Unless both repos share an identical directory structure, paths inside the patch won’t resolve and the script falls back to the slower per-file copy.
- git format-patch $parent_commit..$commit_sha --stdout -- $SYNCED_PATHS > changes.patch
+ git -C $GITHUB_WORKSPACE \
+ format-patch $parent_commit..$commit_sha --stdout -- $SYNCED_PATHS > changes.patch
...
- git apply ../changes.patch || {
+ git apply --directory=$GITHUB_WORKSPACE/../target-docs ../changes.patch || {Alternatively, switch to git diff -p1 and patch -p1 executed from the same directory to avoid the indirection.
Fixing this will save unnecessary IO and runtime.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In .github/workflows/reverse-sync-push.yml around lines 160 to 169, the patch
generated by git format-patch is created from the repo root but applied inside
the target-docs directory, causing path mismatches and patch failures. To fix
this, replace git format-patch with git diff -p1 to generate the patch and use
patch -p1 to apply it, ensuring both commands run from the same directory
(target-docs) so paths align correctly and avoid fallback to manual copying.
Copilot
AI
Jul 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback for a failed patch application relies on manual copy of files. Consider adding more detailed logging or error handling here to facilitate troubleshooting if the patch fails.
| echo "⚠️ Patch application failed, trying manual copy..." | |
| # Fallback: manual copy of changed files | |
| while IFS= read -r file; do | |
| if [ -f "../$file" ]; then | |
| mkdir -p "$(dirname "$file")" | |
| cp "../$file" "$file" | |
| echo "✅ Copied: $file" | |
| echo "⚠️ Patch application failed. Capturing error details..." | |
| git apply ../changes.patch 2> ../patch_error.log | |
| echo "❌ Error details logged to patch_error.log:" | |
| cat ../patch_error.log | |
| echo "⚠️ Attempting manual copy of changed files as fallback..." | |
| # Validate changed_files.txt | |
| if [ ! -f ../changed_files.txt ]; then | |
| echo "❌ Error: changed_files.txt not found. Cannot proceed with manual copy." | |
| exit 1 | |
| fi | |
| # Fallback: manual copy of changed files | |
| while IFS= read -r file; do | |
| if [ -f "../$file" ]; then | |
| mkdir -p "$(dirname "$file")" || { | |
| echo "❌ Error: Failed to create directory for $file" | |
| continue | |
| } | |
| cp "../$file" "$file" || { | |
| echo "❌ Error: Failed to copy $file" | |
| continue | |
| } | |
| echo "✅ Copied: $file" | |
| else | |
| echo "⚠️ Warning: File $file not found in source. Skipping." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary
Uh oh!
There was an error while loading. Please reload this page.