├── src ├── __tests__ ├── jest.config.js ├── babel.config.js ├── .github └── workflows │ ├── test.yml │ └── npm-publish-github-packages.yml ├── tsconfig.json ├── readme.md ├── package.json └── .gitignore /src: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /__tests__: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | }; 5 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | ['@babel/preset-env', { targets: { node: 'current' } }] 4 | ] 5 | }; 6 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test project 2 | on: 3 | pull_request: 4 | branches: 5 | - main 6 | 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | conytainer: 11 | image: node:20 12 | steps: 13 | - uses: actions/checkout@v3 14 | with: 15 | node-version: 20 16 | - run: npm ci 17 | - run: npm test 18 | - run: npm run build 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "esModuleInterop": true, 5 | "target": "es6", 6 | "moduleResolution": "node", 7 | "removeComments": true, 8 | "sourceMap": false, 9 | 10 | "outDir": "./dist", 11 | "rootDir": "./src", 12 | "resolveJsonModule": true, 13 | 14 | "skipLibCheck": true, 15 | "allowJs": true, 16 | // "checkJs": true, 17 | 18 | "strict": false, 19 | "types": ["jest", "node"] 20 | }, 21 | "include": ["src"], 22 | "exclude": ["node_modules", "dist/*", "src/static"], 23 | "lib": ["es6"] 24 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Github Actions Tutorial 2 | 3 | ## Introduction 4 | Github Actions is a CI/CD tool that allows you to automate your workflow. It is a powerful tool that can be used to build, test, package, release, and deploy your code. In this tutorial, we will learn how to create a Github Actions workflow. 5 | 6 | ## Prerequisites 7 | - Github account 8 | - Repository with code (you can use this repository) 9 | 10 | ## Steps 11 | 2. Create a new file in the `.github/workflows` directory 12 | 3. Define the workflow 13 | 4. Push the changes to the repository 14 | 5. Check the Actions tab in the repository 15 | 16 | ## Example Workflow 17 | ```yaml 18 | name: Test Project 19 | 20 | on: 21 | pull_request: 22 | branches: 23 | - main 24 | 25 | jobs: 26 | test: 27 | runs-on: ubuntu-latest 28 | container: 29 | image: node:20 30 | steps: 31 | - uses: actions/checkout@v3 32 | with: 33 | node-version: 20 34 | - run: npm ci 35 | - run: npm test 36 | - run: npm run build 37 | 38 | ``` -------------------------------------------------------------------------------- /.github/workflows/npm-publish-github-packages.yml: -------------------------------------------------------------------------------- 1 | # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created 2 | # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages 3 | 4 | name: Node.js Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/setup-node@v4 16 | with: 17 | node-version: 20 18 | - run: npm ci 19 | - run: npm test 20 | 21 | publish-gpr: 22 | needs: build 23 | runs-on: ubuntu-latest 24 | permissions: 25 | contents: read 26 | packages: write 27 | steps: 28 | - uses: actions/checkout@v4 29 | - uses: actions/setup-node@v4 30 | with: 31 | node-version: 20 32 | registry-url: https://npm.pkg.github.com/ 33 | - run: npm ci 34 | - run: npm publish 35 | env: 36 | NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "recipe-api", 3 | "version": "1.2.2", 4 | "description": "Node JS API for Recipes", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest", 8 | "dev": "npm run start --stage local", 9 | "start": "node --require ts-node/register src/index.ts", 10 | "build:clean": "rm -rf ./dist/*; rm ./dist/*; mkdir ./dist/logs;", 11 | "build:config": "cp ./src/config.json ./dist/config.json; cp ./package.json ./dist/package.json", 12 | "build": "npm run build:clean; npm run build:config; tsc --skipLibCheck;" 13 | }, 14 | "author": "Tom Shaw", 15 | "license": "ISC", 16 | "devDependencies": { 17 | "@babel/core": "^7.24.4", 18 | "@babel/preset-env": "^7.24.4", 19 | "@types/jest": "^29.5.12", 20 | "@types/node": "^22.4.0", 21 | "@types/supertest": "^6.0.2", 22 | "babel-jest": "^29.7.0", 23 | "jest": "^29.7.0", 24 | "superagent": "^8.1.2", 25 | "supertest": "^6.3.4", 26 | "ts-jest": "^29.1.2", 27 | "ts-node": "^10.9.1", 28 | "typescript": "^5.4.4" 29 | }, 30 | "dependencies": { 31 | "body-parser": "^1.20.1", 32 | "cors": "^2.8.5", 33 | "express": "^4.18.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | --------------------------------------------------------------------------------