Skip to content

Merge pull request #17390 from juju/increment-to-3.3.6 #841

Merge pull request #17390 from juju/increment-to-3.3.6

Merge pull request #17390 from juju/increment-to-3.3.6 #841

Workflow file for this run

name: Merge
on:
push:
branches: ['2.9', '3.1', '3.3', '3.4']
jobs:
check-merge:
name: Check for conflicts
runs-on: ubuntu-latest
env:
MERGE_TARGETS: |
2.9: 3.1
3.1: 3.3
3.3: 3.4
3.4: main
steps:
- name: Determine source/target branches
id: branch
run: |
set -x
SOURCE_BRANCH=${{ github.ref_name }}
echo "source=$SOURCE_BRANCH" >> "$GITHUB_OUTPUT"
TARGET_BRANCH=$(echo "$MERGE_TARGETS" | yq ".\"$SOURCE_BRANCH\"")
echo "target=$TARGET_BRANCH" >> "$GITHUB_OUTPUT"
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ steps.branch.outputs.source }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: false
# We need to do this before trying to merge, because if the merge
# creates conflicts in go.mod, we won't be able to use the go command.
- name: Pre-compile try-merge script
run: |
go install ./scripts/try-merge
- name: Attempt to merge
id: merge
env:
SOURCE_BRANCH: ${{ steps.branch.outputs.source }}
TARGET_BRANCH: ${{ steps.branch.outputs.target }}
run: |
set -x
git fetch origin "$TARGET_BRANCH"
git branch "$TARGET_BRANCH" "origin/$TARGET_BRANCH"
# Need to set Git username/email to do the merge (yawn)
git config user.name 'jujubot'
git config user.email '[email protected]'
set +e
git switch "$TARGET_BRANCH"
git merge "$SOURCE_BRANCH"
case $? in
0)
echo "conflicts=false" >> "$GITHUB_OUTPUT"
;;
1)
echo "conflicts=true" >> "$GITHUB_OUTPUT"
;;
*)
exit $?
;;
esac
- name: Generate notification message
if: steps.merge.outputs.conflicts == 'true'
id: message
env:
SOURCE_BRANCH: ${{ steps.branch.outputs.source }}
TARGET_BRANCH: ${{ steps.branch.outputs.target }}
EMAIL_TO_MM_USER: ${{ secrets.EMAIL_TO_MM_USER }}
IGNORE_EMAILS: ${{ secrets.MERGE_NOTIFY_IGNORE_EMAILS }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
MESSAGE=$(try-merge errmsg)
echo "message=$MESSAGE" >> "$GITHUB_OUTPUT"
- name: Notify if merge has conflicts
if: steps.merge.outputs.conflicts == 'true' && steps.message.outputs.message != ''
env:
MM_TOKEN: ${{ secrets.MM_TOKEN }}
MESSAGE: ${{ steps.message.outputs.message }}
run: |
# install mmctl
curl https://github.com/mattermost/mmctl/releases/download/v7.8.5/linux_amd64.tar -Lo mmctl.tar
tar -xvf mmctl.tar
./mmctl auth login 'https://chat.charmhub.io' --name Charmhub --access-token $MM_TOKEN
./mmctl post create Charmhub:juju-bot --message "$MESSAGE"