Skip to content

Commit

Permalink
upgrade API, node, docker
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Apr 28, 2022
1 parent b9cd336 commit bc28b7a
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 130 deletions.
32 changes: 17 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ version: 2.1

executors:
build-executor:
machine: true
machine:
image: ubuntu-2204:edge
resource_class: large
working_directory: /home/circleci/project

Expand All @@ -24,16 +25,17 @@ commands:
- run:
name: Build and Install Deps
command: |
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL "https://github.com/docker/compose/releases/download/v2.4.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
mv .circleci/circle_envs .env
echo -e '\ndocker_volumes/db/pg_wal/*' >> .dockerignore
sudo docker-compose run web gem install bundler
sudo docker-compose run web bundle install
sudo docker-compose run web npm install
sudo docker-compose run web bundle exec rails db:create
sudo docker-compose run web bundle exec rails db:migrate
sudo docker-compose run web rake keys:generate
sudo docker compose run web gem install bundler
sudo docker compose run web bundle install
sudo docker compose run web npm install
sudo docker compose run web bundle exec rails db:create
sudo docker compose run web bundle exec rails db:migrate
sudo docker compose run web rake keys:generate
- run:
name: After cache update
command: |
Expand All @@ -53,34 +55,34 @@ commands:
- run:
name: Run Ruby Tests
command: |
sudo docker-compose run web rspec spec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec/rspec.xml
sudo docker compose run web rspec spec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec/rspec.xml
jest-commands:
steps:
- run:
name: Run JS tests
command: |
sudo docker-compose run web npm run test-slow -- -c .circleci/jest-ci.config.js
sudo docker compose run web npm run test-slow -- -c .circleci/jest-ci.config.js
echo 'export COVERAGE_AVAILABLE=true' >> $BASH_ENV
lint-commands:
steps:
- run:
name: Run JS Linters
command: |
sudo docker-compose run web npm run linters
sudo docker compose run web npm run linters
when: always
coverage-commands:
steps:
- run:
name: Check coverage status
command: |
sudo docker-compose run -e CIRCLE_SHA1="$CIRCLE_SHA1" -e CIRCLE_BRANCH="$CIRCLE_BRANCH" -e CIRCLE_PULL_REQUEST="$CIRCLE_PULL_REQUEST" web rake coverage:run || [ $CIRCLE_BRANCH == "staging" ]
sudo docker compose run -e CIRCLE_SHA1="$CIRCLE_SHA1" -e CIRCLE_BRANCH="$CIRCLE_BRANCH" -e CIRCLE_PULL_REQUEST="$CIRCLE_PULL_REQUEST" web rake coverage:run || [ $CIRCLE_BRANCH == "staging" ]
when: always
- run:
name: Report coverage to Coveralls
command: |
if [ "$COVERAGE_AVAILABLE" ]
then
sudo docker-compose run -e COVERALLS_REPO_TOKEN=lEX6nkql7y2YFCcIXVq5ORvdvMtYzfZdG web npm run coverage || [ $CIRCLE_BRANCH == "staging" ]
sudo docker compose run -e COVERALLS_REPO_TOKEN=lEX6nkql7y2YFCcIXVq5ORvdvMtYzfZdG web npm run coverage || [ $CIRCLE_BRANCH == "staging" ]
fi
when: always # change to `on_success` for a stricter comparison

