-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
74 lines (69 loc) · 3.25 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: gamma-ci-made-easy
description: Merge your PR directly to the testing branch!
author: Umair Jibran
inputs:
target-branch:
description: 'Branch in which you want to merge the PR, defaults to alpha'
required: false
default: 'alpha'
branding:
icon: 'activity'
color: 'white'
runs:
using: 'composite'
steps:
- id: is-pr
run: |
echo "THIS ACTION SUPPORTS PULL REQUESTS ONLY, for now..."
shell: bash
if: ${{ github.event_name != 'pull_request' }}
- id: merge-branch
run: |
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "GIT REPO NOT FOUND, PLEASE USE \`actions/checkout@latest\`"
exit 1
fi
echo "DECLARING DEFAULT BRANCH"
BRANCH=${{ github.event.repository.default_branch }}
git fetch
if ! git ls-remote --exit-code --heads origin ${{ env.TARGET_BRANCH }} >/dev/null 2>&1; then
echo "CHECKING OUT \`$BRANCH\`"
git checkout $BRANCH
echo "FETCHING LATEST CODE AT \`$BRANCH\`"
git pull origin $BRANCH
echo "CREATING \`${{ env.TARGET_BRANCH }}\`"
git branch ${{ env.TARGET_BRANCH }}
echo "PUSHING \`${{ env.TARGET_BRANCH }}\`"
git push --set-upstream origin ${{ env.TARGET_BRANCH }}
echo "CHECKING OUT \`${{ env.TARGET_BRANCH }}\`"
git checkout ${{ env.TARGET_BRANCH }}
else
echo "CHECKING OUT \`${{ env.TARGET_BRANCH }}\`"
git checkout -b ${{ env.TARGET_BRANCH }} origin/${{ env.TARGET_BRANCH }}
fi
echo "PULLING CHANGES IF ANY"
git pull origin ${{ env.TARGET_BRANCH }}
echo "SETTING GITHUB-ACTION BOT CONFIG"
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
echo "MERGING PR IN \`${{ env.TARGET_BRANCH }}\`"
git merge --no-ff origin/${{ github.event.pull_request.head.ref }} -m "Merge pull request into ${{ env.TARGET_BRANCH }}"
echo "PUSHING CHANGES TO ${{ env.TARGET_BRANCH }}"
git push origin ${{ env.TARGET_BRANCH }}
shell: bash
if: ${{ github.event_name == 'pull_request' && ( github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' ) }}
env:
TARGET_BRANCH: ${{ inputs.target-branch }}
- id: leave-comment
run: |
echo "EXTRACTING PR NUMBER"
PR_NUMBER=$(echo "${{ github.event.pull_request.url }}" | awk -F'/' '{print $NF}')
echo "CREATING COMMENT BODY AND API URL"
COMMENT="PR #$PR_NUMBER has been merged successfully in [${{ env.TARGET_BRANCH }}](https://github.com/${{ github.repository }}/tree/${{ env.TARGET_BRANCH }}) by [Gamma](https://gamma.solenova.tech). Thanks to @${{ github.actor }} who contributed the last commit.\n\nLet's celebrate this milestone and get ready for the next one!"
API_URL="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
echo "POSTING COMMENT ON PR"
curl -X POST -H "Authorization: Bearer ${{ github.token }}" -d "{\"body\":\"$COMMENT\"}" $API_URL
shell: bash
if: ${{ steps.merge-branch.outcome == 'success' }}
env:
TARGET_BRANCH: ${{ inputs.target-branch }}