From c498ce981f64df9aa9d50358d0720245b5233988 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:02:01 +1000 Subject: [PATCH 01/30] ci: Try to fix errors in workflow --- .github/workflows/sync-commit.yml | 49 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/.github/workflows/sync-commit.yml b/.github/workflows/sync-commit.yml index 2cd86cc..f85c836 100644 --- a/.github/workflows/sync-commit.yml +++ b/.github/workflows/sync-commit.yml @@ -30,35 +30,42 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | + const { context, github } = require('@actions/github'); const { owner, repo } = context.repo; const base = 'main'; const head = 'dev'; const commits = process.env.commits.split('\n').map(commit => `- ${commit}`).join('\n'); const committer = process.env.committer; - const { data: existingPRs } = await github.pulls.list({ - owner, - repo, - head: `${owner}:${head}`, - base, - state: 'open', - }); - - if (existingPRs.length > 0) { - const pr = existingPRs[0]; - await github.pulls.update({ - owner, - repo, - pull_number: pr.number, - body: `${pr.body}\n\n${commits}` - }); - } else { - await github.pulls.create({ + async function run() { + const { data: existingPRs } = await github.pulls.list({ owner, repo, - title: 'Sync dev to main', - head, + head: `${owner}:${head}`, base, - body: commits + state: 'open', }); + + if (existingPRs.length > 0) { + const pr = existingPRs[0]; + await github.pulls.update({ + owner, + repo, + pull_number: pr.number, + body: `${pr.body}\n\n${commits}` + }); + } else { + await github.pulls.create({ + owner, + repo, + title: 'Sync dev to main', + head, + base, + body: commits + }); + } } + + run().catch(error => { + core.setFailed(error.message); + }); From c0b2627c3bfb5ad0b0e789fd4f6a3c3820ce913e Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:03:45 +1000 Subject: [PATCH 02/30] ci: Try to fix errors in workflow Yes, again :( --- .github/workflows/sync-commit.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/sync-commit.yml b/.github/workflows/sync-commit.yml index f85c836..6792384 100644 --- a/.github/workflows/sync-commit.yml +++ b/.github/workflows/sync-commit.yml @@ -30,15 +30,16 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const { context, github } = require('@actions/github'); - const { owner, repo } = context.repo; + const github = require('@actions/github'); + const core = require('@actions/core'); + const { owner, repo } = github.context.repo; const base = 'main'; const head = 'dev'; const commits = process.env.commits.split('\n').map(commit => `- ${commit}`).join('\n'); const committer = process.env.committer; async function run() { - const { data: existingPRs } = await github.pulls.list({ + const { data: existingPRs } = await github.rest.pulls.list({ owner, repo, head: `${owner}:${head}`, @@ -48,14 +49,14 @@ jobs: if (existingPRs.length > 0) { const pr = existingPRs[0]; - await github.pulls.update({ + await github.rest.pulls.update({ owner, repo, pull_number: pr.number, body: `${pr.body}\n\n${commits}` }); } else { - await github.pulls.create({ + await github.rest.pulls.create({ owner, repo, title: 'Sync dev to main', From 15570affa35e9191cdb2f0b69b4142f9d25fca4d Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:05:47 +1000 Subject: [PATCH 03/30] ci: Try to fix errors in workflow I hope I can fix it today --- .github/workflows/sync-commit.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/sync-commit.yml b/.github/workflows/sync-commit.yml index 6792384..182948c 100644 --- a/.github/workflows/sync-commit.yml +++ b/.github/workflows/sync-commit.yml @@ -30,16 +30,17 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const github = require('@actions/github'); + const { context, getOctokit } = require('@actions/github'); const core = require('@actions/core'); - const { owner, repo } = github.context.repo; + const { owner, repo } = context.repo; + const octokit = getOctokit(core.getInput('github-token')); const base = 'main'; const head = 'dev'; const commits = process.env.commits.split('\n').map(commit => `- ${commit}`).join('\n'); const committer = process.env.committer; async function run() { - const { data: existingPRs } = await github.rest.pulls.list({ + const { data: existingPRs } = await octokit.rest.pulls.list({ owner, repo, head: `${owner}:${head}`, @@ -49,14 +50,14 @@ jobs: if (existingPRs.length > 0) { const pr = existingPRs[0]; - await github.rest.pulls.update({ + await octokit.rest.pulls.update({ owner, repo, pull_number: pr.number, body: `${pr.body}\n\n${commits}` }); } else { - await github.rest.pulls.create({ + await octokit.rest.pulls.create({ owner, repo, title: 'Sync dev to main', From 197ba0defb9eddb529983d3bfffd009b162948c1 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:07:15 +1000 Subject: [PATCH 04/30] ci: Try to fix errors in workflow --- .github/workflows/sync-commit.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sync-commit.yml b/.github/workflows/sync-commit.yml index 182948c..f5e2d86 100644 --- a/.github/workflows/sync-commit.yml +++ b/.github/workflows/sync-commit.yml @@ -25,15 +25,15 @@ jobs: echo "committer=$(git log -1 --pretty=format:'%an')" >> $GITHUB_ENV - name: Create or update pull request - id: create_pr uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const { context, getOctokit } = require('@actions/github'); + const github = require('@actions/github'); const core = require('@actions/core'); - const { owner, repo } = context.repo; - const octokit = getOctokit(core.getInput('github-token')); + const octokit = github.getOctokit(core.getInput('github-token')); + + const { owner, repo } = github.context.repo; const base = 'main'; const head = 'dev'; const commits = process.env.commits.split('\n').map(commit => `- ${commit}`).join('\n'); From 745d7eccedef310c757c690d9c5b7cccfad98b09 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:09:04 +1000 Subject: [PATCH 05/30] ci: Try to fix errors in workflow --- .github/workflows/sync-commit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sync-commit.yml b/.github/workflows/sync-commit.yml index f5e2d86..647ebc4 100644 --- a/.github/workflows/sync-commit.yml +++ b/.github/workflows/sync-commit.yml @@ -29,11 +29,11 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const github = require('@actions/github'); + const { getOctokit, context } = require('@actions/github'); const core = require('@actions/core'); - const octokit = github.getOctokit(core.getInput('github-token')); + const octokit = getOctokit(core.getInput('github-token')); - const { owner, repo } = github.context.repo; + const { owner, repo } = context.repo; const base = 'main'; const head = 'dev'; const commits = process.env.commits.split('\n').map(commit => `- ${commit}`).join('\n'); From 201f038ac8e7585d6552ec11f283e85126b17902 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:17:46 +1000 Subject: [PATCH 06/30] ci: Try to change the way workflow runs to fix error --- .github/workflows/auto_pr.yml | 69 +++++++++++++++++++++++++++++ .github/workflows/sync-commit.yml | 73 ------------------------------- 2 files changed, 69 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/auto_pr.yml delete mode 100644 .github/workflows/sync-commit.yml diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml new file mode 100644 index 0000000..34c7039 --- /dev/null +++ b/.github/workflows/auto_pr.yml @@ -0,0 +1,69 @@ +name: Auto PR + +on: + push: + branches: + - dev + +jobs: + handle_pr: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Get committer username and email + run: | + echo "committer_username=$(git log -1 --pretty=format:'%an')" >> $GITHUB_ENV + echo "committer_email=$(git log -1 --pretty=format:'%ae')" >> $GITHUB_ENV + + - name: Set PR branch name + run: echo "pr_branch=dev_pr_${{ env.committer_username }}" >> $GITHUB_ENV + + - name: Configure git + run: | + git config --global user.name "${{ env.committer_username }}" + git config --global user.email "${{ env.committer_email }}" + + - name: Check if PR branch exists + id: check_branch + run: | + if git show-ref --verify --quiet refs/heads/${{ env.pr_branch }}; then + echo "branch_exists=true" >> $GITHUB_ENV + else + echo "branch_exists=false" >> $GITHUB_ENV + fi + + - name: Get existing PR number + id: get_pr_number + if: env.branch_exists == 'true' + run: | + pr_number=$(gh pr list --state open --head ${{ env.pr_branch }} --json number -q '.[0].number') + echo "pr_number=$pr_number" >> $GITHUB_ENV + + - name: Sync commits to existing PR branch + if: env.branch_exists == 'true' + run: | + git push origin HEAD:refs/heads/${{ env.pr_branch }} + + - name: Create new branch + if: env.branch_exists == 'false' + run: | + git checkout -b ${{ env.pr_branch }} + git push origin ${{ env.pr_branch }} + + - name: Create Pull Request + if: env.branch_exists == 'false' + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ env.pr_branch }} + base: main + title: "Auto PR from ${{ env.pr_branch }}" + body: "This is an automated PR created from ${{ env.pr_branch }}" + + - name: Append commit to existing PR + if: env.branch_exists == 'true' + run: | + gh pr comment ${{ env.pr_number }} --body "New commits have been added to the PR." diff --git a/.github/workflows/sync-commit.yml b/.github/workflows/sync-commit.yml deleted file mode 100644 index 647ebc4..0000000 --- a/.github/workflows/sync-commit.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Sync to Main - -on: - push: - branches: - - dev - -jobs: - create-or-update-pull-request: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up Git - run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - - name: Fetch commit messages - id: fetch_commits - run: | - echo "commits=$(git log --pretty=format:'%h - %s' origin/main..HEAD)" >> $GITHUB_ENV - echo "committer=$(git log -1 --pretty=format:'%an')" >> $GITHUB_ENV - - - name: Create or update pull request - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { getOctokit, context } = require('@actions/github'); - const core = require('@actions/core'); - const octokit = getOctokit(core.getInput('github-token')); - - const { owner, repo } = context.repo; - const base = 'main'; - const head = 'dev'; - const commits = process.env.commits.split('\n').map(commit => `- ${commit}`).join('\n'); - const committer = process.env.committer; - - async function run() { - const { data: existingPRs } = await octokit.rest.pulls.list({ - owner, - repo, - head: `${owner}:${head}`, - base, - state: 'open', - }); - - if (existingPRs.length > 0) { - const pr = existingPRs[0]; - await octokit.rest.pulls.update({ - owner, - repo, - pull_number: pr.number, - body: `${pr.body}\n\n${commits}` - }); - } else { - await octokit.rest.pulls.create({ - owner, - repo, - title: 'Sync dev to main', - head, - base, - body: commits - }); - } - } - - run().catch(error => { - core.setFailed(error.message); - }); From bbda0919501e3c3089417bc98a323a57dc899710 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:20:13 +1000 Subject: [PATCH 07/30] ci: Change the way name branch --- .github/workflows/auto_pr.yml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 34c7039..898eb68 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -15,11 +15,15 @@ jobs: - name: Get committer username and email run: | - echo "committer_username=$(git log -1 --pretty=format:'%an')" >> $GITHUB_ENV - echo "committer_email=$(git log -1 --pretty=format:'%ae')" >> $GITHUB_ENV + committer_username=$(git log -1 --pretty=format:'%an') + committer_email=$(git log -1 --pretty=format:'%ae') + echo "committer_username=$committer_username" >> $GITHUB_ENV + echo "committer_email=$committer_email" >> $GITHUB_ENV - - name: Set PR branch name - run: echo "pr_branch=dev_pr_${{ env.committer_username }}" >> $GITHUB_ENV + - name: Hash committer username + run: | + branch_name=$(echo -n "${{ env.committer_username }}" | md5sum | awk '{ print $1 }') + echo "branch_name=dev_pr_$branch_name" >> $GITHUB_ENV - name: Configure git run: | @@ -29,7 +33,7 @@ jobs: - name: Check if PR branch exists id: check_branch run: | - if git show-ref --verify --quiet refs/heads/${{ env.pr_branch }}; then + if git show-ref --verify --quiet refs/heads/${{ env.branch_name }}; then echo "branch_exists=true" >> $GITHUB_ENV else echo "branch_exists=false" >> $GITHUB_ENV @@ -39,29 +43,29 @@ jobs: id: get_pr_number if: env.branch_exists == 'true' run: | - pr_number=$(gh pr list --state open --head ${{ env.pr_branch }} --json number -q '.[0].number') + pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV - name: Sync commits to existing PR branch if: env.branch_exists == 'true' run: | - git push origin HEAD:refs/heads/${{ env.pr_branch }} + git push origin HEAD:refs/heads/${{ env.branch_name }} - name: Create new branch if: env.branch_exists == 'false' run: | - git checkout -b ${{ env.pr_branch }} - git push origin ${{ env.pr_branch }} + git checkout -b ${{ env.branch_name }} + git push origin ${{ env.branch_name }} - name: Create Pull Request if: env.branch_exists == 'false' uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ env.pr_branch }} + branch: ${{ env.branch_name }} base: main - title: "Auto PR from ${{ env.pr_branch }}" - body: "This is an automated PR created from ${{ env.pr_branch }}" + title: "Auto PR from ${{ env.branch_name }}" + body: "This is an automated PR created from ${{ env.branch_name }}" - name: Append commit to existing PR if: env.branch_exists == 'true' From be858f85521a0e949e204ba5d4f7d034f4d32e64 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:22:07 +1000 Subject: [PATCH 08/30] ci: Try to let workflow can success create PRs --- .github/workflows/auto_pr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 898eb68..32558a2 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -24,6 +24,7 @@ jobs: run: | branch_name=$(echo -n "${{ env.committer_username }}" | md5sum | awk '{ print $1 }') echo "branch_name=dev_pr_$branch_name" >> $GITHUB_ENV + echo "Branch name: ${{ env.branch_name }}" - name: Configure git run: | @@ -45,6 +46,7 @@ jobs: run: | pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV + echo "Existing PR number: $pr_number" - name: Sync commits to existing PR branch if: env.branch_exists == 'true' From a718f7845b6b37f850b9d27fc2dc202f33cad8fa Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:24:09 +1000 Subject: [PATCH 09/30] ci: FIx errors --- .github/workflows/auto_pr.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 32558a2..0ec9d67 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -1,3 +1,4 @@ +# .github/workflows/auto-pr.yml name: Auto PR on: @@ -51,6 +52,8 @@ jobs: - name: Sync commits to existing PR branch if: env.branch_exists == 'true' run: | + git fetch origin ${{ env.branch_name }} + git rebase origin/${{ env.branch_name }} git push origin HEAD:refs/heads/${{ env.branch_name }} - name: Create new branch From d3ebfd9f9cec1a5d66da4dfb5c87ca457a815459 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:25:41 +1000 Subject: [PATCH 10/30] ci: Try to fix errors --- .github/workflows/auto_pr.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 0ec9d67..57125b3 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -41,19 +41,12 @@ jobs: echo "branch_exists=false" >> $GITHUB_ENV fi - - name: Get existing PR number - id: get_pr_number + - name: Fetch and merge remote branch if: env.branch_exists == 'true' run: | - pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') - echo "pr_number=$pr_number" >> $GITHUB_ENV - echo "Existing PR number: $pr_number" - - - name: Sync commits to existing PR branch - if: env.branch_exists == 'true' - run: | - git fetch origin ${{ env.branch_name }} - git rebase origin/${{ env.branch_name }} + git fetch origin + git checkout ${{ env.branch_name }} + git pull origin ${{ env.branch_name }} --rebase git push origin HEAD:refs/heads/${{ env.branch_name }} - name: Create new branch From e62076893892ac9b40df40de7851af902e6ba888 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:26:50 +1000 Subject: [PATCH 11/30] ci: Try to fix error --- .github/workflows/auto_pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 57125b3..6f9191b 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -53,6 +53,7 @@ jobs: if: env.branch_exists == 'false' run: | git checkout -b ${{ env.branch_name }} + git pull git push origin ${{ env.branch_name }} - name: Create Pull Request From 56a20ed527ba02eeb6deb991b38eb890338f761d Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:27:53 +1000 Subject: [PATCH 12/30] ci: FIx errors --- .github/workflows/auto_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 6f9191b..0230ca7 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -53,7 +53,7 @@ jobs: if: env.branch_exists == 'false' run: | git checkout -b ${{ env.branch_name }} - git pull + git pull origin ${{ env.branch_name }} git push origin ${{ env.branch_name }} - name: Create Pull Request From 5520d69b3b3a125bc54c4d195ecb0f3b9bf1d15b Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:28:58 +1000 Subject: [PATCH 13/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 0230ca7..b0d75d8 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -53,6 +53,7 @@ jobs: if: env.branch_exists == 'false' run: | git checkout -b ${{ env.branch_name }} + git config pull.rebase true git pull origin ${{ env.branch_name }} git push origin ${{ env.branch_name }} From cb205c8cd2f59e6df9a685d4e3e73554f6840385 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:30:21 +1000 Subject: [PATCH 14/30] ci: Try to change the way workflow pull --- .github/workflows/auto_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index b0d75d8..d65775b 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -53,7 +53,7 @@ jobs: if: env.branch_exists == 'false' run: | git checkout -b ${{ env.branch_name }} - git config pull.rebase true + git config pull.rebase false git pull origin ${{ env.branch_name }} git push origin ${{ env.branch_name }} From f3248805fc8c4b91a634b3d37e90db091b0ff555 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:31:14 +1000 Subject: [PATCH 15/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index d65775b..b0d75d8 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -53,7 +53,7 @@ jobs: if: env.branch_exists == 'false' run: | git checkout -b ${{ env.branch_name }} - git config pull.rebase false + git config pull.rebase true git pull origin ${{ env.branch_name }} git push origin ${{ env.branch_name }} From 4e64c624e30b74f4bd6514ca76b6c63809d3ebc2 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:33:37 +1000 Subject: [PATCH 16/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index b0d75d8..0f2ee79 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -52,6 +52,7 @@ jobs: - name: Create new branch if: env.branch_exists == 'false' run: | + git branch -M ${{ env.branch_name }} git checkout -b ${{ env.branch_name }} git config pull.rebase true git pull origin ${{ env.branch_name }} From ce2d07d07ba542167a8b16243900a69baf2cf7a3 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:35:18 +1000 Subject: [PATCH 17/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 0f2ee79..1cb5d7f 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -53,7 +53,7 @@ jobs: if: env.branch_exists == 'false' run: | git branch -M ${{ env.branch_name }} - git checkout -b ${{ env.branch_name }} + git checkout ${{ env.branch_name }} git config pull.rebase true git pull origin ${{ env.branch_name }} git push origin ${{ env.branch_name }} From c02e9996902e34b058d4c778844776b7246a2528 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:36:40 +1000 Subject: [PATCH 18/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 1cb5d7f..885deb3 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -55,7 +55,6 @@ jobs: git branch -M ${{ env.branch_name }} git checkout ${{ env.branch_name }} git config pull.rebase true - git pull origin ${{ env.branch_name }} git push origin ${{ env.branch_name }} - name: Create Pull Request From cc50bbd75965f4c6ff90be6f0f9af17d69a64b81 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:45:23 +1000 Subject: [PATCH 19/30] docs: Add info about ci --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9499464..765a54b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ Tips: 文档将很快迁移到单独仓库/网站。 您可以在遵循许可证的情况下自由分发/使用此项目。 +## 贡献提示 + +如果您对此存储库具有写权限,请仅推送到 dev 分支,CI 系统会自动创建一个 Pull Request + ## 贡献者 From 599db0aea4cee71f4e5266efc01cbd370afe12e8 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:47:44 +1000 Subject: [PATCH 20/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 885deb3..d6d16e2 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -32,29 +32,31 @@ jobs: git config --global user.name "${{ env.committer_username }}" git config --global user.email "${{ env.committer_email }}" + - name: Create and push new branch based on dev + if: env.branch_exists == 'false' + run: | + git fetch origin + git checkout dev + git pull origin dev + git checkout -b ${{ env.branch_name }} + git push origin ${{ env.branch_name }} + - name: Check if PR branch exists id: check_branch run: | - if git show-ref --verify --quiet refs/heads/${{ env.branch_name }}; then + git fetch origin + if git show-ref --verify --quiet refs/remotes/origin/${{ env.branch_name }}; then echo "branch_exists=true" >> $GITHUB_ENV else echo "branch_exists=false" >> $GITHUB_ENV fi - - name: Fetch and merge remote branch + - name: Fetch, rebase and push to existing branch if: env.branch_exists == 'true' run: | git fetch origin git checkout ${{ env.branch_name }} git pull origin ${{ env.branch_name }} --rebase - git push origin HEAD:refs/heads/${{ env.branch_name }} - - - name: Create new branch - if: env.branch_exists == 'false' - run: | - git branch -M ${{ env.branch_name }} - git checkout ${{ env.branch_name }} - git config pull.rebase true git push origin ${{ env.branch_name }} - name: Create Pull Request @@ -70,4 +72,5 @@ jobs: - name: Append commit to existing PR if: env.branch_exists == 'true' run: | - gh pr comment ${{ env.pr_number }} --body "New commits have been added to the PR." + pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') + gh pr comment ${{ pr_number }} --body "New commits have been added to the PR." From 6386c9102d280e34b6f944cf893077b941c1f71a Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:49:50 +1000 Subject: [PATCH 21/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index d6d16e2..c37b743 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -69,8 +69,15 @@ jobs: title: "Auto PR from ${{ env.branch_name }}" body: "This is an automated PR created from ${{ env.branch_name }}" - - name: Append commit to existing PR + - name: Get PR number if: env.branch_exists == 'true' + id: get_pr_number run: | pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') - gh pr comment ${{ pr_number }} --body "New commits have been added to the PR." + echo "pr_number=$pr_number" >> $GITHUB_ENV + echo "PR number: $pr_number" + + - name: Append commit to existing PR + if: env.branch_exists == 'true' + run: | + gh pr comment ${{ env.pr_number }} --body "New commits have been added to the PR." From f90448f3bb53db38e8ec1d675dd29d3b42812b60 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:51:21 +1000 Subject: [PATCH 22/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index c37b743..d640cef 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -14,6 +14,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 + - name: Install GitHub CLI + run: sudo apt-get install gh + - name: Get committer username and email run: | committer_username=$(git log -1 --pretty=format:'%an') @@ -32,15 +35,6 @@ jobs: git config --global user.name "${{ env.committer_username }}" git config --global user.email "${{ env.committer_email }}" - - name: Create and push new branch based on dev - if: env.branch_exists == 'false' - run: | - git fetch origin - git checkout dev - git pull origin dev - git checkout -b ${{ env.branch_name }} - git push origin ${{ env.branch_name }} - - name: Check if PR branch exists id: check_branch run: | @@ -51,6 +45,16 @@ jobs: echo "branch_exists=false" >> $GITHUB_ENV fi + - name: Create and push new branch based on dev + if: env.branch_exists == 'false' + run: | + git fetch origin + git checkout dev + git pull origin dev + git checkout -b ${{ env.branch_name }} + git push origin ${{ env.branch_name }} + git branch -a # List all branches for debugging + - name: Fetch, rebase and push to existing branch if: env.branch_exists == 'true' run: | @@ -80,4 +84,5 @@ jobs: - name: Append commit to existing PR if: env.branch_exists == 'true' run: | + echo "Appending commit to PR #${{ env.pr_number }}" gh pr comment ${{ env.pr_number }} --body "New commits have been added to the PR." From d92c04ca67d84e6b9bda9d6eba22fdb73761697d Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:54:03 +1000 Subject: [PATCH 23/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index d640cef..36df1f7 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -65,24 +65,30 @@ jobs: - name: Create Pull Request if: env.branch_exists == 'false' - uses: peter-evans/create-pull-request@v3 + uses: peter-evans/create-pull-request@v6 with: token: ${{ secrets.GITHUB_TOKEN }} branch: ${{ env.branch_name }} base: main title: "Auto PR from ${{ env.branch_name }}" body: "This is an automated PR created from ${{ env.branch_name }}" + draft: false # Ensure the PR is not a draft - - name: Get PR number - if: env.branch_exists == 'true' - id: get_pr_number + - name: Verify Pull Request Creation + if: env.branch_exists == 'false' run: | - pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') - echo "pr_number=$pr_number" >> $GITHUB_ENV - echo "PR number: $pr_number" + pr_url=$(gh pr list --state open --head ${{ env.branch_name }} --json url -q '.[0].url') + echo "PR URL: $pr_url" + if [ -z "$pr_url" ]; then + echo "PR creation failed." + exit 1 + else + echo "PR created successfully: $pr_url" + fi - name: Append commit to existing PR if: env.branch_exists == 'true' run: | - echo "Appending commit to PR #${{ env.pr_number }}" + pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') + echo "pr_number=$pr_number" >> $GITHUB_ENV gh pr comment ${{ env.pr_number }} --body "New commits have been added to the PR." From 2629bd27145050eecb9dd78940a82fa663945062 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:55:36 +1000 Subject: [PATCH 24/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 36df1f7..935a295 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -87,6 +87,8 @@ jobs: fi - name: Append commit to existing PR + env: + GH_TOKEN: ${{ github.token }} if: env.branch_exists == 'true' run: | pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') From 8b5818f21d40652131eb275ad32ede2003581f73 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:57:53 +1000 Subject: [PATCH 25/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 935a295..e65e8fb 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -65,7 +65,8 @@ jobs: - name: Create Pull Request if: env.branch_exists == 'false' - uses: peter-evans/create-pull-request@v6 + id: create_pr + uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.GITHUB_TOKEN }} branch: ${{ env.branch_name }} @@ -74,23 +75,22 @@ jobs: body: "This is an automated PR created from ${{ env.branch_name }}" draft: false # Ensure the PR is not a draft - - name: Verify Pull Request Creation + - name: Wait for PR creation if: env.branch_exists == 'false' + run: sleep 10 # Wait for 10 seconds to ensure PR creation is processed + + - name: Get PR number + if: env.branch_exists == 'false' + id: get_pr_number run: | - pr_url=$(gh pr list --state open --head ${{ env.branch_name }} --json url -q '.[0].url') - echo "PR URL: $pr_url" - if [ -z "$pr_url" ]; then - echo "PR creation failed." - exit 1 - else - echo "PR created successfully: $pr_url" - fi + pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') + echo "pr_number=$pr_number" >> $GITHUB_ENV + echo "PR number: $pr_number" - name: Append commit to existing PR - env: - GH_TOKEN: ${{ github.token }} if: env.branch_exists == 'true' run: | pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV + echo "Appending commit to PR #${{ env.pr_number }}" gh pr comment ${{ env.pr_number }} --body "New commits have been added to the PR." From e3f224778753d9d5aac96c1d9ed44de2070f8045 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:59:34 +1000 Subject: [PATCH 26/30] ci: FIx errors --- .github/workflows/auto_pr.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index e65e8fb..5cb5dfb 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -82,6 +82,8 @@ jobs: - name: Get PR number if: env.branch_exists == 'false' id: get_pr_number + env: + GH_TOKEN: ${{ github.token }} run: | pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV @@ -89,6 +91,8 @@ jobs: - name: Append commit to existing PR if: env.branch_exists == 'true' + env: + GH_TOKEN: ${{ github.token }} run: | pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV From 657779ee4669e9a0faaa1500dd2092434218249a Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 21:03:36 +1000 Subject: [PATCH 27/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 5cb5dfb..250cec1 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -1,4 +1,3 @@ -# .github/workflows/auto-pr.yml name: Auto PR on: @@ -73,26 +72,30 @@ jobs: base: main title: "Auto PR from ${{ env.branch_name }}" body: "This is an automated PR created from ${{ env.branch_name }}" - draft: false # Ensure the PR is not a draft + draft: false - name: Wait for PR creation if: env.branch_exists == 'false' - run: sleep 10 # Wait for 10 seconds to ensure PR creation is processed + run: sleep 30 # 等待 30 秒 - name: Get PR number if: env.branch_exists == 'false' id: get_pr_number env: - GH_TOKEN: ${{ github.token }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV echo "PR number: $pr_number" + if [ -z "$pr_number" ]; then + echo "No PR found for branch ${{ env.branch_name }}" + exit 1 + fi - name: Append commit to existing PR if: env.branch_exists == 'true' env: - GH_TOKEN: ${{ github.token }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV From 933fab9c70fa816749c32d74fb2762fff22cde44 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 21:05:48 +1000 Subject: [PATCH 28/30] ci: Fix errors :( --- .github/workflows/auto_pr.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 250cec1..f646a4e 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -65,14 +65,17 @@ jobs: - name: Create Pull Request if: env.branch_exists == 'false' id: create_pr - uses: peter-evans/create-pull-request@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ env.branch_name }} - base: main - title: "Auto PR from ${{ env.branch_name }}" - body: "This is an automated PR created from ${{ env.branch_name }}" - draft: false + run: | + curl -X POST \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{ + "title": "Auto PR from ${{ env.branch_name }}", + "body": "This is an automated PR created from ${{ env.branch_name }}", + "head": "${{ env.branch_name }}", + "base": "main" + }' \ + https://api.github.com/repos/${{ github.repository }}/pulls - name: Wait for PR creation if: env.branch_exists == 'false' @@ -80,9 +83,6 @@ jobs: - name: Get PR number if: env.branch_exists == 'false' - id: get_pr_number - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV From 0413567a60717508a4747ffe645323cf6c1f73b1 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 21:09:22 +1000 Subject: [PATCH 29/30] ci: Try to fix errors --- .github/workflows/auto_pr.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index f646a4e..3c952f4 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -52,7 +52,6 @@ jobs: git pull origin dev git checkout -b ${{ env.branch_name }} git push origin ${{ env.branch_name }} - git branch -a # List all branches for debugging - name: Fetch, rebase and push to existing branch if: env.branch_exists == 'true' @@ -66,7 +65,7 @@ jobs: if: env.branch_exists == 'false' id: create_pr run: | - curl -X POST \ + response=$(curl -s -X POST \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \ -d '{ @@ -75,22 +74,21 @@ jobs: "head": "${{ env.branch_name }}", "base": "main" }' \ - https://api.github.com/repos/${{ github.repository }}/pulls + https://api.github.com/repos/${{ github.repository }}/pulls) + + echo "response=$response" >> $GITHUB_ENV + echo "PR creation response: $response" - name: Wait for PR creation if: env.branch_exists == 'false' - run: sleep 30 # 等待 30 秒 + run: sleep 30 # 等待 30 秒,确保 PR 被创建 - name: Get PR number if: env.branch_exists == 'false' run: | - pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') + pr_number=$(echo "${{ env.response }}" | jq -r .number) echo "pr_number=$pr_number" >> $GITHUB_ENV echo "PR number: $pr_number" - if [ -z "$pr_number" ]; then - echo "No PR found for branch ${{ env.branch_name }}" - exit 1 - fi - name: Append commit to existing PR if: env.branch_exists == 'true' From b65735201d4900e9cf305b015b67a33f6423c694 Mon Sep 17 00:00:00 2001 From: Cycle Bai <168964798+CycleBai@users.noreply.github.com> Date: Mon, 29 Jul 2024 21:16:29 +1000 Subject: [PATCH 30/30] ci: Fix errors --- .github/workflows/auto_pr.yml | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/.github/workflows/auto_pr.yml b/.github/workflows/auto_pr.yml index 3c952f4..6cbf069 100644 --- a/.github/workflows/auto_pr.yml +++ b/.github/workflows/auto_pr.yml @@ -64,29 +64,26 @@ jobs: - name: Create Pull Request if: env.branch_exists == 'false' id: create_pr - run: | - response=$(curl -s -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d '{ - "title": "Auto PR from ${{ env.branch_name }}", - "body": "This is an automated PR created from ${{ env.branch_name }}", - "head": "${{ env.branch_name }}", - "base": "main" - }' \ - https://api.github.com/repos/${{ github.repository }}/pulls) - - echo "response=$response" >> $GITHUB_ENV - echo "PR creation response: $response" + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ env.branch_name }} + base: main + title: "Auto PR from ${{ env.branch_name }}" + body: "This is an automated PR created from ${{ env.branch_name }}" + draft: false - name: Wait for PR creation if: env.branch_exists == 'false' - run: sleep 30 # 等待 30 秒,确保 PR 被创建 + run: sleep 20 # 等待 20 秒,确保 PR 被创建 - name: Get PR number if: env.branch_exists == 'false' + id: get_pr_number + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - pr_number=$(echo "${{ env.response }}" | jq -r .number) + pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number') echo "pr_number=$pr_number" >> $GITHUB_ENV echo "PR number: $pr_number"