devops: fix cherry-pick bot

This commit is contained in:
Max Schmitt 2022-08-11 09:55:01 +02:00
parent d12afa7ff3
commit 5578b86885

View file

@ -28,19 +28,22 @@ jobs:
ref: release-${{ github.event.inputs.version }} ref: release-${{ github.event.inputs.version }}
fetch-depth: 0 fetch-depth: 0
- name: Cherry-pick commits - name: Cherry-pick commits
id: cherry-pick
run: | run: |
git config --global user.name github-actions
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
for COMMIT_HASH in $(echo "${{ github.event.inputs.commit_hashes }}" | tr "," "\n"); do for COMMIT_HASH in $(echo "${{ github.event.inputs.commit_hashes }}" | tr "," "\n"); do
git cherry-pick --no-commit "$COMMIT_HASH" git cherry-pick --no-commit "$COMMIT_HASH"
COMMIT_MESSAGE="$(git show -s --format=%B $COMMIT_HASH | head -n 1)"
COMMIT_MESSAGE=$(node -e ' COMMIT_MESSAGE=$(node -e '
console.log(process.argv[1]) const match = /^(.*) (\(#\d+\))$/.exec(process.argv[1]);
const match = /^(.*) (\(#\d+\))$/.exec(process.argv[1]); if (!match) {
if (!match) { console.log(process.argv[1]);
console.log(process.argv[1]); process.exit(0);
process.exit(0); }
} console.log(`chery-pick${match[2]}: ${match[1]}`);
console.log(`chery-pick${match[2]}: ${match[1]}`); ' "$COMMIT_MESSAGE")
' $(git show -s --format=%B $COMMIT_HASH))
git commit -m "$COMMIT_MESSAGE" git commit -m "$COMMIT_MESSAGE"
done done
@ -51,22 +54,20 @@ jobs:
run: | run: |
BRANCH_NAME="cherry-pick-${{ github.event.inputs.version }}-$(date +%Y-%m-%d-%H-%M-%S)" BRANCH_NAME="cherry-pick-${{ github.event.inputs.version }}-$(date +%Y-%m-%d-%H-%M-%S)"
echo "::set-output name=BRANCH_NAME::$BRANCH_NAME" echo "::set-output name=BRANCH_NAME::$BRANCH_NAME"
git config --global user.name github-actions
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
git checkout -b "$BRANCH_NAME" git checkout -b "$BRANCH_NAME"
git push origin $BRANCH_NAME git push origin $BRANCH_NAME
- name: Create Pull Request - name: Create Pull Request
uses: actions/github-script@v6 uses: actions/github-script@v4
with: with:
github-token: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }} github-token: ${{ secrets.REPOSITORY_DISPATCH_PERSONAL_ACCESS_TOKEN }}
script: | script: |
const readableCommitHashesList = '${{ github.event.inputs.commit_hashes }}'.split(',').map(hash => `- ${hash}`).join('\n'); const readableCommitHashesList = '${{ github.event.inputs.commit_hashes }}'.split(',').map(hash => `- ${hash}`).join('\n');
const response = await github.pulls.create({ const response = await github.pulls.create({
owner: 'microsoft', owner: 'microsoft',
repo: 'playwright', repo: 'playwright',
head: 'microsoft:${{ steps.prepare-branch.outputs.BRANCH_NAME }}', head: 'microsoft:${{ steps.prepare-branch.outputs.BRANCH_NAME }}',
base: 'main', base: 'release-${{ github.event.inputs.version }}',
title: '${{ steps.prepare-branch.outputs.PR_TITLE }}', title: '${{ steps.cherry-pick.outputs.PR_TITLE }}',
body: `This PR cherry-picks the following commits:\n\n${readableCommitHashesList}`, body: `This PR cherry-picks the following commits:\n\n${readableCommitHashesList}`,
}); });
await github.issues.addLabels({ await github.issues.addLabels({