Trigger Production Deploy Squash #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | | |
| # 1) Merge (squash) everything from origin/master, preferring "theirs" on conflict | |
| git merge --squash origin/master -Xtheirs | |
| # 2) Find the last "Production Deploy" commit in prod history | |
| # We'll grep its message for the final hash. | |
| # Example commit message line: | |
| # "Production Deploy: 8 commits (abc1234 → def5678)" | |
| # So let's grab the second hash: "def5678" | |
| last_squash_commit=$(git log origin/prod --grep="Production Deploy:" -1 --pretty=format:"%B" \ | |
| | grep -oE '[0-9a-f]{7,40}' \ | |
| | tail -n1) | |
| if [ -n "$last_squash_commit" ]; then | |
| # We found a previous deploy | |
| 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) | |
| else | |
| # No previous deploy found, so deploy everything in master | |
| commit_count=$(git rev-list origin/master --count) | |
| first_commit=$(git rev-list origin/master | tail -n1 | cut -c1-7) | |
| fi | |
| # 3) Grab the very last commit in master (short) | |
| last_commit=$(git rev-list origin/master | head -n1 | cut -c1-7) | |
| # 4) Build the commit message | |
| { | |
| echo "Production Deploy: $commit_count commits ($first_commit → $last_commit)" | |
| echo | |
| echo "Included commits:" | |
| # Show the list of commits from HEAD..origin/master | |
| git log HEAD..origin/master --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 |