Skip to content

Commit dfdb9e5

Browse files
Adding CI (#1)
1 parent ae1d982 commit dfdb9e5

File tree

4 files changed

+398
-0
lines changed

4 files changed

+398
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @tetherto/miningos-bk-merge
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: 'Node Restore Cache'
2+
description: 'Restore Node.js dependencies from cache'
3+
4+
inputs:
5+
cache-key:
6+
description: 'Cache key from setup-node step'
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
# Restore-only: avoids "another job may be creating this cache" when setup and downstream jobs race on save
13+
- name: Restore node modules cache
14+
id: cache-node-modules
15+
uses: actions/cache/restore@v4
16+
with:
17+
path: node_modules
18+
key: ${{ inputs.cache-key }}
19+
restore-keys: |
20+
node-modules-${{ runner.os }}-20.x-
21+
22+
- name: Setup Node.js
23+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
24+
uses: actions/setup-node@v6
25+
with:
26+
node-version: '20.x'
27+
28+
- name: Install Dependencies
29+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
30+
shell: bash
31+
run: |
32+
if [ -f package-lock.json ]; then
33+
npm ci
34+
else
35+
npm install
36+
fi
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: 'Node.js Setup with Cache'
2+
description: 'Sets up Node.js with dependency caching for the initial setup job'
3+
author: 'miningos-devops'
4+
5+
inputs:
6+
node-version:
7+
description: 'Node.js version to use'
8+
required: false
9+
default: '20.x'
10+
install-dependencies:
11+
description: 'Whether to install dependencies on cache miss'
12+
required: false
13+
default: 'true'
14+
additional-packages:
15+
description: 'Additional system packages to install (space-separated)'
16+
required: false
17+
default: ''
18+
19+
outputs:
20+
cache-key:
21+
description: 'The generated cache key for node_modules'
22+
value: ${{ steps.cache-keys.outputs.cache-key }}
23+
cache-hit:
24+
description: 'Whether the cache was hit'
25+
value: ${{ steps.cache-node-modules.outputs.cache-hit }}
26+
27+
runs:
28+
using: composite
29+
steps:
30+
- name: Generate cache keys
31+
id: cache-keys
32+
shell: bash
33+
run: |
34+
NODE_VERSION="${{ inputs.node-version }}"
35+
BASE_KEY="node-modules-${{ runner.os }}-${NODE_VERSION}"
36+
# Stable key per deps so downstream jobs and future runs get cache hits
37+
HASH_KEY="${BASE_KEY}-${{ hashFiles('package-lock.json', 'package.json') }}"
38+
echo "cache-key=${HASH_KEY}" >> $GITHUB_OUTPUT
39+
echo "base-key=${BASE_KEY}" >> $GITHUB_OUTPUT
40+
41+
- name: Setup Node.js
42+
uses: actions/setup-node@v6
43+
with:
44+
node-version: ${{ inputs.node-version }}
45+
46+
- name: Install additional system packages
47+
if: inputs.additional-packages != ''
48+
shell: bash
49+
run: |
50+
echo "Installing additional packages: ${{ inputs.additional-packages }}"
51+
sudo apt update
52+
sudo apt install -y ${{ inputs.additional-packages }}
53+
54+
- name: Install dependencies
55+
if: inputs.install-dependencies == 'true'
56+
shell: bash
57+
run: |
58+
if [ -f package-lock.json ]; then
59+
echo "Found package-lock.json, using npm ci for deterministic installs"
60+
npm ci
61+
else
62+
echo "No package-lock.json found, using npm install"
63+
npm install
64+
fi
65+
66+
- name: Cache node modules
67+
id: cache-node-modules
68+
uses: actions/cache@v4
69+
with:
70+
path: node_modules
71+
key: ${{ steps.cache-keys.outputs.cache-key }}
72+
restore-keys: |
73+
${{ steps.cache-keys.outputs.base-key }}-

0 commit comments

Comments
 (0)