📖 Scenario: You are working on a small Deno project and want to automate testing and deployment using a CI/CD pipeline. This will help you catch errors early and deploy your app automatically when changes are made.
🎯 Goal: Build a simple CI/CD pipeline configuration file that runs tests and deploys the Deno app automatically on every code push.
📋 What You'll Learn
Create a Deno test script file with a sample test
Add a configuration variable for the Deno version to use
Write the CI/CD pipeline steps to run tests and deploy
Print the pipeline status message at the end
💡 Why This Matters
🌍 Real World
Automating tests and deployment saves time and reduces errors in software projects.
💼 Career
Understanding CI/CD pipelines is essential for DevOps roles and modern software development.
Progress0 / 4 steps
1
Create a Deno test script
Create a file named test.ts with a simple test that checks if 1 + 1 equals 2. Use Deno's built-in test function with the name "simple addition test".
Deno
Hint
Use Deno.test with a callback function that throws an error if the test fails.
2
Add Deno version configuration
Create a variable called denoVersion and set it to the string "1.36.0" to specify the Deno version for the pipeline.
Deno
Hint
Use const denoVersion = "1.36.0"; to set the version.
3
Write CI/CD pipeline steps
Create a variable called pipelineSteps that is an array of strings. Add these exact steps in order: "checkout code", "setup deno 1.36.0", "run tests", and "deploy app". Use the denoVersion variable to insert the version number in the second step string.
Deno
Hint
Use a template string with backticks to include denoVersion in the second step.
4
Print the pipeline status
Write a console.log statement that prints the string "Pipeline steps:" followed by the pipelineSteps array joined by commas.
Deno
Hint
Use console.log("Pipeline steps: " + pipelineSteps.join(", ")) to print the steps.
Practice
(1/5)
1. What is the main purpose of setting up a CI/CD pipeline for a Deno project?
easy
A. To automate testing and deployment processes
B. To write code faster manually
C. To increase the size of the project files
D. To disable automatic updates
Solution
Step 1: Understand CI/CD pipeline purpose
A CI/CD pipeline automates repetitive tasks like testing and deployment to save time and reduce errors.
Step 2: Match purpose to options
Only To automate testing and deployment processes describes automation of testing and deployment, which is the main goal.
Final Answer:
To automate testing and deployment processes -> Option A
Quick Check:
CI/CD automates testing and deployment = A [OK]
Hint: CI/CD means automating build, test, and deploy steps [OK]
Common Mistakes:
Thinking CI/CD is about writing code manually
Confusing CI/CD with increasing file size
Believing CI/CD disables updates
2. Which of the following is the correct command to run tests in a Deno CI/CD pipeline?
easy
A. deno test
B. deno run test
C. deno build test
D. deno deploy test
Solution
Step 1: Recall Deno test command
The official command to run tests in Deno is deno test.
Step 2: Compare options with correct syntax
Only deno test matches the correct command syntax for running tests.
Final Answer:
deno test -> Option A
Quick Check:
Run tests with 'deno test' = A [OK]
Hint: Use 'deno test' to run tests, not 'deno run test' [OK]
Common Mistakes:
Using 'deno run test' which runs a script, not tests
Confusing build or deploy commands with test command
Adding extra words like 'build' or 'deploy' incorrectly
3. Given this CI step in a Deno pipeline:
steps:
- name: Run tests
run: deno test --unstable
- name: Bundle code
run: deno bundle mod.ts bundle.js
What will be the result if tests fail?
medium
A. The pipeline skips tests and bundles code
B. The pipeline stops and does not bundle the code
C. The pipeline continues and bundles the code anyway
D. The pipeline deletes the bundle.js file
Solution
Step 1: Understand default pipeline behavior on failure
In most CI/CD systems, if a test step fails, the pipeline stops to prevent deploying broken code.
Step 2: Apply to given steps
If deno test --unstable fails, the next step to bundle code will not run.
Final Answer:
The pipeline stops and does not bundle the code -> Option B
Quick Check:
Failed tests stop pipeline = C [OK]
Hint: Failed tests usually stop pipeline to avoid bad deploys [OK]
But the pipeline fails with an error. What is the likely cause?
medium
A. The pipeline requires 'deno test' before bundling
B. The file 'mod.ts' does not exist
C. The 'run' keyword is misspelled
D. The '-o' flag is not valid for 'deno bundle'
Solution
Step 1: Check 'deno bundle' syntax
The correct syntax to specify output file is: deno bundle input.ts output.js without '-o' flag.
Step 2: Identify error cause
Using '-o' causes an error because 'deno bundle' does not support it.
Final Answer:
The '-o' flag is not valid for 'deno bundle' -> Option D
Quick Check:
Output file is positional, no '-o' flag = D [OK]
Hint: Use positional output filename, not '-o', with deno bundle [OK]
Common Mistakes:
Adding '-o' flag like other bundlers
Assuming file existence without checking
Thinking 'run' keyword is wrong
Believing tests must run before bundling always
5. You want to create a CI/CD pipeline that runs tests, bundles code, and then deploys only if tests pass. Which YAML snippet correctly represents this sequence?
hard
A. steps:
- run: deno bundle mod.ts bundle.js
- run: deno test
- run: deploy.sh
B. steps:
- run: deploy.sh
- run: deno test
- run: deno bundle mod.ts bundle.js
C. steps:
- run: deno test
- run: deno bundle mod.ts bundle.js
- run: deploy.sh
D. steps:
- run: deno test
- run: deploy.sh
- run: deno bundle mod.ts bundle.js
Solution
Step 1: Determine correct order for CI/CD steps
Tests must run first to verify code, then bundle code, then deploy if tests pass.
Step 2: Match order with options
Only steps:
- run: deno test
- run: deno bundle mod.ts bundle.js
- run: deploy.sh runs tests first, then bundles, then deploys.
Final Answer:
Tests first, then bundle, then deploy -> Option C
Quick Check:
Test -> Bundle -> Deploy = B [OK]
Hint: Test first, then bundle, then deploy in pipeline steps [OK]
Common Mistakes:
Deploying before tests run
Bundling before tests
Changing step order incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.