Skip to content

Add multiply to math.js #3

Mergedsyntaqx merged into mainrequested by syntaqx

Approved by g1t

7 files+150−00/7 viewed
+10−0
1+name: After build
2+on:
3+ workflow_run:
4+ workflows: [Build]
5+ types: [completed]
6+jobs:
7+ report:
8+ runs-on: ubuntu-latest
9+ steps:
10+ - run: echo "Build ${{ github.event.workflow_run.run_number }} finished with ${{ github.event.workflow_run.conclusion }} on ${{ github.event.workflow_run.head_branch }}"
+35−0
1+name: Build
2+on:
3+ push:
4+ branches: [main]
5+ workflow_dispatch:
6+jobs:
7+ build:
8+ runs-on: ubuntu-latest
9+ steps:
10+ - uses: actions/checkout@v7
11+ - name: Restore the cache
12+ id: cache
13+ uses: actions/cache@v6
14+ with:
15+ path: .deps
16+ key: deps-${{ hashFiles('math.js') }}
17+ restore-keys: deps-
18+ - name: Fill the cache on a miss
19+ if: steps.cache.outputs.cache-hit != 'true'
20+ run: mkdir -p .deps && date > .deps/made-at && echo "cache was cold"
21+ - run: echo "cache hit=${{ steps.cache.outputs.cache-hit }}; deps made at $(cat .deps/made-at)"
22+ - run: mkdir -p dist && cp math.js dist/ && echo "built $(date)" > dist/BUILD
23+ - uses: actions/upload-artifact@v7
24+ with:
25+ name: dist
26+ path: dist/
27+ verify:
28+ needs: build
29+ runs-on: ubuntu-latest
30+ steps:
31+ - uses: actions/download-artifact@v8
32+ with:
33+ name: dist
34+ path: out
35+ - run: ls -la out && cat out/BUILD && node -e "console.log(require('./out/math.js').add(2, 2))"
+23−0
1+name: Checks
2+on:
3+ pull_request:
4+ merge_group:
5+ push:
6+ branches: [main]
7+jobs:
8+ test:
9+ runs-on: ubuntu-latest
10+ steps:
11+ - uses: actions/checkout@v7
12+ - name: Unit tests
13+ run: node test.js
14+ - name: House style
15+ run: |
16+ # Every exported function is documented with a JSDoc block.
17+ for fn in $(grep -oE '^function [a-zA-Z]+' math.js | cut -d' ' -f2); do
18+ if ! grep -B1 "^function $fn" math.js | grep -q '^ \*/\|^\*/\|\*/$'; then
19+ echo "::error file=math.js,title=House style::$fn needs a /** JSDoc */ comment right above it"
20+ exit 1
21+ fi
22+ done
23+ echo "house style ok"
+63−0
1+name: CI
2+on:
3+ push:
4+ branches: [main]
5+ workflow_dispatch:
6+ inputs:
7+ greeting:
8+ description: What to say
9+ default: hi
10+env:
11+ WORKFLOW_LEVEL: from-the-workflow
12+jobs:
13+ setup:
14+ runs-on: ubuntu-latest
15+ outputs:
16+ version: ${{ steps.version.outputs.value }}
17+ matrix: ${{ steps.matrix.outputs.json }}
18+ steps:
19+ - uses: actions/checkout@v7
20+ - id: version
21+ run: echo "value=1.2.$GITHUB_RUN_NUMBER" >> "$GITHUB_OUTPUT"
22+ - id: matrix
23+ run: echo 'json={"node":[24,26]}' >> "$GITHUB_OUTPUT"
24+ - name: Show the context
25+ run: |
26+ echo "::group::Context"
27+ echo "repo=${{ github.repository }} ref=${{ github.ref_name }} sha=${{ github.sha }}"
28+ echo "event=${{ github.event_name }} actor=${{ github.actor }}"
29+ echo "var=${{ vars.GREETING }} secret=${{ secrets.DEMO_SECRET }}"
30+ echo "workflow env=$WORKFLOW_LEVEL"
31+ echo "::endgroup::"
32+ echo "::notice title=Version::Building ${{ steps.version.outputs.value }}"
33+ ls -la
34+ test:
35+ needs: setup
36+ runs-on: ${{ matrix.os || 'ubuntu-latest' }}
37+ strategy:
38+ matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}
39+ steps:
40+ - uses: actions/checkout@v7
41+ - uses: actions/setup-node@v7
42+ with:
43+ node-version: ${{ matrix.node }}
44+ - run: node --version
45+ - name: Pass state between steps
46+ run: echo "FROM_EARLIER=set by step one" >> "$GITHUB_ENV"
47+ - run: echo "Reading it back -> $FROM_EARLIER (version ${{ needs.setup.outputs.version }})"
48+ - name: Allowed to fail
49+ continue-on-error: true
50+ run: exit 3
51+ - name: Only on Node 22
52+ if: matrix.node == 24
53+ run: echo "hash=${{ hashFiles('**/*.yml') }}"
54+ report:
55+ needs: [setup, test]
56+ if: always()
57+ runs-on: ubuntu-latest
58+ steps:
59+ - run: echo "test result was ${{ needs.test.result }}"
60+ - shell: python
61+ run: |
62+ import os
63+ print("python says", os.environ["GITHUB_REPOSITORY"])
+1−0
1+# automation lab
+12−0
1+// Small helpers for numbers.
2+/** Returns the sum of a and b. */
3+function add(a, b) {
4+ return a + b;
5+}
6+
7+/** Returns the product of a and b. */
8+function multiply(a, b) {
9+ return a * b;
10+}
11+
12+module.exports = { add, multiply };
+6−0
1+const assert = require("node:assert");
2+const math = require("./math");
3+
4+assert.strictEqual(math.add(2, 3), 5);
5+assert.strictEqual(math.multiply(4, 5), 20);
6+console.log("all tests passed");