-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- 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
1 parent
e220854
commit 2d9e568
Showing
1 changed file
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) }} | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
{ | ||
|