-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (50 loc) · 1.95 KB
/
some-test-deploy-squash.yml
File metadata and controls
64 lines (50 loc) · 1.95 KB
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
name: Trigger Production Deploy Squash
on:
workflow_dispatch:
jobs:
merge-master-to-prod:
name: Squash Master into Prod
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Checkout prod branch
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: prod
token: ${{ secrets.SECRET }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch master branch
run: git fetch origin master
- name: Squash changes from master into prod
run: |
git merge --squash origin/master -Xtheirs
last_squash_commit=$(git log origin/prod --grep="Production Deploy:" -1 --pretty=format:"%B" \
| grep -oP '(?<=→ )\b[0-9a-f]{7,40}\b' \
| head -n1)
if [ -n "$last_squash_commit" ]; then
commit_count=$(git rev-list "$last_squash_commit"..origin/master --count)
first_commit=$(git rev-list "$last_squash_commit"..origin/master | tail -n1 | cut -c1-7)
commit_range="$last_squash_commit..origin/master"
else
commit_count=$(git rev-list origin/master --count)
first_commit=$(git rev-list origin/master | tail -n1 | cut -c1-7)
commit_range="origin/master"
fi
last_commit=$(git rev-list origin/master | head -n1 | cut -c1-7)
{
echo "Production Deploy: $commit_count commits ($first_commit → $last_commit)"
echo
echo "Included commits:"
git log "$commit_range" --pretty=format:"- %h %s"
} > /tmp/commitmsg
# 5) Create the single squash commit
git commit -F /tmp/commitmsg
- name: Push new squash commit to prod
run: |
git push origin prod --force-with-lease