Skip to content

Trigger Production Deploy Squash #5

Trigger Production Deploy Squash

Trigger Production Deploy Squash #5

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: |
# Merge (squash) everything from origin/master,
# preferring "theirs" on conflict
git merge --squash origin/master -Xtheirs
# Gather commit info for HEAD..origin/master
commit_count=$(git rev-list HEAD..origin/master --count)
first_commit=$(git log HEAD..origin/master --reverse --pretty=format:"%h" | head -n 1)
last_commit=$(git log HEAD..origin/master --pretty=format:"%h" | head -n 1)
# Start the commit message
{
echo "Production Deploy"
echo "Total commits included: $commit_count"
echo "From $first_commit to $last_commit"
echo
echo "Included commits:"
git log HEAD..origin/master --pretty=format:"- %h %s"
} > /tmp/commitmsg
# 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