Skip to content

Commit 308a9f4

Browse files
authored
(chore) Update CI workflow (#98)
This PR updates the main CI workflow for this repo to use Turborepo and cache dependencies. Importantly, it also ensures that the release job includes a build step to ensure that artifacts are built before being uploaded to NPM.
1 parent 9f75eda commit 308a9f4

File tree

1 file changed

+104
-36
lines changed

1 file changed

+104
-36
lines changed

.github/workflows/node.js.yml

Lines changed: 104 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,92 +10,160 @@ on:
1010
- created
1111

1212
env:
13-
ESM_NAME: "@openmrs/esm-cohort-builder-app"
14-
JS_NAME: "openmrs-esm-cohort-builder-app.js"
13+
TURBO_API: 'http://127.0.0.1:9080'
14+
TURBO_TOKEN: 'turbo-token'
15+
TURBO_TEAM: ${{ github.repository_owner }}
1516

1617
jobs:
1718
build:
1819
runs-on: ubuntu-latest
1920

2021
steps:
2122
- uses: actions/checkout@v4
22-
- name: Use Node.js
23+
- name: 🛠️ Setup Node.js
2324
uses: actions/setup-node@v4
2425
with:
25-
node-version: "18.x"
26-
- run: yarn install --immutable
27-
- run: yarn verify
28-
- run: yarn build
29-
- name: Upload Artifacts
30-
uses: actions/upload-artifact@v3
26+
node-version: "18"
27+
28+
- name: 💾 Cache dependencies
29+
id: cache
30+
uses: actions/cache@v4
31+
with:
32+
path: '**/node_modules'
33+
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
34+
35+
- name: 📦 Install dependencies
36+
if: steps.cache.outputs.cache-hit != 'true'
37+
run: yarn install --immutable
38+
39+
- name: 🚀 Setup local cache server for Turborepo
40+
uses: felixmosh/turborepo-gh-artifacts@v3
41+
with:
42+
repo-token: ${{ secrets.GITHUB_TOKEN }}
43+
server-token: ${{ env.TURBO_TOKEN }}
44+
45+
- name: 🧪 Run tests, lint and type checks
46+
run: yarn verify
47+
48+
- name: 🏗️ Run build
49+
run: yarn turbo run build
50+
51+
- name: 📤 Upload Artifacts
52+
uses: actions/upload-artifact@v4
3153
with:
3254
name: dist
3355
path: |
3456
dist
57+
overwrite: true
3558

3659
pre_release:
3760
runs-on: ubuntu-latest
38-
3961
needs: build
40-
4162
if: ${{ github.event_name == 'push' }}
4263

4364
steps:
44-
- run: echo "Uncomment the lines below and delete this one."
4565
- uses: actions/checkout@v4
46-
- name: Download Artifacts
47-
uses: actions/download-artifact@v4
48-
- name: Use Node.js
66+
- name: 🛠️ Setup Node.js
4967
uses: actions/setup-node@v4
5068
with:
51-
node-version: "18.x"
52-
registry-url: "https://registry.npmjs.org"
53-
- run: yarn install --immutable
54-
- run: yarn version "$(node -e "console.log(require('semver').inc(require('./package.json').version, 'patch'))")-pre.${{ github.run_number }}"
55-
- run: yarn build
56-
- run: git config user.email "info@openmrs.org" && git config user.name "OpenMRS CI"
57-
- run: git add . && git commit -m "Prerelease version" --no-verify
58-
- run: yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" && yarn npm publish --access public --tag next
69+
node-version: "18"
70+
71+
- name: 💾 Cache dependencies
72+
id: cache
73+
uses: actions/cache@v4
74+
with:
75+
path: '**/node_modules'
76+
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
77+
78+
- name: 📦 Install dependencies
79+
if: steps.cache.outputs.cache-hit != 'true'
80+
run: yarn install --immutable
81+
82+
- name: 🚀 Setup local cache server for Turborepo
83+
uses: felixmosh/turborepo-gh-artifacts@v3
84+
with:
85+
repo-token: ${{ secrets.GITHUB_TOKEN }}
86+
server-token: ${{ env.TURBO_TOKEN }}
87+
88+
- name: 🏷️ Version
89+
run: yarn version "$(node -e "console.log(require('semver').inc(require('./package.json').version, 'patch'))")-pre.${{ github.run_number }}"
90+
91+
- name: 🏗️ Build
92+
run: yarn turbo run build
93+
94+
- name: 🔧 Configure Git
95+
run: git config user.email "info@openmrs.org" && git config user.name "OpenMRS CI"
96+
- name: 💾 Commit changes
97+
run: git add . && git commit -m "Prerelease version" --no-verify
98+
99+
- name: 🚀 Pre-release
100+
run: yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" && yarn npm publish --access public --tag next
59101
env:
60102
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
61-
- name: Upload Artifacts
62-
uses: actions/upload-artifact@v3
103+
- name: 📤 Upload Artifacts
104+
uses: actions/upload-artifact@v4
63105
with:
64106
name: dist
65107
path: |
66108
dist
109+
overwrite: true
67110

68111
release:
69112
runs-on: ubuntu-latest
70-
71113
needs: build
72-
73114
if: ${{ github.event_name == 'release' }}
74115

75116
steps:
76117
- uses: actions/checkout@v4
77-
- name: Download Artifacts
118+
- name: 📥 Download Artifacts
78119
uses: actions/download-artifact@v4
79-
- name: Use Node.js
120+
- name: 🛠️ Use Node.js
80121
uses: actions/setup-node@v4
81122
with:
82-
node-version: "18.x"
123+
node-version: "18"
83124
registry-url: 'https://registry.npmjs.org'
84-
- run: yarn install --immutable
85-
- run: yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" && yarn npm publish --access public
125+
126+
- name: 💾 Cache dependencies
127+
id: cache
128+
uses: actions/cache@v4
129+
with:
130+
path: '**/node_modules'
131+
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
132+
133+
- name: 📦 Install dependencies
134+
if: steps.cache.outputs.cache-hit != 'true'
135+
run: yarn install --immutable
136+
137+
- name: 🚀 Setup local cache server for Turborepo
138+
uses: felixmosh/turborepo-gh-artifacts@v3
139+
with:
140+
repo-token: ${{ secrets.GITHUB_TOKEN }}
141+
server-token: ${{ env.TURBO_TOKEN }}
142+
143+
- name: 🏗️ Build
144+
run: yarn turbo run build
145+
146+
- name: 🚀 Publish to NPM
147+
run: yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" && yarn npm publish --access public
86148
env:
87149
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
88150

151+
- name: 📤 Upload Artifacts
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: dist
155+
path: |
156+
dist
157+
overwrite: true
158+
89159
deploy:
90160
runs-on: ubuntu-latest
91-
92161
needs: pre_release
93-
94162
if: ${{ github.event_name == 'push' }}
95163

96164
steps:
97-
- name: Trigger RefApp Build
98-
uses: fjogeleit/http-request-action@master
165+
- name: 🚀 Trigger RefApp Build
166+
uses: fjogeleit/http-request-action@v1
99167
with:
100168
url: https://ci.openmrs.org/rest/api/latest/queue/O3-BF
101169
method: "POST"

0 commit comments

Comments
 (0)