Skip to content

[3.4.x] [ocpp] Retry MeterValues ChangeConfiguration with stripped measurand on Reject #769

[3.4.x] [ocpp] Retry MeterValues ChangeConfiguration with stripped measurand on Reject

[3.4.x] [ocpp] Retry MeterValues ChangeConfiguration with stripped measurand on Reject #769

Workflow file for this run

name: Backport
on:
pull_request_target:
types: [closed, labeled]
branches: ["master", "3.*", "4.*", "5.*"]
jobs:
backport:
if: >
github.event.pull_request.merged == true &&
contains(join(github.event.pull_request.labels.*.name, ' '), 'backport-')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Get Github App Token
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
id: app-token
with:
app-id: ${{ vars.BOT_APP_ID }}
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # 6.0.3
with:
token: '${{ steps.app-token.outputs.token }}'
fetch-depth: 0
- name: Run backports
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
LABELS: ${{ join(github.event.pull_request.labels.*.name, ' ') }}
AUTHOR: ${{ github.event.pull_request.user.login }}
TRIGGER_LABEL: ${{ github.event.label.name }}
run: |
git config user.name "connectorio-ci[bot]"
git config user.email "ci@connectorio.com"
# On 'labeled' events process only the label that was just added.
# On 'closed' events process all backport-* labels present on the PR.
LABELS=$(printf '%s\n' ${TRIGGER_LABEL:-$LABELS} | sort | tr '\n' ' ')
# Detect whether the merge commit has multiple parents (true merge commit)
# vs. a single parent (squash or rebase merge).
PARENT_COUNT=$(git rev-list --parents -n 1 "$MERGE_SHA" | awk '{print NF-1}')
# Preserve original author for conflict commits (clean cherry-picks keep it automatically).
ORIGINAL_AUTHOR=$(git log -1 --format="%an <%ae>" "$MERGE_SHA")
do_cherry_pick() {
if [ "$PARENT_COUNT" -gt 1 ]; then
git cherry-pick -x -m 1 "$MERGE_SHA"
else
git cherry-pick -x "$MERGE_SHA"
fi
}
for label in $LABELS; do
[[ "$label" =~ ^backport-(.+)$ ]] || continue
TARGET="${BASH_REMATCH[1]}"
BRANCH="backport-pr${PR_NUMBER}-to-${TARGET}"
echo "Backporting #${PR_NUMBER} to ${TARGET}"
git fetch origin "$TARGET"
git checkout -B "$BRANCH" "origin/${TARGET}"
DRAFT="--draft"
BODY=$(printf 'Backport of #%s to `%s`.\n\nConflicts need manual resolution before merging.' "$PR_NUMBER" "$TARGET")
if do_cherry_pick; then
DRAFT=""
BODY=$(printf 'Backport of #%s to `%s`.' "$PR_NUMBER" "$TARGET")
else
git add -A
git commit --author="$ORIGINAL_AUTHOR" -m "conflict: cherry-pick of ${MERGE_SHA:0:7} onto ${TARGET}"
fi
git push origin "$BRANCH"
BACKPORT_URL=$(gh pr create \
--title "[${TARGET}] ${PR_TITLE}" \
--body "$BODY" \
--base "$TARGET" \
--head "$BRANCH" \
--label "bot" \
--assignee "$AUTHOR" \
$DRAFT)
BACKPORT_PR="${BACKPORT_URL##*/}"
if [ -z "$DRAFT" ]; then
gh pr merge "$BACKPORT_PR" --auto --rebase
fi
done