From 8629f40bbbec2d099f79b06b09a6c4f8cfc63365 Mon Sep 17 00:00:00 2001 From: Lewis Stevens Date: Thu, 15 Aug 2024 10:47:16 +0100 Subject: [PATCH 1/3] Fix NVM issues --- .github/workflows/on-pr-into-main.yml | 18 -------- .nvmrc | 1 - Makefile | 65 ++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 21 deletions(-) delete mode 100644 .nvmrc diff --git a/.github/workflows/on-pr-into-main.yml b/.github/workflows/on-pr-into-main.yml index f93e4e0b..5abe6dbe 100644 --- a/.github/workflows/on-pr-into-main.yml +++ b/.github/workflows/on-pr-into-main.yml @@ -1,8 +1,6 @@ name: on-pr-into-main env: - NVM_VERSION: 0.39.7 - NODE_VERSION: 16.14.0 PYTHON_VERSION: 3.9 on: @@ -22,22 +20,6 @@ jobs: with: python-version: ${{ env.PYTHON_VERSION }} - - name: Install a specific nvm version - run: | - rm -rf $NVM_DIR - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${{ env.NVM_VERSION }}/install.sh | bash - - cat ~/.bashrc | grep "NVM" > ~/.non-interactive - - - name: Install a specific node version - run: | - source ~/.non-interactive - - echo "NVM Version: $(nvm --version)" - nvm install ${{ env.NODE_VERSION }} - nvm use ${{ env.NODE_VERSION }} - nvm alias default ${{ env.NODE_VERSION }} - - name: Install and upgrade pre-requisites run: | python3.9 -m pip install --upgrade pip wheel setuptools diff --git a/.nvmrc b/.nvmrc deleted file mode 100644 index 832d3850..00000000 --- a/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -16.14.0 diff --git a/Makefile b/Makefile index 62801dbb..91cf5bf7 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,67 @@ CF_MANIFEST_PATH ?= /tmp/manifest.yml NOTIFY_CREDENTIALS ?= ~/.notify-credentials $(eval export CF_HOME) +NVM_VERSION := 0.39.7 +NODE_VERSION := 16.14.0 + +write-source-file: + @if [ -f ~/.zshrc ]; then \ + if [[ $$(cat ~/.zshrc | grep "export NVM") ]]; then \ + cat ~/.zshrc | grep "export NVM" | sed "s/export//" > ~/.nvm-source; \ + else \ + cat ~/.bashrc | grep "export NVM" | sed "s/export//" > ~/.nvm-source; \ + fi \ + else \ + cat ~/.bashrc | grep "export NVM" | sed "s/export//" > ~/.nvm-source; \ + fi + + +read-source-file: write-source-file + @for line in $$(cat ~/.nvm-source); do \ + export $$line; \ + done + + @echo '. "$$NVM_DIR/nvm.sh"' >> ~/.nvm-source; + + @current_nvm_version=$$(. ~/.nvm-source && nvm --version); \ + echo "NVM Versions (current/expected): $$current_nvm_version/$(NVM_VERSION)"; \ + echo ""; + +.PHONY: install-nvm +install-nvm: + @echo "" + @echo "[Install Node Version Manager]" + @echo "" + + @if [ ! -f ~/.nvm-source ]; then \ + rm -rf $(NVM_DIR); \ + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$(NVM_VERSION)/install.sh | bash; \ + echo ""; \ + fi + + @$(MAKE) read-source-file + + @current_nvm_version=$$(. ~/.nvm-source && nvm --version); \ + if [[ "$(NVM_VERSION)" == "$$current_nvm_version" ]]; then \ + echo "No need up adjust NVM versions."; \ + else \ + rm -rf $(NVM_DIR); \ + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$(NVM_VERSION)/install.sh | bash; \ + echo ""; \ + fi + + @$(MAKE) read-source-file + +.PHONY: install-node +install-node: install-nvm + @echo "" + @echo "[Install Node]" + @echo "" + + @. ~/.nvm-source && nvm install $(NODE_VERSION) \ + && nvm use $(NODE_VERSION) \ + && nvm alias default $(NODE_VERSION); + .PHONY: clean clean: rm -rf dist/* @@ -19,12 +80,12 @@ run-flask: . environment.sh && flask run -p 6017 .PHONY: bootstrap -bootstrap: +bootstrap: install-node pip3 install -r requirements_local_utils.txt npm ci --no-audit && npm run build .PHONY: bootstrap-for-tests -bootstrap-for-tests: +bootstrap-for-tests: install-node pip3 install -r requirements_github_utils.txt npm ci --no-audit && npm run build From bbe2923b5b2e92b64b90ddba9c47ade15a33924c Mon Sep 17 00:00:00 2001 From: Lewis Stevens Date: Thu, 15 Aug 2024 10:56:03 +0100 Subject: [PATCH 2/3] Remove source file --- .github/workflows/on-pr-into-main.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/on-pr-into-main.yml b/.github/workflows/on-pr-into-main.yml index 5abe6dbe..fadd182e 100644 --- a/.github/workflows/on-pr-into-main.yml +++ b/.github/workflows/on-pr-into-main.yml @@ -29,8 +29,6 @@ jobs: - name: Bootstrap Python app and run tests run: | - source ~/.non-interactive - export ENVIRONMENT='local' set -eu make bootstrap-for-tests From b278441d6413a37380ac4a021b2f32e9551fa4b0 Mon Sep 17 00:00:00 2001 From: Lewis Stevens Date: Thu, 15 Aug 2024 15:43:52 +0100 Subject: [PATCH 3/3] Remove source file --- Makefile | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 91cf5bf7..08cf4426 100644 --- a/Makefile +++ b/Makefile @@ -24,17 +24,44 @@ write-source-file: cat ~/.bashrc | grep "export NVM" | sed "s/export//" > ~/.nvm-source; \ fi - read-source-file: write-source-file + @if [ ! -f ~/.nvm-source ]; then \ + echo "Source file could not be read"; \ + exit 1; \ + fi + @for line in $$(cat ~/.nvm-source); do \ export $$line; \ - done + done; \ + echo '. "$$NVM_DIR/nvm.sh"' >> ~/.nvm-source; - @echo '. "$$NVM_DIR/nvm.sh"' >> ~/.nvm-source; + @if [[ "$(NVM_DIR)" == "" || ! -f "$(NVM_DIR)/nvm.sh" ]]; then \ + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$(NVM_VERSION)/install.sh | bash; \ + echo ""; \ + $(MAKE) write-source-file; \ + for line in $$(cat ~/.nvm-source); do \ + export $$line; \ + done; \ + echo '. "$$NVM_DIR/nvm.sh"' >> ~/.nvm-source; \ + fi @current_nvm_version=$$(. ~/.nvm-source && nvm --version); \ - echo "NVM Versions (current/expected): $$current_nvm_version/$(NVM_VERSION)"; \ - echo ""; + echo "NVM Versions (current/expected): $$current_nvm_version/$(NVM_VERSION)"; + +upgrade-node: + @TEMPDIR=/tmp/node-upgrade; \ + if [[ -d $(NVM_DIR)/versions ]]; then \ + rm -rf $$TEMPDIR; \ + mkdir $$TEMPDIR; \ + cp -rf $(NVM_DIR)/versions $$TEMPDIR; \ + echo "Node versions temporarily backed up to: $$TEMPDIR"; \ + fi; \ + rm -rf $(NVM_DIR); \ + $(MAKE) read-source-file; \ + if [[ -d $$TEMPDIR/versions ]]; then \ + cp -rf $$TEMPDIR/versions $(NVM_DIR); \ + echo "Restored node versions from: $$TEMPDIR"; \ + fi; .PHONY: install-nvm install-nvm: @@ -42,25 +69,18 @@ install-nvm: @echo "[Install Node Version Manager]" @echo "" - @if [ ! -f ~/.nvm-source ]; then \ - rm -rf $(NVM_DIR); \ - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$(NVM_VERSION)/install.sh | bash; \ - echo ""; \ + @if [[ "$(NVM_VERSION)" == "" ]]; then \ + echo "NVM_VERSION cannot be empty."; \ + exit 1; \ fi @$(MAKE) read-source-file @current_nvm_version=$$(. ~/.nvm-source && nvm --version); \ - if [[ "$(NVM_VERSION)" == "$$current_nvm_version" ]]; then \ - echo "No need up adjust NVM versions."; \ - else \ - rm -rf $(NVM_DIR); \ - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$(NVM_VERSION)/install.sh | bash; \ - echo ""; \ + if [[ "$(NVM_VERSION)" != "$$current_nvm_version" ]]; then \ + $(MAKE) upgrade-node; \ fi - @$(MAKE) read-source-file - .PHONY: install-node install-node: install-nvm @echo ""