Trigger Production Deploy Squash #17
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: | | |
| 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 | |
| # 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 | |
| echo everything | |
| # 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 | |
| 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:" | |
| # 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 |