Skip to content

Commit

Permalink
build: remove uuid and use Node.js built-in crypto.randomUUID, update…
Browse files Browse the repository at this point in the history
… to Node 20
  • Loading branch information
sophiabrandt committed Jun 21, 2024
1 parent cedae20 commit 75289fe
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 121 deletions.
101 changes: 50 additions & 51 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
name: Build Project
on:
push:
branches:
- master
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Pull Repo
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
node-version: '16'
- name: Run Script
shell: bash
run: |
set -x
npm ci # install packages
NODE_OUTPUT=`node scripts/aggregate-json.mjs 2>&1`
if [[ ! $NODE_OUTPUT ]];then
exit 0
fi
NODE_OUTPUT="<pre>${NODE_OUTPUT//$'\n'/<br />}</pre>"
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
if [[ ! $PR_NUMBER ]]; then
exit 0
fi
jq -n --arg body "$(echo $NODE_OUTPUT)" '{ body: $body }' |\
curl -sL -X POST -d @- \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://github.com/gitapi/repos/${{ github.repository }}/commits/$GITHUB_SHA/comments"
- name: Build Project
run: |
CI=false npm run build
- name: Publish
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: build
CLEAN: true
build:
runs-on: ubuntu-latest
steps:
- name: Pull Repo
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
node-version: '20'
- name: Run Script
shell: bash
run: |
set -x
npm ci # install packages
NODE_OUTPUT=`node scripts/aggregate-json.mjs 2>&1`
if [[ ! $NODE_OUTPUT ]];then
exit 0
fi
NODE_OUTPUT="<pre>${NODE_OUTPUT//$'\n'/<br />}</pre>"
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
if [[ ! $PR_NUMBER ]]; then
exit 0
fi
jq -n --arg body "$(echo $NODE_OUTPUT)" '{ body: $body }' |\
curl -sL -X POST -d @- \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://github.com/gitapi/repos/${{ github.repository }}/commits/$GITHUB_SHA/comments"
- name: Build Project
run: |
CI=false npm run build
- name: Publish
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: build
CLEAN: true
60 changes: 30 additions & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
name: Test

on:
pull_request:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16, 18]
steps:
- name: Check out source code
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Use cache
uses: actions/cache@v2
with:
path: |
node_modules
*/*/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20]
steps:
- name: Check out source code
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Use cache
uses: actions/cache@v2
with:
path: |
node_modules
*/*/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.17.1
v20.15.0
18 changes: 0 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"react-scripts": "^5.0.1",
"react-search-input": "^0.11.3",
"tachyons": "^4.12.0",
"uuid": "^9.0.1",
"webfontloader": "^1.6.28"
},
"husky": {
Expand Down Expand Up @@ -66,6 +65,6 @@
"not op_mini all"
],
"volta": {
"node": "18.17.1"
"node": "20.15.0"
}
}
38 changes: 19 additions & 19 deletions scripts/aggregate-json.mjs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import fs from "fs"
import path from "path"
import { v4 as uuidv4 } from "uuid"
import fs from 'fs'
import path from 'path'
import crypto from 'crypto'

const JSON_SOURCE_DIR = "Submissions"
const FINAL_JSON_FILE = "src/assets/persons.json"
const JSON_SOURCE_DIR = 'Submissions'
const FINAL_JSON_FILE = 'src/assets/persons.json'
let dirContent = null
const finalJSON = []

try {
dirContent = fs.readdirSync(path.resolve(JSON_SOURCE_DIR))
dirContent = fs.readdirSync(path.resolve(JSON_SOURCE_DIR))
} catch (e) {
console.log(`error while reading "${JSON_SOURCE_DIR}": ` + e.message)
console.log(`error while reading "${JSON_SOURCE_DIR}": ` + e.message)
}

try {
for (let i = 0; i < dirContent.length; i++) {
const jsonContent__raw = fs.readFileSync(
path.resolve(JSON_SOURCE_DIR, dirContent[i]),
{ encoding: "utf-8" }
)
for (let i = 0; i < dirContent.length; i++) {
const jsonContent__raw = fs.readFileSync(
path.resolve(JSON_SOURCE_DIR, dirContent[i]),
{ encoding: 'utf-8' }
)

const jsonContent__parsed = JSON.parse(jsonContent__raw)
jsonContent__parsed.id = uuidv4()
finalJSON.push(jsonContent__parsed)
}
const jsonContent__parsed = JSON.parse(jsonContent__raw)
jsonContent__parsed.id = crypto.randomUUID()
finalJSON.push(jsonContent__parsed)
}
} catch (e) {
console.log(`error: ` + e.message)
console.log(`error: ` + e.message)
}

fs.writeFileSync(
path.resolve(FINAL_JSON_FILE),
JSON.stringify(finalJSON, null, 2)
path.resolve(FINAL_JSON_FILE),
JSON.stringify(finalJSON, null, 2)
)

0 comments on commit 75289fe

Please sign in to comment.