diff --git a/.rwx/sample-run.yml b/.rwx/ci.yml similarity index 90% rename from .rwx/sample-run.yml rename to .rwx/ci.yml index 74b1ca2..09af4b7 100644 --- a/.rwx/sample-run.yml +++ b/.rwx/ci.yml @@ -2,6 +2,10 @@ on: cli: init: commit-sha: ${{ event.git.sha }} + github: + push: + init: + commit-sha: ${{ event.git.sha }} base: image: ubuntu:24.04 @@ -21,8 +25,6 @@ tasks: - key: node-modules use: [code, node] - agent: - tmpfs: true run: npm install filter: - package.json @@ -35,7 +37,7 @@ tasks: filter: - docker-compose.yml - - key: example-tests + - key: test use: [node-modules, docker-images] docker: true background-processes: @@ -47,7 +49,7 @@ tasks: test-results: - path: test-results.json - - key: example-lint-failures + - key: lint use: node-modules run: npm run lint outputs: diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 700ae18..0000000 --- a/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM node:18-alpine -WORKDIR /app -COPY package*.json ./ -RUN npm ci --only=production -COPY . . -RUN addgroup -g 1001 -S nodejs -RUN adduser -S nodejs -u 1001 -RUN chown -R nodejs:nodejs /app -USER nodejs -EXPOSE 3000 -HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD node healthcheck.js -CMD ["npm", "start"] diff --git a/README.md b/README.md index 508c7c6..bfb5be0 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,6 @@ [RWX](https://rwx.com) is the CI/CD platform for high velocity teams. -### What You'll See in CI Runs - -- **Test Failures**: Some tests are intentionally designed to fail to demonstrate test result reporting -- **Linting Errors**: The source code contains various ESLint violations (missing semicolons, unused variables, etc.) -- **Debugging**: A task that demonstrates RWX's debugging capabilities - ## Step 1: Install the CLI With RWX, you can run tasks without having to push to a git repository. @@ -50,16 +44,16 @@ rwx whoami ## Step 3: Kick off your first run -This repository contains a real Node.js project with intentional issues. Clone this repository and run the sample-run.yml workflow. Or if you'd prefer, check out the [documentation](https://www.rwx.com/docs/mint/guides/ci) to learn how to write your own workflows. +This repository contains an example Node.js project. Clone this repository and run the ci.yml workflow. Or if you'd prefer, check out the [documentation](https://www.rwx.com/docs/mint/guides/ci) to learn how to write your own workflows. ``` -git clone git@github.com:rwx-cloud/ci-examples.git +git clone https://github.com/rwx-cloud/ci-examples.git ``` ``` cd ci-examples ``` ``` -rwx run -f .rwx/sample-run.yml --title "Sample Run" --open +rwx run .rwx/ci.yml --open ``` -You can run this example run multiple times, and you'll see that, on subsequent runs, some redundant tasks are cached. +You can run this example run multiple times and you'll see that on subsequent runs all of the tasks will be cache hits. diff --git a/docker-compose.yml b/docker-compose.yml index 1dce16a..c4ecbb7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,15 +29,6 @@ services: timeout: 5s retries: 5 - adminer: - image: adminer:4.8.1 - ports: - - "8080:8080" - depends_on: - - db - environment: - - ADMINER_DEFAULT_SERVER=db - volumes: postgres_data: redis_data: diff --git a/src/index.js b/src/index.js index b5de622..15ed09a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,30 +1,28 @@ -const _ = require('lodash'); +// Calculate total price of items +function calculateTotal (items) { + let total = 0; -// This function has some intentional linting issues for demonstration -function calculateTotal(items) { - let total = 0 - - const taxRate = 0.08 - for (let i = 0; i < items.length; i++) { - var item = items[i] - total += item.price * item.quantity + const item = items[i]; + total += item.price * item.quantity; } - - return total + + return total; } -// Function with logic error (will cause test failure when b is 0) -function divide(a, b) { - return a / b +function divide (a, b) { + if (b === 0) { + return 0; + } + return a / b; } -function add(a, b) { - return a + b +function add (a, b) { + return a + b; } -function multiply( a,b ){ - return a*b +function multiply (a, b) { + return a * b; } module.exports = { @@ -32,4 +30,4 @@ module.exports = { divide, add, multiply -} +}; diff --git a/src/utils.js b/src/utils.js index ac41320..1c254bf 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,24 +1,25 @@ -function formatCurrency(amount) { - if (amount == null) { - return '$0.00' +function formatCurrency (amount) { + if (amount === null || amount === undefined) { + return '$0.00'; } - - return `$${amount.toFixed(2)},` + + return `$${amount.toFixed(2)},`; } -function validateEmail(email) { +function validateEmail (email) { if (email && email.includes('@')) { - return true + return true; } + return undefined; } -function debugLog(message) { - console.log('DEBUG:', message) +function debugLog (message) { + // eslint-disable-next-line no-console + console.log('DEBUG:', message); } -function isEven(number) { - // This logic is intentionally wrong - it returns true for odd numbers - return number % 2 === 1 +function isEven (number) { + return number % 2 === 0; } module.exports = { @@ -26,4 +27,4 @@ module.exports = { validateEmail, debugLog, isEven -} +}; diff --git a/test/index.test.js b/test/index.test.js index fb79c88..05298ad 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -44,14 +44,12 @@ describe('Index functions', () => { expect(divide(10, 2)).toBe(5); }); - // This test will fail because we're not handling division by zero test('should handle division by zero', () => { expect(divide(10, 0)).toBe(0); }); - // This test will also fail due to the logic error test('should divide negative numbers', () => { - expect(divide(-10, 2)).toBe(5); + expect(divide(-10, 2)).toBe(-5); }); }); }); diff --git a/test/utils.test.js b/test/utils.test.js index 3ede23c..14b37cd 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -31,17 +31,17 @@ describe('Utils functions', () => { describe('isEven', () => { test('should identify even numbers', () => { - expect(isEven(2)).toBe(true); // This will fail - our function is wrong - expect(isEven(4)).toBe(true); // This will fail - our function is wrong + expect(isEven(2)).toBe(true); + expect(isEven(4)).toBe(true); }); test('should identify odd numbers', () => { - expect(isEven(1)).toBe(false); // This will fail - our function is wrong - expect(isEven(3)).toBe(false); // This will fail - our function is wrong + expect(isEven(1)).toBe(false); + expect(isEven(3)).toBe(false); }); test('should handle zero', () => { - expect(isEven(0)).toBe(true); // This will fail - 0 is even but our function is wrong + expect(isEven(0)).toBe(true); }); });