Skip to content

Commit 54897f3

Browse files
committed
(chore) Add auto-update for OpenMRS dependencies
1 parent 2042bef commit 54897f3

4 files changed

Lines changed: 261 additions & 1150 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Setup Node.js
2424
uses: actions/setup-node@v4
2525
with:
26-
node-version: '18'
26+
node-version: "20"
2727

2828
- name: Cache dependencies
2929
id: cache
@@ -59,13 +59,14 @@ jobs:
5959
pre_release:
6060
runs-on: ubuntu-latest
6161
needs: build
62-
if: ${{ github.event_name == 'push' }}
62+
if: ${{ github.event_name == 'push' }} && github.repository_owner == 'openmrs'
63+
6364
steps:
6465
- uses: actions/checkout@v4
6566
- name: 🛠️ Setup Node.js
6667
uses: actions/setup-node@v4
6768
with:
68-
node-version: "18"
69+
node-version: "20"
6970

7071
- name: 💾 Cache dependencies
7172
id: cache
@@ -108,10 +109,8 @@ jobs:
108109

109110
release:
110111
runs-on: ubuntu-latest
111-
112112
needs: build
113-
114-
if: ${{ github.event_name == 'release' }}
113+
if: ${{ github.event_name == 'release' }} && github.repository_owner == 'openmrs'
115114

116115
steps:
117116
- uses: actions/checkout@v4
@@ -120,7 +119,7 @@ jobs:
120119
- name: 🛠️ Use Node.js
121120
uses: actions/setup-node@v4
122121
with:
123-
node-version: "18"
122+
node-version: "20"
124123

125124
- name: 💾 Cache dependencies
126125
id: cache
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
on:
2+
workflow_dispatch:
3+
schedule:
4+
# every hour
5+
- cron: '30 * * * *'
6+
7+
name: 'Check for OpenMRS Dependency Updates'
8+
9+
jobs:
10+
check-for-updates:
11+
name: Check for updates to OpenMRS libraries
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
if: github.repository_owner == 'openmrs'
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: 🟢 Use Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 20
24+
- name: 💾 Cache dependencies
25+
id: cache
26+
uses: actions/cache@v4
27+
with:
28+
path: '**/node_modules'
29+
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
30+
- name: 📦 Install dependencies
31+
if: steps.cache.outputs.cache-hit != 'true'
32+
run: yarn install --immutable
33+
- name: ✅ Check for updates
34+
run: node ./tools/update-openmrs-deps.mjs
35+
- name: ⬆️ Create PR if necessary
36+
id: cpr
37+
uses: peter-evans/create-pull-request@v7
38+
with:
39+
commit-message: '(chore) Update OpenMRS dependencies'
40+
title: '(chore) Update OpenMRS dependencies'
41+
body: |
42+
Update OpenMRS dependencies
43+
branch: 'chore/update-openmrs-deps'
44+
author: 'OpenMRS Bot <infrastructure@openmrs.org>'
45+
token: ${{ secrets.OMRS_BOT_GH_TOKEN }}
46+
- name: ✅ Auto approve PR
47+
if: steps.cpr.outputs.pull-request-operation == 'created' || steps.cpr.outputs.pull-request-operation == 'updated'
48+
run: gh pr review --approve "${{ steps.cpr.outputs.pull-request-number }}"
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
- name: 🔀 Automerge PR
52+
if: steps.cpr.outputs.pull-request-operation == 'created' || steps.cpr.outputs.pull-request-operation == 'updated'
53+
run: gh pr merge --auto --squash "${{ steps.cpr.outputs.pull-request-number }}"
54+
env:
55+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tools/update-openmrs-deps.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { execSync } from 'node:child_process';
2+
3+
try {
4+
// NB for other places use '@openmrs/*@next'; here we want to ignore patient-common-lib
5+
execSync(`yarn up --fixed '@openmrs/*@next' 'openmrs@next'`, {
6+
stdio: ['ignore', 'inherit', 'inherit'],
7+
windowsHide: true,
8+
});
9+
} catch (error) {
10+
console.error(`Error while updating dependencies: ${error.message ?? error}`);
11+
process.exit(1);
12+
}
13+
14+
try {
15+
execSync(`yarn dedupe`, {
16+
stdio: ['ignore', 'inherit', 'inherit'],
17+
windowsHide: true,
18+
});
19+
} catch (error) {
20+
console.error(`Error while deduplicating dependencies: ${error.message ?? error}`);
21+
process.exit(1);
22+
}
23+
24+
try {
25+
execSync(`git diff-index --quiet HEAD --`, {
26+
stdio: 'ignore',
27+
windowsHide: true,
28+
});
29+
process.exit(0);
30+
} catch (error) {
31+
// git diff-index --quite HEAD --
32+
// exits with status 1 if there are changes; we only need to run yarn verify if there are changes
33+
}
34+
35+
try {
36+
execSync(`yarn verify`, {
37+
stdio: ['ignore', 'inherit', 'inherit'],
38+
windowsHide: true,
39+
});
40+
} catch (error) {
41+
console.error(`Error while running yarn verify: ${error.message ?? error}. Updates require manual intervention.`);
42+
process.exit(1);
43+
}

0 commit comments

Comments
 (0)