Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NVM issues #360

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .github/workflows/on-pr-into-main.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

85 changes: 83 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand All @@ -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

Expand Down