debian-image-builder-frontend/.github/workflows/sync-branches.yml
2022-04-27 19:48:28 +02:00

81 lines
2.5 KiB
YAML

name: Sync branches
on:
push:
branches:
- main
workflow_dispatch:
inputs:
source:
description: Source ref (branch or sha)
required: true
type: string
target:
description: Target branch
required: true
type: choice
options:
- production
- stage-stable
jobs:
check:
name: Check source and target validity
timeout-minutes: 1
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.source }}
fetch-depth: 0
- name: Check ancestry
if: ${{ github.event.inputs.target == 'production' }}
run: |
if ! git merge-base --is-ancestor ${{ github.event.inputs.source }} origin/main; then
echo "Target is production and source ref isn't an ancestor of main"
exit 1
fi
if ! git merge-base --is-ancestor ${{ github.event.inputs.source }} origin/stage-stable; then
echo "Target is production and source ref isn't deployed in stage-stable"
echo "The main and stage-stable branches should be in sync, please fix"
exit 1
fi
- name: Check stage-stable manual sync
if: ${{ github.event.inputs.target == 'stage-stable' }}
run: |
if [ $(git rev-parse ${{ github.event.inputs.source }}) != $(git rev-parse origin/main) ]; then
echo "Target is stage-stable and source ref isn't main"
exit 1
fi
sync:
name: Sync source and target refs
needs: check
if: ${{ github.event_name == 'push' || success() }}
timeout-minutes: 5
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.SCHUTZBOT_GH_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.source }}
fetch-depth: 0
- name: Release to production
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'production' }}
run: |
git push origin ${{ github.event.inputs.source }}:refs/heads/prod-beta
git push origin ${{ github.event.inputs.source }}:refs/heads/prod-stable
- name: Sync main to stage-stable
if: ${{ github.event_name == 'push' || github.event.inputs.target == 'stage-stable' }}
run: |
git push origin origin/main:refs/heads/stage-stable