-
Notifications
You must be signed in to change notification settings - Fork 2.5k
121 lines (105 loc) · 3.97 KB
/
setup-workflows.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Setup and update common workflows
on:
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
inputs:
config:
description: 'Config'
required: false
default: ''
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout default branch
# https://github.com/marketplace/actions/checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.GH_WORKFLOWS_TOKEN }}
- name: Read config
run: |
CONFIG='{}'
if [[ ! -z '${{ github.event.inputs.config }}' ]]; then
CONFIG='${{ github.event.inputs.config }}'
elif [[ -f "./.github/workflows-config.json" ]]; then
CONFIG=$( jq -c .setupWorkflows './.github/workflows-config.json' )
fi
echo "CONFIG=$CONFIG" >> $GITHUB_ENV
echo "Workflow config: $CONFIG"
- name: Process config
run: |
AS_PR=$(echo '${{ env.CONFIG }}' | jq -r ".pushAsPullRequest")
if [[ "$AS_PR" == "true" ]]; then
echo "AS_PR=1" >> $GITHUB_ENV
else
echo "AS_PR=0" >> $GITHUB_ENV
fi
BRANCH_SOURCE=$(git rev-parse --abbrev-ref HEAD)
if [[ "$AS_PR" == "true" ]]; then
BRANCH_SOURCE="t/setup-workflows-update_$BRANCH_SOURCE"
fi
echo "BRANCH_SOURCE=$BRANCH_SOURCE" >> $GITHUB_ENV
- name: Check if update branch already exists
if: env.AS_PR == 1
run: |
if [[ $(git ls-remote --heads | grep ${{ env.BRANCH_SOURCE }} | wc -c) -ne 0 ]]; then
echo "SHOULD_CANCEL=1" >> $GITHUB_ENV
fi
- name: Cancel build if update branch already exists
if: env.SHOULD_CANCEL == 1
# https://github.com/marketplace/actions/cancel-this-build
uses: andymckay/cancel-action@0.2
- name: Wait for cancellation
if: env.SHOULD_CANCEL == 1
# https://github.com/marketplace/actions/wait-sleep
uses: jakejarvis/wait-action@master
with:
time: '60s'
- name: Checkout common workflows repository
# https://github.com/marketplace/actions/checkout
uses: actions/checkout@v2
with:
path: ckeditor4-workflows-common
repository: ckeditor/ckeditor4-workflows-common
ref: master
- name: Setup workflows directory
run: |
mkdir -p .github/workflows
- name: Synchronize workflow files
run: |
rsync -a --include='*/' --include='*.yml' --exclude='*' ./ckeditor4-workflows-common/workflows/ ./.github/workflows/
if [[ $(git status ./.github/workflows/ --porcelain) ]]; then
echo "HAS_CHANGES=1" >> $GITHUB_ENV
fi
- name: Cleanup common workflows artifacts
run: |
rm -rf ckeditor4-workflows-common
- name: Checkout PR branch
if: env.HAS_CHANGES == 1
run: |
git checkout -b "t/${{ env.BRANCH_SOURCE }}"
- name: Add changes
if: env.HAS_CHANGES == 1
run: |
git config --local user.email "${{ secrets.GH_BOT_EMAIL }}"
git config --local user.name "${{ secrets.GH_BOT_USERNAME }}"
git add .github/workflows
git commit -m "Update common workflows."
- name: Push changes
if: env.HAS_CHANGES == 1
# https://github.com/marketplace/actions/github-push
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_WORKFLOWS_TOKEN }}
branch: ${{ env.BRANCH_SOURCE }}
- name: Create PR
if: env.HAS_CHANGES == 1 && env.AS_PR == 1
# https://github.com/marketplace/actions/github-pull-request-action
uses: repo-sync/pull-request@v2
with:
source_branch: "${{ env.BRANCH_SOURCE }}"
destination_branch: "${{ github.ref }}"
pr_title: "Update 'setup-workflows' workflow"
pr_body: "Update 'setup-workflows' workflow."
github_token: ${{ secrets.GITHUB_TOKEN }}