From 922c786d0d67819d55fc5ff898e3ca7bf9b2ddb9 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 4 Jun 2024 11:43:17 +0200 Subject: [PATCH 01/10] Introduce `BUFFER` custom codec --- libs/hpc-data/src/lib/util.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/hpc-data/src/lib/util.ts b/libs/hpc-data/src/lib/util.ts index 68d37b40b..908421513 100644 --- a/libs/hpc-data/src/lib/util.ts +++ b/libs/hpc-data/src/lib/util.ts @@ -114,6 +114,13 @@ export const BLOB = new t.Type( t.identity ); +export const BUFFER = new t.Type( + 'Buffer', + (v): v is Buffer => v instanceof Buffer, + (v, c) => (v instanceof Buffer ? t.success(v) : t.failure(v, c)), + t.identity +); + /** * A file Buffer */ From 67fa795d65d7d6467854079a4f664c2f9d160d4c Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 4 Jun 2024 12:17:34 +0200 Subject: [PATCH 02/10] Introduce `STRING_FROM_SINGLE_ELEMENT_ARRAY` custom codec --- libs/hpc-data/src/lib/util.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/hpc-data/src/lib/util.ts b/libs/hpc-data/src/lib/util.ts index 908421513..e13aacaa3 100644 --- a/libs/hpc-data/src/lib/util.ts +++ b/libs/hpc-data/src/lib/util.ts @@ -70,6 +70,19 @@ export const INTEGER_ARRAY_FROM_STRING = new t.Type( t.identity ); +export const STRING_FROM_SINGLE_ELEMENT_ARRAY = new t.Type( + 'STRING_FROM_SINGLE_ELEMENT_ARRAY', + t.string.is, + (v, c) => { + if (Array.isArray(v) && v.length === 1 && typeof v[0] === 'string') { + return t.success(v[0]); + } + + return t.failure(v, c); + }, + t.identity +); + /** * Accepts either a boolean, or a string of a boolean. */ From e26997964468ac1b6d1f9f790e841cae33207c1a Mon Sep 17 00:00:00 2001 From: Pl217 Date: Wed, 12 Jun 2024 13:47:01 +0200 Subject: [PATCH 03/10] Introduce `TRIMMED_STRING` custom codec --- libs/hpc-data/src/lib/util.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/hpc-data/src/lib/util.ts b/libs/hpc-data/src/lib/util.ts index e13aacaa3..25cfb4118 100644 --- a/libs/hpc-data/src/lib/util.ts +++ b/libs/hpc-data/src/lib/util.ts @@ -111,6 +111,18 @@ export const BOOLEAN_FROM_STRING = new t.Type( t.identity ); +export const TRIMMED_STRING = new t.Type( + 'TRIMMED_STRING', + t.string.is, + (v, c) => { + if (typeof v === 'string') { + return t.success(v.trim()); + } + return t.failure(v, c); + }, + t.identity +); + /** * A file BLOB */ From 7fb687bead8e4d0d20fc0478575ef4fffdfbb452 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 16 Apr 2024 14:45:42 +0200 Subject: [PATCH 04/10] Modify config for GitHub Action supporting monorepo GitHub Action now supports releasing from a monorepo, therefore we can start using those capabilities in this repository. 1) Change from `docker` object to `dockerImages` array in configuration 2) Rename `path` to `dockerfilePath` 3) Add `appName` keys to differentiate applications 4) Modify Dockerfile to accept `APP_TO_BUILD` argument and utilize this argument in the configuration --- .github/workflow.config.json | 43 ++++++++++++++++++++++++++---------- Dockerfile | 3 ++- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/.github/workflow.config.json b/.github/workflow.config.json index 13c6f0717..d135a9746 100644 --- a/.github/workflow.config.json +++ b/.github/workflow.config.json @@ -2,19 +2,38 @@ "stagingEnvironmentBranch": "env/stage", "repoType": "node", "developmentEnvironmentBranches": ["env/red.dev", "env/blue.dev"], - "docker": { - "path": ".", - "args": { - "commitSha": "COMMIT_SHA", - "treeSha": "TREE_SHA" - }, - "environmentVariables": { - "commitSha": "HPC_ACTIONS_COMMIT_SHA", - "treeSha": "HPC_ACTIONS_TREE_SHA" + "dockerImages": [ + { + "dockerfilePath": ".", + "appName": "hpc-cdm", + "args": { + "commitSha": "COMMIT_SHA", + "treeSha": "TREE_SHA", + "appToBuild": "APP_TO_BUILD" + }, + "environmentVariables": { + "commitSha": "HPC_ACTIONS_COMMIT_SHA", + "treeSha": "HPC_ACTIONS_TREE_SHA" + }, + "repository": "public.ecr.aws/unocha/hpc-cdm", + "skipLogin": true }, - "repository": "public.ecr.aws/unocha/hpc-cdm", - "skipLogin": true - }, + { + "dockerfilePath": ".", + "appName": "hpc-ftsadmin", + "args": { + "commitSha": "COMMIT_SHA", + "treeSha": "TREE_SHA", + "appToBuild": "APP_TO_BUILD" + }, + "environmentVariables": { + "commitSha": "HPC_ACTIONS_COMMIT_SHA", + "treeSha": "HPC_ACTIONS_TREE_SHA" + }, + "repository": "public.ecr.aws/unocha/hpc-ftsadmin", + "skipLogin": true + } + ], "ci": ["./.github/ci.sh"], "mergebackLabels": ["mergeback"], "deployments": { diff --git a/Dockerfile b/Dockerfile index e955a7dd5..be8d9bf7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,10 +2,11 @@ FROM public.ecr.aws/unocha/nodejs-builder:20-alpine AS builder WORKDIR /srv/src COPY . . ARG ENVIRONMENT=production +ARG APP_TO_BUILD RUN npm run remove-unneeded-deps && \ npm install && \ # Output path is relative to working directory - npm run build hpc-cdm -- --output-path=dist/ --configuration=$ENVIRONMENT + npm run build ${APP_TO_BUILD} -- --output-path=dist/ --configuration=$ENVIRONMENT FROM public.ecr.aws/unocha/nginx:stable-beagle From 7204074d22c673bda95ed0d50085b9aaa45a0743 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 16 Apr 2024 14:50:10 +0200 Subject: [PATCH 05/10] Use Nx CLI to find affected apps to build --- .github/workflows/workflow.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 62470ee98..8537e77f3 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -14,6 +14,18 @@ jobs: with: node-version: '20' + - name: Install NPM Packages + run: npm ci + + - name: Derive appropriate SHAs for base and head for `nx affected` commands + # Production deployments are triggered by push events and not when a pull request + # is open, so we cannot use branch names when determining affected apps + if: ${{ github.ref_name == 'env/prod' }} + uses: nrwl/nx-set-shas@v4 + with: + main-branch-name: 'env/prod' + error-on-no-successful-workflow: true + - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -31,7 +43,26 @@ jobs: env: AWS_REGION: us-east-1 + - name: Get affected apps + id: affectedApps + run: | + if [[ -z "${{ env.NX_BASE }}" ]]; then + BASE_REF=${GITHUB_BASE_REF} + else + BASE_REF=${{ env.NX_BASE }} + fi + + if [[ -z "${{ env.NX_HEAD }}" ]]; then + HEAD_REF=${GITHUB_HEAD_REF} + else + HEAD_REF=${{ env.NX_HEAD }} + fi + + echo "AFFECTED_APPS=$(npx nx show projects --affected --type app --exclude=*-e2e --base=$BASE_REF --head=$HEAD_REF | xargs | tr ' ' ',')" >> "$GITHUB_OUTPUT" + - uses: UN-OCHA/hpc-actions@develop + with: + apps-to-build: ${{ steps.affectedApps.outputs.AFFECTED_APPS }} env: CONFIG_FILE: .github/workflow.config.json GITHUB_TOKEN: ${{ secrets.HPC_BOT_TOKEN }} From f7ec554dfa088650f0c29594647b6510fb6058fb Mon Sep 17 00:00:00 2001 From: Pl217 Date: Wed, 17 Apr 2024 00:22:09 +0200 Subject: [PATCH 06/10] Fetch all commits needed for `nrwl/nx-set-shas` --- .github/workflows/workflow.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 8537e77f3..c3d9a4c80 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -9,6 +9,9 @@ jobs: timeout-minutes: 25 steps: - uses: actions/checkout@v4 + with: + # We need to fetch all branches and commits so that Nx affected has a base to compare against. + fetch-depth: 0 - uses: actions/setup-node@v4 with: From b340e1c69f3fa16cdda50b0231f1e0ef89c2040d Mon Sep 17 00:00:00 2001 From: Pl217 Date: Thu, 18 Apr 2024 18:33:24 +0200 Subject: [PATCH 07/10] Replace `ci.sh` with plain workflow step The idea is to remove usage of shell scripts in CI and keep everything under the workflow file. The shell script was just installing packages so that it could run `lint` and `build` commands. By reading the code of custom GitHub Action, it was found that `ci.sh` is executed if branch isn't one of `env/prod`, `env/stage`, `env/red.dev` or `env/blue.dev`, but now they will always be run on affected apps. Before, with `ci.sh`, the commands would be run somewhere in between other stuff that custom GitHub Action does, but now the commands are run before anything else in custom GitHub Action. These two changes in behavior aren't seen as potentially problematic. --- .github/ci.sh | 13 ------------- .github/workflow.config.json | 1 - .github/workflows/workflow.yml | 6 ++++++ 3 files changed, 6 insertions(+), 14 deletions(-) delete mode 100755 .github/ci.sh diff --git a/.github/ci.sh b/.github/ci.sh deleted file mode 100755 index cd0f6cbe3..000000000 --- a/.github/ci.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /usr/bin/env bash - -set -xe - -npm install - -npm run build - -npm run lint - -# Tests are currently disabled until we're using them -# npm run test -# npm run e2e diff --git a/.github/workflow.config.json b/.github/workflow.config.json index d135a9746..81af39302 100644 --- a/.github/workflow.config.json +++ b/.github/workflow.config.json @@ -34,7 +34,6 @@ "skipLogin": true } ], - "ci": ["./.github/ci.sh"], "mergebackLabels": ["mergeback"], "deployments": { "environments": [ diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index c3d9a4c80..d59089e8e 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -46,6 +46,12 @@ jobs: env: AWS_REGION: us-east-1 + - name: Lint affected apps + run: npm run lint + + - name: Build affected apps + run: npx nx affected:build + - name: Get affected apps id: affectedApps run: | From 8a3fdc0ecc9b241a8c29b94f54bee5ddec177b1d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Jun 2024 15:06:50 +0000 Subject: [PATCH 08/10] Bump braces from 3.0.2 to 3.0.3 Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3. - [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3) --- updated-dependencies: - dependency-name: braces dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index ce159d9e7..ebb8ba3e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7285,12 +7285,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -10354,9 +10354,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" From 443a87258b3ec1891e437e358167673c2e506b4c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 06:35:18 +0000 Subject: [PATCH 09/10] Bump ws from 8.13.0 to 8.17.1 Bumps [ws](https://github.com/websockets/ws) from 8.13.0 to 8.17.1. - [Release notes](https://github.com/websockets/ws/releases) - [Commits](https://github.com/websockets/ws/compare/8.13.0...8.17.1) --- updated-dependencies: - dependency-name: ws dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index ebb8ba3e5..37cf802bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18920,9 +18920,9 @@ } }, "node_modules/ws": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", - "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "dev": true, "engines": { "node": ">=10.0.0" From 078d203510bf2e47755d58dd346c1a13888288fa Mon Sep 17 00:00:00 2001 From: manelcecs Date: Tue, 25 Jun 2024 14:33:36 +0200 Subject: [PATCH 10/10] =?UTF-8?q?=F0=9F=94=96Bump=20version=20to=20v1.9.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 37cf802bf..9469d4e56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "unocha", - "version": "1.8.0", + "version": "1.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "unocha", - "version": "1.8.0", + "version": "1.9.0", "license": "Apache-2.0", "devDependencies": { "@babel/core": "7.21.4", diff --git a/package.json b/package.json index 6a7412343..0c3ec2884 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unocha", - "version": "1.8.0", + "version": "1.9.0", "license": "Apache-2.0", "scripts": { "remove-unneeded-deps": "node tools/remove-unneeded-deps.js",