Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr 01 pokedex #192

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
51f2f3b
osa11/hello.yml: initial commit
Aug 12, 2024
f17bd25
osa11/hello.yml: added new steps
Aug 12, 2024
bdb5bb5
osa11/pipeline.yml: initial commit
Aug 13, 2024
967b543
osa11/pipeline.yml: fixed some errors
Aug 13, 2024
ea6bf5c
osa11: fixed linting errors
Aug 13, 2024
e12effb
osa11/pipeline.yml: addded lint and build steps
Aug 13, 2024
b0856a1
osa11/PokemonPage.jsx: fixed error in next link
Aug 13, 2024
96fddb9
osa11: added end-to-end tests
Aug 13, 2024
8ce6410
osa11/cypress.config.js: fixed lint errors
Aug 13, 2024
e37d56b
osa11/pokemon_app.cy.js: added a new test case
Aug 13, 2024
b5223c8
osa11: enabled automatic deployments
Aug 14, 2024
f4a0596
osa11/app.js: added missing port number
Aug 14, 2024
f6daeac
osa11/app.js: added a broken build to test that it won't be deployed
Aug 14, 2024
433e83e
osa11/app.js: returned working health check function
Aug 14, 2024
acf7dda
osa11/PR_01_pokedex: added pull request to the pipeline
Aug 14, 2024
26eb2a6
osa11/pipeline.yml: modified deployment conditions
Aug 14, 2024
0e3aaa1
Merge pull request #1 from halonar/PR_01_pokedex
Aug 14, 2024
482450e
osa11/pipeline.yml: added versioning
Aug 15, 2024
ba4a783
osa11/pipeline.yml:changed DRY_RUN from true to false
Aug 15, 2024
c4ef30f
osa11/app.js: incremented version number
Aug 15, 2024
f7a72b5
osa11/pipeline.yml: Corrected action inputs
Aug 15, 2024
4ab7bbd
osa11/pipeline.yml: corrected more of action inputs
Aug 15, 2024
7d3c1d0
osa11/pipeline.yml: still a new input action correction
Aug 15, 2024
13e1f7e
osa11/pipeline.yml: added handling of commit containing #skip
Aug 15, 2024
6a05faa
osa11: test commit
Aug 15, 2024
fdd0952
osa11/app: test commit 2
Aug 15, 2024
937faf7
osa11/app: Testing pull request with #skip
Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 29 additions & 43 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,35 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"jest/globals": true
env: {
browser: true,
es6: true,
"jest/globals": true,
"cypress/globals": true,
node: true,
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
extends: ["eslint:recommended", "plugin:react/recommended"],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
"ecmaVersion": 2018,
"sourceType": "module"
ecmaVersion: 2018,
sourceType: "module",
},
"plugins": [
"react", "jest"
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
],
"eqeqeq": "error",
settings: {
react: {
version: "detect",
},
},
plugins: ["react", "jest", "cypress"],
rules: {
indent: ["error", 2],
//"linebreak-style": ["error", "unix"],
quotes: ["off"],
//semi: ["error", "never"],
eqeqeq: "error",
"no-trailing-spaces": "error",
"object-curly-spacing": [
"error", "always"
],
"arrow-spacing": [
"error", { "before": true, "after": true }
],
"object-curly-spacing": ["error", "always"],
"arrow-spacing": ["error", { before: true, after: true }],
"no-console": "error",
"react/prop-types": 0
}
}
"react/prop-types": 0,
},
};
20 changes: 20 additions & 0 deletions .github/workflows/hello.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Hello World!

on:
push:
branches:
- main

jobs:
hello_world_job:
runs-on: ubuntu-20.04
steps:
- name: Say hello
run: |
echo "Hello World!"
- name: Now it is
run: |
date
- name: Directory content
run: |
ls -l
51 changes: 51 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deployment pipeline

on:
push:
branches:
- main
pull_request:
branches: [main]
types: [opened, synchronize]

jobs:
simple_deployment_pipeline:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm install
- name: Run linter
run: npm run eslint
- name: Build prod
run: npm run build
- name: Test
run: npm run test
- name: e2e tests
uses: cypress-io/github-action@v5
with:
command: npm run test:e2e
start: npm run start-prod
wait-on: http://localhost:5000
- name: Trigger deployment
if: ${{ github.event_name == 'push' && !contains(join(github.event.commits.*.message, ' '), '#skip')}}
run: curl https://api.render.com/deploy/srv-${{ secrets.RENDER_SERVICE_ID }}?key=${{ secrets.RENDER_API_KEY }}

tag_release:
needs: simple_deployment_pipeline # This ensures the job runs after the simple_deployment_pipeline job
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch the entire history of the repository, including all branches and tags
- name: Bump version and push tag
if: github.ref == 'refs/heads/main' && !contains(join(github.event.commits.*.message, ' '), '#skip') # Ensure this job only runs on the main branch and if #skip is not in the commit message
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BUMP: patch # Set default bump to patch
TAG_PREFIX: "v" # Optional: prefix for the tag
DRY_RUN: false
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
node_modules/
node_modules/
.env
17 changes: 17 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
require("dotenv").config();
const express = require("express");
const app = express();

// get the port from env variable
//const PORT = process.env.PORT || 3001;
const PORT = process.env.PORT || 5000;

app.use(express.static("dist"));

app.get("/version", (req, res) => {
res.send("666"); // change this string to ensure a new version deployed
});

app.get("/health", (req, res) => {
res.send("ok");
});

// app.get('/health', (req, res) => {
// // eslint-disable-next-line no-constant-condition
// if (true) throw('error... ')
// res.send('ok')
// })

app.listen(PORT, () => {
// eslint-disable-next-line no-console
console.log(`server started on port ${PORT}`);
});
12 changes: 12 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
// eslint-disable-next-line no-unused-vars
setupNodeEvents(on, config) {
// implement node event listeners here
},
//baseUrl: "http://localhost:8080",
},
env: { BACKEND: "http://localhost:5000" },
});
17 changes: 17 additions & 0 deletions cypress/e2e/pokemon_app.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe("Pokedex", function () {
it("front page can be opened", function () {
cy.visit("http://localhost:5000");
cy.contains("ivysaur");
cy.contains(
"Pokémon and Pokémon character names are trademarks of Nintendo."
);
});

describe("Pokemon Page Test", function () {
it("Navigate to Ivysaur page which contains text chlorophyll", function () {
cy.visit("http://localhost:5000");
cy.contains("ivysaur").click();
cy.contains("chlorophyll");
});
});
});
67 changes: 67 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

// cy.request("POST", "http://localhost:3003/api/login", {
// username,
// password,
// failOnStatusCode: false,
// })
Cypress.Commands.add("login", ({ username, password }) => {
cy.request({
url: "http://localhost:3003/api/login",
method: "POST",
body: { username, password },
}).then(({ body }) => {
localStorage.setItem("loggedBlogappUser", JSON.stringify(body));
cy.visit("http://localhost:5173");
});
});

Cypress.Commands.add("loginError", ({ username, password }) => {
cy.request({
url: "http://localhost:3003/api/login",
method: "POST",
body: { username, password },
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.eq(401);
});
});

Cypress.Commands.add("createBlog", ({ title, author, url, likes }) => {
cy.request({
url: "http://localhost:3003/api/blogs",
method: "POST",
body: { title, author, url, likes },
headers: {
Authorization: `Bearer ${
JSON.parse(localStorage.getItem("loggedBlogappUser")).token
}`,
},
});

cy.visit("http://localhost:5173");
});
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading