Skip to content

Commit

Permalink
add pr-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mordamax committed Aug 30, 2024
1 parent a60880b commit bcb69cd
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions .github/workflows/cmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,55 @@ jobs:
fi
if [[ $BODY == "/cmd bench"* ]]; then
echo "RUNNER=arc-runners-polkadot-sdk-benchmark" >> $GITHUB_OUTPUT
echo "RUNNER=arc-runners-beefy-stg" >> $GITHUB_OUTPUT
elif [[ $BODY == "/cmd update-ui"* ]]; then
echo "RUNNER=arc-runners-polkadot-sdk-beefy" >> $GITHUB_OUTPUT
echo "RUNNER=arc-runners-beefy-stg" >> $GITHUB_OUTPUT
else
echo "RUNNER=ubuntu-latest" >> $GITHUB_OUTPUT
fi
cmd:
# Get PR branch name, because the issue_comment event does not contain the PR branch name
get-pr-branch:
needs: [ set-image ]
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;
console.log(prBranch, repo, pr, pr.data, pr.data.head)
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: [ set-image, get-pr-branch ]
env:
JOB_NAME: 'cmd'
runs-on: ${{ needs.set-image.outputs.RUNNER }}
Expand Down Expand Up @@ -291,7 +331,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: Install dependencies for bench
if: startsWith(steps.get-pr-comment.outputs.group2, 'bench')
Expand All @@ -317,11 +358,11 @@ jobs:
git config --local user.email "action@github.com"
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 Down

0 comments on commit bcb69cd

Please sign in to comment.