-
Notifications
You must be signed in to change notification settings - Fork 4
150 lines (142 loc) · 4.94 KB
/
update-examples.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Update Edgio Examples
on:
workflow_dispatch:
inputs:
allow-major:
description: 'Allow major version updates'
required: false
default: 'false'
schedule:
- cron: '0 0 * * 0'
concurrency:
group: update-examples-${{ github.ref }}
cancel-in-progress: true
env:
# Node version for all the jobs
NODE_VERSION: 16
# Base branch all jobs will merge into
BRANCH_PREFIX: bot-examples-update-
UPDATES_BRANCH_NAME: bot-examples-update-${{ github.run_number }}
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.setMatrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: https://registry.npmjs.org/
- name: Install Node.js modules
run: npm ci
- name: Cleanup branches; Create branch and push to origin
run: |
# Cleanup existing branches
git pull
git fetch --all
for branch in $(git branch --remotes)
do
git branch -q ${branch#origin/} $branch || true
done
for branch in $(git branch --list "${{ env.BRANCH_PREFIX }}*")
do
git push origin --delete $branch || true
done
# Create new branch
git checkout -b ${{ env.UPDATES_BRANCH_NAME }}
git push origin ${{ env.UPDATES_BRANCH_NAME }}
- name: Get matrix of examples
id: setMatrix
run: echo -e "matrix=$(node scripts/helpers/printV7Examples.js)" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-examples:
name: Update Examples
needs: prepare
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
example: ${{ fromJson( needs.prepare.outputs.matrix ) }}
env:
EXAMPLE_DIR: examples/${{ matrix.example }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.UPDATES_BRANCH_NAME }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: https://registry.npmjs.org/
- name: Install Node.js modules
run: |
npm i -g @edgio/cli
npm ci
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-examples-node-modules-${{ matrix.example }}-node16-v2
with:
path: |
examples/${{ matrix.example }}/node_modules
*/*/node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles(format('examples/{0}/package-lock.json', matrix.test), 'packages/*/package-lock.json') }}
- name: Update Examples
run: npm run update-examples -- --dir ${{ env.EXAMPLE_DIR }} --allowMajor ${{ github.event.inputs.allow-major }}
- name: Check if there are modified files
id: status
run: |
# Check if the git status is clean
if [ -z "$(git status --porcelain)" ]; then
echo "No modified files"
# Set a variable to indicate that there are no modified files
echo "NO_MODIFIED_FILES=true" >> $GITHUB_OUTPUT
else
echo "Modified files"
# Set a variable to indicate that there are modified files
echo "NO_MODIFIED_FILES=false" >> $GITHUB_OUTPUT
fi
- name: Commit changes
if: steps.status.outputs.NO_MODIFIED_FILES == 'false'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git checkout -b ${{ env.BRANCH_NAME }}
git add .
git commit -am "Update ${{ matrix.example }}"
git push origin ${{ env.BRANCH_NAME }}
env:
BRANCH_NAME: ${{ env.UPDATES_BRANCH_NAME }}-${{ matrix.example }}
create-pr:
name: Create Update PR
needs: update-examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.UPDATES_BRANCH_NAME }}
fetch-depth: 0
- name: Prepare branches to merge
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git fetch --all --prune
for branch in $(git branch --remotes)
do
git branch -q ${branch#origin/} $branch || true
done
git pull --all
- name: Merge in updated branches to base branch
run: |
for branch in $(git branch --list "${{ env.UPDATES_BRANCH_NAME }}-*")
do
git merge --allow-unrelated-histories -m "Merging $branch" $branch
done
git push origin ${{ env.UPDATES_BRANCH_NAME }}
- name: Create PR
uses: repo-sync/pull-request@v2
with:
destination_branch: main
source_branch: ${{ env.UPDATES_BRANCH_NAME }}
pr_title: '[BOT] Update Edgio Version'