Skip to content

Commit

Permalink
Fixes for cmd bot (#448)
Browse files Browse the repository at this point in the history
<!-- Remember that you can run `/merge` to enable auto-merge in the PR
-->

<!-- Remember to modify the changelog. If you don't need to modify it,
you can check the following box.
Instead, if you have already modified it, simply delete the following
line. -->

- [x] Does not require a CHANGELOG entry

the issue_comment works from the refs/main branch by default, and
doesn't bring the PR context anyhow. Since i was testing it from the
default branch in paritytech-stg - it was working fine, but from real PR
non-default branch it didn't push result to PR branch.

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
mordamax and actions-user authored Aug 30, 2024
1 parent e220854 commit 2d9e568
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions .github/workflows/cmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ jobs:
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `<details><summary>Command help:</summary>${{ steps.help.outputs.help }}</details>`
body: `<details><summary>Command help:</summary>
\`\`\`
${{ steps.help.outputs.help }}
\`\`\`
</details>`
})
- name: Add confused reaction on failure
Expand Down Expand Up @@ -165,9 +171,49 @@ jobs:
repo: context.repo.repo,
content: '+1'
})
# Get PR branch name, because the issue_comment event does not contain the PR branch name
get-pr-branch:
needs: [clean, fellows]
runs-on: ubuntu-latest
outputs:
pr-branch: ${{ steps.get-pr.outputs.pr_branch }}
repo: ${{ steps.get-pr.outputs.repo }}
steps:
- name: Check if the issue is a PR
id: check-pr
run: |
if [ -n "${{ github.event.issue.pull_request.url }}" ]; then
echo "This is a pull request comment"
else
echo "This is not a pull request comment"
exit 1
fi
- name: Get PR Branch Name and Repo
if: steps.check-pr.outcome == 'success'
id: get-pr
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const prBranch = pr.data.head.ref;
const repo = pr.data.head.repo.full_name;
return { pr_branch: prBranch, repo: repo };
result-encoding: string

- name: Use PR Branch Name and Repo
run: |
echo "The PR branch is ${{ steps.get-pr.outputs.pr_branch }}"
echo "The repository is ${{ steps.get-pr.outputs.repo }}"
cmd:
needs: [clean, fellows]
needs: [get-pr-branch, fellows]
env:
JOB_NAME: 'cmd'
if: ${{ startsWith(github.event.comment.body, '/cmd') && !contains(github.event.comment.body, '--help') && contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
Expand Down Expand Up @@ -225,7 +271,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
repository: ${{ needs.get-pr-branch.outputs.repo }}
ref: ${{ needs.get-pr-branch.outputs.pr-branch }}

- name: Set rust version via common env file
run: cat .github/env >> $GITHUB_ENV
Expand Down Expand Up @@ -256,7 +303,8 @@ jobs:
env:
CMD: ${{ steps.get-pr-comment.outputs.group2 }} # to avoid "" around the command
run: |
echo "Running command: $CMD"
echo "github.ref: ${{ github.ref }}"
echo "Running command: $CMD on branch ${{ needs.get-pr-branch.outputs.pr-branch }}"
git remote -v
python3 .github/scripts/cmd/cmd.py $CMD
git status
Expand All @@ -268,11 +316,11 @@ jobs:
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git pull origin ${{ github.head_ref }}
git pull origin ${{ needs.get-pr-branch.outputs.pr-branch }}
git add .
git restore --staged Cargo.lock # ignore changes in Cargo.lock
git commit -m "Update from ${{ github.actor }} running command '${{ steps.get-pr-comment.outputs.group2 }}'" || true
git push origin ${{ github.head_ref }}
git push origin ${{ needs.get-pr-branch.outputs.pr-branch }}
else
echo "Nothing to commit";
fi
Expand All @@ -290,7 +338,7 @@ jobs:
--no-color \
--change added changed \
--ignore-errors \
refs/remotes/origin/main ${{ github.ref }})
refs/remotes/origin/main refs/heads/${{ needs.get-pr-branch.outputs.pr-branch }})
# Save the multiline result to the output
{
Expand Down

0 comments on commit 2d9e568

Please sign in to comment.