Skip to content

Auto release PR

Auto release PR #20

Workflow file for this run

name: Auto release PR
on:
push:
tags:
- '*'
branches:
- staging
workflow_dispatch:
permissions:
contents: write # to create release
pull-requests: write # to create release PR
jobs:
# from https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md#keep-a-branch-up-to-date-with-another
deploy-staging:
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.SGTPOOKI_PAT }}
ref: staging
- name: Fetch all tags
run: git fetch --tags
- name: Get latest tag
id: get_latest_tag
run: echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
- name: Ensure staging-release branch points to latest tag
run: |
git reset --hard ${{ steps.get_latest_tag.outputs.tag }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
token: ${{ secrets.SGTPOOKI_PAT }}
base: staging
branch: staging-release
title: 'chore: point staging to release ${{ steps.get_latest_tag.outputs.tag }}'
body: 'This PR points the staging branch to release ${{ steps.get_latest_tag.outputs.tag }}. **Choose "Rebase and merge" for this PR only!**'
# from https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md#keep-a-branch-up-to-date-with-another
deploy-production:
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/staging')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.SGTPOOKI_PAT }}
ref: production
fetch-depth: 0 # Fetch all branches and commit history
- name: Get latest tag deployed to staging
id: get_latest_tag
run: |
latest_tag=$(git --no-pager log origin/staging --all --grep="chore: point staging to release v" --pretty=format:"%H %s" | head -n1 | sed -n 's/.*release \(v[0-9]*\.[0-9]*\.[0-9]*\).*/\1/p')
echo "tag=$latest_tag" >> $GITHUB_OUTPUT
- name: Set production branch to latest tag deployed to staging
run: |
git reset --hard ${{ steps.get_latest_tag.outputs.tag }}
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
token: ${{ secrets.SGTPOOKI_PAT }}
base: production
branch: production-release
title: 'chore: Point production to ${{ steps.get_latest_tag.outputs.tag }}'
body: 'This PR points the production branch to release ${{ steps.get_latest_tag.outputs.tag }}, which is the latest tag deployed to staging. **Choose "Rebase and merge" for this PR only!**'