Closed hongyi-zhao closed 7 months ago
I tried to sync with the upstream repository with the help of this project via the workflow script here, but the error occurred, see here for more details, as shown below:
How do you think I could fix this error?
Regards, Zhao
Hi @hongyi-zhao, is this case still up to date? The problem is not related to the push action in general. Is the fetched repository publicly accessible? If the repository is not available, it is necessary to inject the credentials for the repository.
Is the fetched repository publicly accessible?
See below:
werner@X10DAi:~$ /usr/bin/git clone git://git.lyx.org/lyx
Cloning into 'lyx'...
remote: Enumerating objects: 504295, done.
remote: Counting objects: 100% (504295/504295), done.
^Cmote: Compressing objects: 76% (68942/90574)
Is the fetched repository publicly accessible?
See below:
werner@X10DAi:~$ /usr/bin/git clone git://git.lyx.org/lyx Cloning into 'lyx'... remote: Enumerating objects: 504295, done. remote: Counting objects: 100% (504295/504295), done. ^Cmote: Compressing objects: 76% (68942/90574)
Hello @hongyi-zhao,
I have a feeling that the problem is a side effect of the missing git config --local --add safe.directory
function in your workflow file. The setting is not included by default in the checkout action version v2
. I recommend upgrading to v3
or v4
. It would also be helpful if you could add the --verbose
option to this line.
I've recreated the workfolws based on your comments. Let's see if it can solve the problem.
I have a feeling that the problem is a side effect of the missing
git config --local --add safe.directory
function in your workflow file. The setting is not included by default in the checkout action versionv2
. I recommend upgrading tov3
orv4
.
Based on your above comments, it seems that if I use v3
or v4
, the following line is unnecessary:
But I'm not sure if I understand you correctly.
I have a feeling that the problem is a side effect of the missing
git config --local --add safe.directory
function in your workflow file. The setting is not included by default in the checkout action versionv2
. I recommend upgrading tov3
orv4
.Based on your above comments, it seems that if I use
v3
orv4
, the following line is unnecessary:But I'm not sure if I understand you correctly.
Yes, that is right.
Ok, thank you for your confirmation, and I've updated the corresponding settings to the following:
Strangely, it has exceeded the preset running cycle of my workflow, but it did not run as expected, as shown here.
Thank you very much for reminding me about this. It turned out that the workflows had been put into REPO_ROOT/workflows
instead of REPO_ROOT/.github/workflows
under the root of GitHub repository. I have corrected the problem and let's see if it can work as expected.
It runs but still fails, as shown below, and you see here for more details:
Hi @hongyi-zhao, I think you can remove the duplicate checkout branch step and change the corresponding command by adding the --allow-unrelated-histories
parameter to the execution section. I think this should solve the problem.
I have repaired the workflows according to your suggestion: https://github.com/hongyi-zhao/lyx/blob/master/.github/workflows/sync-with-upstream-repository.yml
Still failed, as shown below:
I manually resolved the conflicts on my local machine, merged with the upstream, and then pushed it to my GitHub repo. Let's see if the workflow works in subsequent update runs.
Hi @hongyi-zhao,
You have some Git merge conflicts and the problem has nothing to do with the GitHub push action. I will try to support you to solve the case and set up a test environment on my side.
Now, I use the following logic to implement automatic merging:
I adjusted the GH action and was able to carry out a successful test. I also checked the runs here and found that you are missing authorizations for the token. You can solve this problem as follows.
Thanks again for your patient help and guidance, I finally succeeded, as shown here.
Although the workflow discussed here has been successful, I still have some additional questions, as shown here:
As shown in the figure above, this method produces many additional commits. Is there a way to avoid this problem by guaranteeing that pull only if upstream does have new commits, and then no additional commits are added in the updated GitHub mirror repo?
Yes, you can use the following code snipped to handle only valid commits.
- name: Merge changes from upstream
run: git merge upstream/master --allow-unrelated-histories -Xtheirs --no-edit # Ensure the upstream branch is correct
- name: Check if push is necessary
id: verify-changed-files
run: |
if [ -n "$(git status --untracked-files=no --porcelain)" ]; then
echo "files_changed=true" >> "$GITHUB_OUTPUT";
else
echo "files_changed=false" >> "$GITHUB_OUTPUT";
fi
Then, how about the following implementation without using your github-push-action
package and without using the temporary variable steps.verify-changed-files.outputs.files_changed
?
name: Sync with upstream repository
on:
workflow_dispatch:
schedule:
- cron: '0 */6 * * *' # Every 6 hours, can be adjusted as needed
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup git
run: |
git config user.name "Hongyi Zhao"
git config user.email "hongyi.zhao@gmail.com"
- name: Add remote upstream
run: git remote add upstream git://git.lyx.org/lyx
- name: Fetch changes from upstream
run: git fetch upstream
- name: Merge changes from upstream
run: git merge upstream/master --allow-unrelated-histories -Xtheirs --no-edit
- name: Push changes if necessary
run: |
if git diff --quiet; then
echo "No changes to push."
else
git push origin master
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Then, how about the following implementation without using your
github-push-action
package and without using the temporary variablesteps.verify-changed-files.outputs.files_changed
?name: Sync with upstream repository on: workflow_dispatch: schedule: - cron: '0 */6 * * *' # Every 6 hours, can be adjusted as needed jobs: sync: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: persist-credentials: false - name: Setup git run: | git config user.name "Hongyi Zhao" git config user.email "hongyi.zhao@gmail.com" - name: Add remote upstream run: git remote add upstream git://git.lyx.org/lyx - name: Fetch changes from upstream run: git fetch upstream - name: Merge changes from upstream run: git merge upstream/master --allow-unrelated-histories -Xtheirs --no-edit - name: Push changes if necessary run: | if git diff --quiet; then echo "No changes to push." else git push origin master fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@hongyi-zhao I don't think this is possible because then you will have problems using the credentials to push to the repository. To better explain the result, I've tested it here
Hi @ZPascal,
Although your latest recommended workflow can avoid frequent updates, I ultimately found that it seems unable to fetch the latest updates from upstream. The latest update in my mirror repo is that I manually updated from the remote upstream repo to local, and then pushed it to the GitHub repo.
For more details, you can check the commit history here.
Hi @ZPascal,
Although your latest recommended workflow can avoid frequent updates, I ultimately found that it seems unable to fetch the latest updates from upstream. The latest update in my mirror repo is that I manually updated from the remote upstream repo to local, and then pushed it to the GitHub repo.
For more details, you can check the commit history here.
Hello @hongyi-zhao,
I rechecked it and found a suitable solution for your case.
Functionality: I forward the output of the fetch command to a file and check the line length in the file to see if a push is necessary.
Test cases: I reverted your commit in my fork and created a state to test the new functionality. After that, I tested the following cases:
Implementation:
- name: Merge changes from upstream
run: git merge upstream/master --allow-unrelated-histories -Xtheirs --no-edit > log.txt # Ensure the upstream branch is correct
- name: Check if push is necessary
id: verify-changed-files
run: |
if [ $(wc -l log.txt | sed 's/ log.txt//g') -gt 2 ]; then
echo "files_changed=true" >> "$GITHUB_OUTPUT";
else
echo "files_changed=false" >> "$GITHUB_OUTPUT";
fi
rm -rf log.txt
I hope this helps you. I will leave the fork for a few more days to observe the orderly effect of the functionality.
After a period of observation, it seems that your above modification has achieved the expected functionality.
I tried to sync with the upstream repository with the help of this project via the workflow script here, but the error occurred, see here for more details, as shown below:
How do you think I could fix this error?
Regards, Zhao