diff --git a/.github/workflows/grade-assignment.yml b/.github/workflows/grade-assignment.yml deleted file mode 100644 index d06dc2d..0000000 --- a/.github/workflows/grade-assignment.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Grade Assignment - -on: - pull_request_target: - branches: - - main - -jobs: - grade: - permissions: - issues: write - pull-requests: write - uses: HackYourFuture/github-actions/.github/workflows/auto-grade.yml@main diff --git a/.hyf/package.json b/.hyf/package.json deleted file mode 100644 index ac1bb20..0000000 --- a/.hyf/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "hyf", - "version": "1.0.0", - "description": "HackYourFuture assignment", - "license": "ISC", - "author": "", - "type": "module", - "main": "tester.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - } -} \ No newline at end of file diff --git a/.hyf/task1.js b/.hyf/task1.js deleted file mode 100644 index e43ef28..0000000 --- a/.hyf/task1.js +++ /dev/null @@ -1,166 +0,0 @@ -import fs from 'fs/promises'; -import { exec } from 'child_process'; -import { promisify } from 'util'; - -const execPromise = promisify(exec); - -const setup = async () => { - await fs.rm('project', { recursive: true, force: true }); - await execPromise('git config --global user.name "Tester"'); - await execPromise('git config --global user.email "tester@example.com"'); -} - -const checkPath = async (filePath, shouldExist) => { - let score = 0; - try { - await fs.access(filePath); - let icon = shouldExist ? "✅" : "❌"; - if (shouldExist) { - score = 2; - } - console.log(`${icon} Path exists:`, filePath); - } catch { - let icon = shouldExist ? "❌" : "✅"; - if (!shouldExist) { - score = 2; - } - console.log(`${icon} Path does not exist:`, filePath); - } - return score; -} - -const checkFileContent = async (filePath, expectedContent) => { - let score = 0; - try { - const content = await fs.readFile(filePath, 'utf-8'); - if (content.trim() === expectedContent.trim()) { - score += 3; - console.log(`✅ File content is correct:`, filePath); - } else { - console.log(`❌ File content does not match:`, filePath); - console.log(`Expected: "${expectedContent.trim()}"`); - console.log(`Found: "${content.trim()}"`); - } - } catch (error) { - console.log(`❌ Error reading file:`, filePath); - } - return score; -} - -const checkStringInOutput = (output, pattern) => { - let score = 0; - const regex = new RegExp(pattern, 'i'); - if (regex.test(output)) { - console.log(`✅ Output has: "${pattern}"`); - score += 1; - } else { - console.log(`❌ Output does not have: "${pattern}"`); - } - return score; -} - -const checkGitCommits = async () => { - let score = 0; - const workDir = 'project'; - try { - // Check number of commits - const { stdout: countOutput } = await execPromise('git rev-list --count HEAD', { cwd: workDir }); - const commitCount = Number.parseInt(countOutput.trim()) ?? 0; - if (commitCount === 3) { - console.log(`✅ Found 3 commits`); - } else { - console.log(`❌ Expected 3 commits, found ${commitCount}`); - } - score += Math.max(commitCount, 0) * 3; - - // Check first commit message - const { stdout: firstCommitMsg } = await execPromise('git log --format=%s $(git rev-list --max-parents=0 HEAD)', { cwd: workDir }); - const message = firstCommitMsg.trim(); - - if (message.toLowerCase() === 'initial commit') { - console.log(`✅ First commit message is "initial commit"`); - score += 1; - } else { - console.log(`❌ First commit message is "${message}", expected "initial commit"`); - } - } catch (error) { - console.log(`❌ Error checking git commits:`, error.message); - } - return score; -} - -export const task1 = async () => { - // Setup - let score = 0; - let maxScore = 0; - await setup(); - - // Run - console.error('▶️ Running setup.sh...'); - let output = null; - const startTime = performance.now(); - try { - let result = await execPromise('bash ../task-1/setup.sh'); - output = result.stdout; - console.log(`✅ Successfully executed setup.sh.`); - } catch (error) { - console.error(`❌ Error executing setup.sh (Exit code ${error.code})`); - output = error.stdout + error.stderr; - } - - // check execution time (5 points) - maxScore += 5; - const executionTime = (performance.now() - startTime) / 1000; - if (executionTime >= 6) { - console.log(`✅ Script ran for at least 6 seconds`); - score += 5; - } else { - console.log(`❌ Script ran for less than 6 seconds (${executionTime.toFixed(2)}s)`); - } - - // Check paths (26 points) - maxScore += 26; - const expectedPaths = [ - 'project', - 'project/README.md', - 'project/settings.conf', - 'project/resources', - 'project/resources/icon.png', - 'project/resources/logo.png', - 'project/src', - 'project/src/program.js', - 'project/src/database', - 'project/.git' - ]; - const expectedPathsNotToExist = [ - 'project/resources/family picture.jpg', - 'project/src/profile', - 'project/src/program.java', - ]; - for (const path of expectedPaths) { - score += await checkPath(path, true); - } - for (const path of expectedPathsNotToExist) { - score += await checkPath(path, false); - } - - // Check file contents (6 points) - maxScore += 6; - score += await checkFileContent('project/src/program.js', `console.log('JavaScript works!');`); - score += await checkFileContent('project/README.md', `Welcome to my project`); - - // Check output content (6 points) - maxScore += 6; - score += checkStringInOutput(output, 'Creating project'); - score += checkStringInOutput(output, 'Setup project'); - score += checkStringInOutput(output, 'Setup JavaScript'); - score += checkStringInOutput(output, 'JavaScript works!'); - score += checkStringInOutput(output, 'icon.png'); - score += checkStringInOutput(output, 'All done!'); - - // Check git commits (10 points) - maxScore += 10; - score += await checkGitCommits(); - - return Math.round((score / maxScore) * 100); -}; diff --git a/.hyf/task2.js b/.hyf/task2.js deleted file mode 100644 index 32b5afa..0000000 --- a/.hyf/task2.js +++ /dev/null @@ -1,79 +0,0 @@ -import fs from 'fs/promises'; - -const readGithubUsername = async () => { - try { - - const content = await fs.readFile('../task-2/github-username.txt', 'utf-8'); - return content.trim(); - } catch (error) { - console.log('❌ Error reading github-username.txt:', error.message); - return null; - } -}; - -const fetchGithubProfile = async (username) => { - const readmeUrl = `https://raw.githubusercontent.com/${username}/${username}/main/README.md`; - console.log('▶️ Downloading profile README from:', readmeUrl); - - try { - const response = await fetch(readmeUrl); - if (!response.ok) { - throw new Error(`HTTP ${response.status}: ${response.statusText}`); - } - return await response.text(); - } catch (error) { - console.log('❌ Failed to download profile README:', error.message); - return null; - } -}; - -export const task2 = async () => { - let score = 0; - let maxScore = 30; - - // Read the GitHub username - const username = await readGithubUsername(); - - if (!username) { - console.log('❌ No username found in file'); - return score; - } - - console.log('Your GitHub username:', username); - - const profileContent = (await fetchGithubProfile(username)) ?? ""; - - // Check if profile contains GitHub top languages widget (10 points) - maxScore += 10; - const expectedStatsUrl = `https://github-readme-stats.vercel.app/api/top-langs/?username=${username}`; - if (profileContent.includes(expectedStatsUrl)) { - console.log('✅ Profile contains GitHub top languages widget'); - score += 10; - } else { - console.log('❌ Profile does not contain GitHub top languages widget'); - } - - - // Check if profile contains GitHub top languages widget (10 points) - maxScore += 10; - const expectedStreaksUrl = `https://streak-stats.demolab.com?user=${username}`; - if (profileContent.includes(expectedStreaksUrl)) { - console.log('✅ Profile contains GitHub streaks widget'); - score += 10; - } else { - console.log('❌ Profile does not contain GitHub streaks widget'); - } - - // Check if profile contains GitHub top languages widget (10 points) - maxScore += 10; - const expectedTitleUrl = `https://readme-typing-svg.demolab.com`; - if (profileContent.includes(expectedTitleUrl)) { - console.log('✅ Profile contains an animated title'); - score += 10; - } else { - console.log('❌ Profile does not contain an animated title'); - } - - return Math.round((score / maxScore) * 100); -} - diff --git a/.hyf/test.sh b/.hyf/test.sh deleted file mode 100644 index 901a19a..0000000 --- a/.hyf/test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Run the Node.js tester and capture stdout/stderr to the expected output file -/usr/bin/env node tester.js diff --git a/.hyf/tester.js b/.hyf/tester.js deleted file mode 100644 index d58b663..0000000 --- a/.hyf/tester.js +++ /dev/null @@ -1,32 +0,0 @@ -import { task1 } from './task1.js'; -import { task2 } from './task2.js'; -import fs from 'fs/promises'; - -const main = async () => { - console.log('======================= Task 1 ======================='); - const score1 = await task1(); - - console.log('\n======================= Task 2 ======================='); - const score2 = await task2(); - - console.log('\n======================= Summary ======================='); - const totalScore = Math.min(100, Math.round(score1 * 0.7 + score2 * 0.3)); - const passingScore = 50; - console.log(`- Task 1 Score: ${score1}%`); - console.log(`- Task 2 Score: ${score2}%`); - console.log(`Total Score: ${totalScore}%`); - console.log(`Min passing score: ${passingScore}%`); - const results = { - score: totalScore, - pass: totalScore >= passingScore, - passingScore: passingScore - }; - - await fs.writeFile('score.json', JSON.stringify(results, null, 2)); -} - -try { - await main(); -} catch (error) { - console.error(`❌ Something went wrong:\n${error}`); -} diff --git a/README.md b/README.md index b0e5a6b..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,12 +0,0 @@ -# Core program week 1 assignment -HackYourFuture core program week 1 assignment - -## Submission Instructions -### Task 1 -Complete the script `task-1/setup.sh` according to the assignment instructions. - -### Task 2 -Write your github username in the file `task-2/github-username.txt`. - -Do not include the `@` symbol before your username. -Do not paste the URL of your github profile. diff --git a/family picture.jpg b/family picture.jpg new file mode 100644 index 0000000..e69de29 diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..e69de29 diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..e69de29 diff --git a/resources b/resources new file mode 100644 index 0000000..e69de29 diff --git a/settings.conf b/settings.conf new file mode 100644 index 0000000..e69de29 diff --git a/src b/src new file mode 100644 index 0000000..e69de29 diff --git a/task-1/setup.sh b/task-1/setup.sh index 4067509..4ed3054 100644 --- a/task-1/setup.sh +++ b/task-1/setup.sh @@ -1 +1,46 @@ -# Write your code here \ No newline at end of file +#!/bin/bash +echo "Creating project..." + +mkdir project +cd project +git init +touch README.md +mkdir resources +touch settings.conf +mkdir src +cd resources +touch "family picture.jpg" icon.png logo.png +cd .. +cd src +touch database profile program.java +cd .. +git add . +git commit -m "initial commit" +echo "Setup project..." +echo "Welcome to my project" >> README.md + +cd src +rm -r profile +cd .. +cd resources +rm -r "family picture.jpg" + +git add . +git commit -m "deleted 2 files" +sleep 3 + +ls + +echo "Setup javascript..." +cd .. +cd src + +mv "program.java" "program.js" +echo "console.log('Javascript works!');" >> program.js +node program.js +cd .. + +git add . +git commit -m "checked the script runs" +ls -a +echo "All done!" \ No newline at end of file diff --git a/task-2/github-username.txt b/task-2/github-username.txt deleted file mode 100644 index 5eabca7..0000000 --- a/task-2/github-username.txt +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file