@@ -12,19 +12,20 @@ permissions:
1212jobs :
1313 auto-approve-merge :
1414 runs-on : ubuntu-latest
15- if : (github.actor == 'dependabot[bot]' || github.actor == 'renovate[bot]') && github.repository == 'internetee/registry'
1615 steps :
1716 - name : Checkout repository
17+ if : github.repository == 'internetee/registry'
1818 uses : actions/checkout@v5
1919
2020 - name : Install GitHub CLI
2121 run : |
22- curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
23- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
24- sudo apt update
25- sudo apt install gh
22+ sudo apt-get update
23+ sudo apt-get install -y gh
2624
2725 - name : Auto approve PR
26+ if : |
27+ github.actor == 'dependabot[bot]' ||
28+ github.actor == 'renovate[bot]'
2829 uses : hmarr/auto-approve-action@v3
2930 with :
3031 github-token : ${{ secrets.GITHUB_TOKEN }}
@@ -39,29 +40,36 @@ jobs:
3940 - name : Check if PR should be auto-merged
4041 id : check_auto_merge
4142 run : |
43+ # Set default UPDATE_TYPE to avoid unbound variable errors
44+ UPDATE_TYPE="${{ steps.metadata.outputs.update-type || 'unknown' }}"
45+
4246 if [ "${{ github.actor }}" == "dependabot[bot]" ]; then
43- if [[ "${{ steps.metadata.outputs.update-type }} " == "version-update:semver-patch" ]]; then
47+ if [[ "$UPDATE_TYPE " == "version-update:semver-patch" ]]; then
4448 echo "auto_merge=true" >> $GITHUB_OUTPUT
49+ echo "update_type=${UPDATE_TYPE}" >> $GITHUB_OUTPUT
4550 echo "Auto-merge: Dependabot patch update detected"
4651 else
4752 echo "auto_merge=false" >> $GITHUB_OUTPUT
53+ echo "update_type=${UPDATE_TYPE}" >> $GITHUB_OUTPUT
4854 echo "Auto-merge: Dependabot non-patch update, skipping"
4955 fi
5056 elif [ "${{ github.actor }}" == "renovate[bot]" ]; then
51- # Check if PR has patch label (set by renovate.json configuration)
52- # Extract label names from the labels array
53- LABEL_NAMES=$(echo '${{ toJson(github.event.pull_request.labels) }}' | jq -r '.[].name' | tr '\n' ' ')
54- if [[ "$LABEL_NAMES" == *"patch"* ]] || [[ "$LABEL_NAMES" == *"bundler"* ]] || [[ "$LABEL_NAMES" == *"ruby-version"* ]] || [[ "$LABEL_NAMES" == *"github-actions"* ]]; then
57+ # Check if the PR has the 'patch' label but NOT 'minor' or 'major' labels
58+ LABELS=$(gh pr view ${{ github.event.pull_request.number }} --json labels -q '.labels[].name' | tr '\n' ' ')
59+ if [[ "$LABELS" == *"patch"* ]] && [[ "$LABELS" != *"minor"* ]] && [[ "$LABELS" != *"major"* ]]; then
5560 echo "auto_merge=true" >> $GITHUB_OUTPUT
56- echo "Auto-merge: Renovate patch update detected (label-based): $LABEL_NAMES"
61+ echo "update_type=renovate- patch-only" >> $GITHUB_OUTPUT
5762 else
5863 echo "auto_merge=false" >> $GITHUB_OUTPUT
59- echo "Auto-merge: Renovate non-patch update, skipping. Labels: $LABEL_NAMES"
64+ echo "update_type=renovate- non-patch-or-mixed" >> $GITHUB_OUTPUT
6065 fi
6166 else
6267 echo "auto_merge=false" >> $GITHUB_OUTPUT
68+ echo "update_type=${UPDATE_TYPE}" >> $GITHUB_OUTPUT
6369 echo "Auto-merge: Unknown actor, skipping"
6470 fi
71+ env :
72+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6573 shell : bash
6674
6775 - name : Wait for CI checks
8290 }
8391 env :
8492 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
85-
86- - name : Send Mattermost notification
87- if : steps.check_auto_merge.outputs.auto_merge == 'true'
88- run : |
89- TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M UTC")
90- curl -X POST -H "Authorization: Bearer ${{ secrets.MATTERMOST_BOT_TOKEN }}" \
91- -H "Content-Type: application/json" \
92- -d "{\"channel_id\":\"${{ secrets.MATTERMOST_CHANNEL_ID }}\",\"message\":\"[${{ github.repository }}] PR #${{ github.event.pull_request.number }}: \\\"${{ github.event.pull_request.title }}\\\" was auto-merged by ${{ github.actor }}.\nUpdate type: ${{ steps.metadata.outputs.update-type || 'patch' }}\nMerged at: $TIMESTAMP\nLink: ${{ github.event.pull_request.html_url }}\"}" \
93- https://mattermost.example.com/api/v4/posts
9493
0 commit comments