Expand Down Expand Up @@ -137,6 +139,6 @@ jobs:
name: Run JS Tests
command: |
circleci tests glob **/__tests__/**/*.ts* | circleci tests split > /tmp/tests-to-run
sudo docker-compose run web npm run test-very-slow -- -c .circleci/jest-ci.config.js $(cat /tmp/tests-to-run)
sudo docker compose run web npm run test-very-slow -- -c .circleci/jest-ci.config.js $(cat /tmp/tests-to-run)
- store_test_results:
path: /tmp/test-results
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.log
*.pem
*.tsbuildinfo
*.pid.lock
*scratchpad*
/config/master.key
api_docs.md
Expand Down
116 changes: 58 additions & 58 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,40 @@ GIT
GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.5)
actionpack (= 6.1.5)
activesupport (= 6.1.5)
actioncable (6.1.5.1)
actionpack (= 6.1.5.1)
activesupport (= 6.1.5.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.5)
actionpack (= 6.1.5)
activejob (= 6.1.5)
activerecord (= 6.1.5)
activestorage (= 6.1.5)
activesupport (= 6.1.5)
actionmailbox (6.1.5.1)
actionpack (= 6.1.5.1)
activejob (= 6.1.5.1)
activerecord (= 6.1.5.1)
activestorage (= 6.1.5.1)
activesupport (= 6.1.5.1)
mail (>= 2.7.1)
actionmailer (6.1.5)
actionpack (= 6.1.5)
actionview (= 6.1.5)
activejob (= 6.1.5)
activesupport (= 6.1.5)
actionmailer (6.1.5.1)
actionpack (= 6.1.5.1)
actionview (= 6.1.5.1)
activejob (= 6.1.5.1)
activesupport (= 6.1.5.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.5)
actionview (= 6.1.5)
activesupport (= 6.1.5)
actionpack (6.1.5.1)
actionview (= 6.1.5.1)
activesupport (= 6.1.5.1)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.5)
actionpack (= 6.1.5)
activerecord (= 6.1.5)
activestorage (= 6.1.5)
activesupport (= 6.1.5)
actiontext (6.1.5.1)
actionpack (= 6.1.5.1)
activerecord (= 6.1.5.1)
activestorage (= 6.1.5.1)
activesupport (= 6.1.5.1)
nokogiri (>= 1.8.5)
actionview (6.1.5)
activesupport (= 6.1.5)
actionview (6.1.5.1)
activesupport (= 6.1.5.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
Expand All @@ -50,22 +50,22 @@ GEM
activemodel (>= 4.1, < 7.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (6.1.5)
activesupport (= 6.1.5)
activejob (6.1.5.1)
activesupport (= 6.1.5.1)
globalid (>= 0.3.6)
activemodel (6.1.5)
activesupport (= 6.1.5)
activerecord (6.1.5)
activemodel (= 6.1.5)
activesupport (= 6.1.5)
activestorage (6.1.5)
actionpack (= 6.1.5)
activejob (= 6.1.5)
activerecord (= 6.1.5)
activesupport (= 6.1.5)
activemodel (6.1.5.1)
activesupport (= 6.1.5.1)
activerecord (6.1.5.1)
activemodel (= 6.1.5.1)
activesupport (= 6.1.5.1)
activestorage (6.1.5.1)
actionpack (= 6.1.5.1)
activejob (= 6.1.5.1)
activerecord (= 6.1.5.1)
activesupport (= 6.1.5.1)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (6.1.5)
activesupport (6.1.5.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -166,15 +166,15 @@ GEM
google-cloud-env (1.6.0)
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.2.0)
google-cloud-storage (1.36.1)
google-cloud-storage (1.36.2)
addressable (~> 2.8)
digest-crc (~> 0.4)
google-apis-iamcredentials_v1 (~> 0.1)
google-apis-storage_v1 (~> 0.1)
google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)
googleauth (1.1.2)
googleauth (1.1.3)
faraday (>= 0.17.3, < 3.a)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
Expand Down Expand Up @@ -205,7 +205,7 @@ GEM
activesupport (>= 4)
railties (>= 4)
request_store (~> 1.0)
loofah (2.16.0)
loofah (2.17.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
Expand Down Expand Up @@ -242,26 +242,26 @@ GEM
multi_json (~> 1.15)
racc (1.6.0)
rack (2.2.3)
rack-attack (6.6.0)
rack-attack (6.6.1)
rack (>= 1.0, < 3)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.5)
actioncable (= 6.1.5)
actionmailbox (= 6.1.5)
actionmailer (= 6.1.5)
actionpack (= 6.1.5)
actiontext (= 6.1.5)
actionview (= 6.1.5)
activejob (= 6.1.5)
activemodel (= 6.1.5)
activerecord (= 6.1.5)
activestorage (= 6.1.5)
activesupport (= 6.1.5)
rails (6.1.5.1)
actioncable (= 6.1.5.1)
actionmailbox (= 6.1.5.1)
actionmailer (= 6.1.5.1)
actionpack (= 6.1.5.1)
actiontext (= 6.1.5.1)
actionview (= 6.1.5.1)
activejob (= 6.1.5.1)
activemodel (= 6.1.5.1)
activerecord (= 6.1.5.1)
activestorage (= 6.1.5.1)
activesupport (= 6.1.5.1)
bundler (>= 1.15.0)
railties (= 6.1.5)
railties (= 6.1.5.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
Expand All @@ -273,9 +273,9 @@ GEM
rails_stdout_logging
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
railties (6.1.5)
actionpack (= 6.1.5)
activesupport (= 6.1.5)
railties (6.1.5.1)
actionpack (= 6.1.5.1)
activesupport (= 6.1.5.1)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand Down Expand Up @@ -306,7 +306,7 @@ GEM
rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-rails (5.1.1)
rspec-rails (5.1.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
Expand Down
2 changes: 1 addition & 1 deletion docker_configs/api.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ruby:3.0.2
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg > /dev/null && \
sh -c '. /etc/os-release; echo $VERSION_CODENAME; echo "deb http://apt.postgresql.org/pub/repos/apt/ $VERSION_CODENAME-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' && \
apt-get update -qq && apt-get install -y build-essential libpq-dev postgresql postgresql-contrib && \
curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
sh -c 'echo "\nPackage: *\nPin: origin deb.nodesource.com\nPin-Priority: 700\n" >> /etc/apt/preferences' && \
apt-get install -y nodejs && \
mkdir /farmbot;
Expand Down
20 changes: 9 additions & 11 deletions frontend/redux/__tests__/subscribers_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
unsavedCheck,
stopThem,
dontStopThem,
} from "../subscribers";
import {
buildResourceIndex,
Expand All @@ -15,6 +13,8 @@ import { WebAppConfig } from "farmbot/dist/resources/configs/web_app";
describe("unsavedCheck", () => {
beforeEach(() => {
localStorage.setItem("session", "YES");
window.addEventListener = jest.fn();
window.removeEventListener = jest.fn();
});

function setItUp(
Expand Down Expand Up @@ -56,48 +56,46 @@ describe("unsavedCheck", () => {
unsavedCheck(setItUp(
{ seqDirty: true, otherDirty: true },
{ discard_unsaved: false, discard_unsaved_sequences: false }));
expect(window.onbeforeunload).toBe(dontStopThem);
expect(window.removeEventListener).toHaveBeenCalled();
});

it("doesn't stop users if work is saved", () => {
unsavedCheck(setItUp(
{ seqDirty: false, otherDirty: false },
{ discard_unsaved: false, discard_unsaved_sequences: false }));
expect(window.onbeforeunload).toBe(dontStopThem);
expect(dontStopThem()).toBeFalsy();
expect(window.removeEventListener).toHaveBeenCalled();
});

it("stops users if they have unsaved work without config", () => {
unsavedCheck(setItUp({ seqDirty: true, otherDirty: true }, undefined));
expect(window.onbeforeunload).toBe(stopThem);
expect(stopThem()).toBe("You have unsaved work.");
expect(window.addEventListener).toHaveBeenCalled();
});

it("doesn't stop users if they want to discard all unsaved work", () => {
unsavedCheck(setItUp(
{ seqDirty: true, otherDirty: true },
{ discard_unsaved: true, discard_unsaved_sequences: false }));
expect(window.onbeforeunload).toBe(dontStopThem);
expect(window.removeEventListener).toHaveBeenCalled();
});

it("stops users if they have unsaved work other than sequences", () => {
unsavedCheck(setItUp(
{ seqDirty: false, otherDirty: true },
{ discard_unsaved: false, discard_unsaved_sequences: true }));
expect(window.onbeforeunload).toBe(stopThem);
expect(window.addEventListener).toHaveBeenCalled();
});

it("doesn't stop users if discard unsaved sequences is enabled", () => {
unsavedCheck(setItUp(
{ seqDirty: true, otherDirty: true },
{ discard_unsaved: false, discard_unsaved_sequences: true }));
expect(window.onbeforeunload).toBe(dontStopThem);
expect(window.removeEventListener).toHaveBeenCalled();
});

it("stops users with unsaved sequences", () => {
unsavedCheck(setItUp(
{ seqDirty: true, otherDirty: false },
{ discard_unsaved: false, discard_unsaved_sequences: false }));
expect(window.onbeforeunload).toBe(stopThem);
expect(window.addEventListener).toHaveBeenCalled();
});
});
10 changes: 7 additions & 3 deletions frontend/redux/subscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { all } from "../resources/selectors";
import { getWebAppConfig } from "../resources/getters";
import { TaggedResource, TaggedWebAppConfig } from "farmbot";

export function stopThem() { return "You have unsaved work."; }
export function dontStopThem() { }
export function stopThem(event: BeforeUnloadEvent) {
event.preventDefault();
return "You have unsaved work.";
}

/** Determine when to notify users about unsaved changes (stop auto-discard). */
const shouldStop =
Expand Down Expand Up @@ -43,7 +45,9 @@ export function unsavedCheck(state: Everything) {
const resources = all(index);
const conf = getWebAppConfig(index);

window.onbeforeunload = shouldStop(resources, conf) ? stopThem : dontStopThem;
shouldStop(resources, conf)
? window.addEventListener("beforeunload", stopThem)
: window.removeEventListener("beforeunload", stopThem);
}

export interface Subscription { fn: (state: Everything) => void; env: EnvName; }
Expand Down

0 comments on commit bc28b7a

Please sign in to comment.