diff --git a/.github/workflows/on-pr-into-main.yml b/.github/workflows/on-pr-into-main.yml index f93e4e0b..fadd182e 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 @@ -47,8 +29,6 @@ jobs: - name: Bootstrap Python app and run tests run: | - source ~/.non-interactive - export ENVIRONMENT='local' set -eu make bootstrap-for-tests 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..08cf4426 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,87 @@ 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 + @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; \ + 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)"; + +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: + @echo "" + @echo "[Install Node Version Manager]" + @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 \ + $(MAKE) upgrade-node; \ + fi + +.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 +100,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