This repository has been archived by the owner on Jun 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
124 lines (108 loc) · 4.22 KB
/
update-js-deps.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
name: js-upgrade
on:
workflow_call:
jobs:
js-upgrade:
name: 'JS upgrade'
runs-on: ubuntu-latest
env:
pr_title: DEP Update JS dependencies
pr_desc: Automated yarn upgrade and yarn build
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Read .nvmrc
run: echo ::set-output name=version::$(cat .nvmrc)
id: read-nvm
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ steps.read-nvm.outputs.version }}
- name: Install yarn
run: npm install --global yarn
- name: Install admin JS
if: github.event.repository.name != 'silverstripe-admin'
run: |
# Install admin js in sibling directory so shared components are available
DIR=$(pwd)
cd ..
git clone https://github.com/silverstripe/silverstripe-admin.git admin
cd admin
git checkout 1
yarn install
cd $DIR
# Use `yarn install` rather than `yarn upgrade` to prevent the following error:
# "error Outdated lockfile. Please run `yarn install` and try again."
- name: Update yarn.lock
run: |
if [ -f yarn.lock ]; then rm yarn.lock; fi
yarn install
- name: Read package.json
id: package-json
run: |
# Read package.json to see if lint and test are runnable scripts
LINT=0
TEST=0
if [ "$(jq .scripts.lint? package.json)" != "null" ]; then LINT=1; fi
if [ "$(jq .scripts.test? package.json)" != "null" ]; then TEST=1; fi
echo "::set-output name=lint::$LINT"
echo "::set-output name=test::$TEST"
echo "LINT is $LINT"
echo "TEST is $TEST"
# The following 3 steps make up `yarn build`
# Splitting apart to make it easier to see where any failures originate from
- name: Yarn lint
if: steps.package-json.outputs.lint == 1
run: yarn lint
- name: Yarn test
if: steps.package-json.outputs.test == 1
run: yarn test
- name: Build JS with webpack
# always run this and subsequent steps even if yarn.lint/yarn.test fails so that pull-request is
# created which will result in a red pull-request build so it's easy to see where things are at
if: always()
run: NODE_ENV=production node_modules/webpack/bin/webpack.js -p --bail --progress
- name: Remove any old pull-requests
if: always()
run: |
JSON=$(curl https://api.github.com/repos/${{ github.repository }}/pulls)
NUMBERS=$(echo $JSON | jq '.[] | select(.title=="${{ env.pr_title }}" and .user.login=="github-actions[bot]") | .number')
for NUMBER in $NUMBERS; do
curl -s \
-X PATCH https://api.github.com/repos/${{ github.repository }}/pulls/$NUMBER \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d @- << EOF
{
"state": "closed"
}
EOF
echo "Closed old pull-request $NUMBER"
done
- name: Remove any old branches
if: always()
run: |
JSON=$(curl https://api.github.com/repos/${{ github.repository }}/branches)
BRANCHES=$(echo $JSON | jq -r '.[] | .name | select(.|test("^pulls\/[0-9]\/update-js-[0-9]{10}$"))')
for BRANCH in $BRANCHES; do
if [[ "$BRANCH" =~ ^pulls/[0-9\.]+/update\-js\-[0-9]+$ ]]; then
git push origin --delete "$BRANCH"
echo "Deleted old branch $BRANCH"
fi
done
- name: Generate branch name
if: always()
id: generate-branch-name
run: |
# Convert refs/heads/mybranch to mybranch
CUT=$(echo ${{ github.ref }} | cut -c 12-)
# e.g. pulls/1/update-js-1647810133
BRANCH=pulls/$CUT/update-js-$(date +%s)
echo ::set-output name=branch::$BRANCH
- name: Git
if: always()
uses: emteknetnz/gha-pull-request@main
with:
branch: ${{ steps.generate-branch-name.outputs.branch }}
title: ${{ env.pr_title }}
description: ${{ env.pr_desc }}