generated from RedHatInsights/frontend-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 16
79 lines (70 loc) · 2.57 KB
/
sync_branches.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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: Validate source and target refs
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
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.FE_RELEASE_TOKEN }}
ref: ${{ (github.event.inputs.target == 'production' && github.event.inputs.source) || 'main' }}
fetch-depth: 0
- name: Release to production
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'production' }}
run: |
git push https://${GITHUB_ACTOR}:${{ secrets.FE_RELEASE_TOKEN }}@github.com/${{ github.repository }}.git HEAD:prod-beta
- name: Sync main to stage-stable
if: ${{ github.event_name == 'push' || github.event.inputs.target == 'stage-stable' }}
run:
git push https://${GITHUB_ACTOR}:${{ secrets.FE_RELEASE_TOKEN }}@github.com/${{ github.repository }}.git HEAD:stage-stable