Skip to content

Commit bdeea0b

Browse files
authored
Merge pull request #20 from codersforcauses/init
feat(ci): Add workflow inits
2 parents 32bf91f + d432591 commit bdeea0b

16 files changed

Lines changed: 375 additions & 37 deletions

.github/issue-branch.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# https://github.com/robvanderleek/create-issue-branch#option-2-configure-github-action
2+
3+
# ex: i4-lower_camel_upper
4+
branchName: "i${issue.number}-${issue.title,}"
5+
branches:
6+
- label: epic
7+
skip: true
8+
- label: debt
9+
skip: true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: "Autolink Issue"
2+
on:
3+
pull_request:
4+
types: [opened]
5+
6+
jobs:
7+
issue-links:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: tkt-actions/add-issue-links@v1.6.0
11+
with:
12+
repo-token: "${{ secrets.GITHUB_TOKEN }}"
13+
branch-prefix: "i"
14+
resolve: "true"

.github/workflows/backend.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Backend CI/CD
2+
3+
on:
4+
push:
5+
paths:
6+
- server/**
7+
branches:
8+
- main
9+
- master
10+
pull_request:
11+
paths:
12+
- server/**
13+
branches:
14+
- main
15+
- master
16+
17+
jobs:
18+
ci:
19+
runs-on: ${{ matrix.os }}
20+
21+
defaults:
22+
run:
23+
working-directory: server
24+
25+
strategy:
26+
matrix:
27+
os: [ubuntu-latest]
28+
python-version: [3.10.5]
29+
30+
services:
31+
postgres:
32+
image: postgres
33+
env:
34+
POSTGRES_USER: postgres
35+
POSTGRES_PASSWORD: postgres
36+
POSTGRES_DB: github-actions
37+
ports:
38+
- 5432:5432
39+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
40+
41+
steps:
42+
- name: Checkout 🛎
43+
uses: actions/checkout@v3
44+
45+
- name: Setup Python env 🏗
46+
uses: actions/setup-python@v4
47+
with:
48+
python-version: ${{ matrix.python-version }}
49+
architecture: x64
50+
51+
- name: Setup Poetry 🏗
52+
uses: snok/install-poetry@v1
53+
with:
54+
version: 1.1.10
55+
virtualenvs-create: true
56+
virtualenvs-in-project: true
57+
58+
- name: Cache .venv 📦
59+
id: cached-poetry-dependencies
60+
uses: actions/cache@v3.0.4
61+
with:
62+
path: server/.venv
63+
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
64+
65+
- name: Install dependencies 👨🏻‍💻
66+
run: poetry install
67+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
68+
69+
- name: Run linter 👀
70+
run: |
71+
source .venv/bin/activate
72+
flake8 api manage.py
73+
black api manage.py --check --line-length 80 --preview
74+
isort api manage.py
75+
76+
- name: Run Migrations 🕊️
77+
run: |
78+
source .venv/bin/activate
79+
python manage.py migrate
80+
81+
- name: Run tests 🧪
82+
run: |
83+
source .venv/bin/activate
84+
python manage.py test
85+
86+
- name: Upload Coverage ☂️
87+
uses: codecov/codecov-action@v3.1.0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "Create Branch"
2+
on:
3+
issues:
4+
types: [assigned]
5+
pull_request:
6+
types: [closed]
7+
8+
jobs:
9+
create_issue_branch_job:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Create Issue Branch
13+
uses: robvanderleek/create-issue-branch@main
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/frontend.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ jobs:
1818
ci:
1919
runs-on: ${{ matrix.os }}
2020

21+
defaults:
22+
run:
23+
working-directory: client
24+
2125
strategy:
2226
matrix:
2327
os: [ubuntu-latest]
2428
node: [16]
2529

2630
steps:
2731
- name: Checkout 🛎
28-
uses: actions/checkout@master
32+
uses: actions/checkout@v3
2933

3034
- name: Setup node env 🏗
3135
uses: actions/setup-node@v3.3.0
@@ -48,15 +52,19 @@ jobs:
4852
4953
- name: Install dependencies 👨🏻‍💻
5054
run: yarn
51-
working-directory: client
5255

5356
- name: Run linter 👀
5457
run: yarn lint
55-
working-directory: client
5658

57-
- name: Run tests 🧪
59+
- name: Run Jest tests 🧪
5860
run: yarn test
59-
working-directory: client
61+
62+
- name: Run Cypress tests 🧪
63+
uses: cypress-io/github-action@v4
64+
with:
65+
working-directory: client
66+
install-command: yarn --frozen-lockfile --silent
67+
build: yarn build
6068

6169
- name: Upload Coverage ☂️
6270
uses: codecov/codecov-action@v3.1.0

client/.eslintrc.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ module.exports = {
44
es2021: true,
55
jest: true,
66
},
7-
extends: ['plugin:vue/essential', 'standard', 'prettier'],
7+
extends: [
8+
'plugin:vue/essential',
9+
'standard',
10+
'prettier',
11+
'plugin:cypress/recommended',
12+
],
813
parserOptions: {
914
ecmaVersion: 'latest',
1015
sourceType: 'module',
1116
},
12-
plugins: ['vue'],
17+
plugins: ['vue', 'cypress'],
1318
rules: {},
1419
};

client/.vscode/extensions.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"recommendations": [
3+
// frontend
4+
"octref.vetur",
5+
"hollowtree.vue-snippets",
6+
"bradlc.vscode-tailwindcss",
7+
"heybourn.headwind",
8+
"austenc.tailwind-docs",
9+
"csstools.postcss",
10+
"esbenp.prettier-vscode",
11+
"dbaeumer.vscode-eslint",
12+
"eg2.vscode-npm-script",
13+
"christian-kohler.npm-intellisense",
14+
15+
// quality of life
16+
"aaron-bond.better-comments",
17+
"eamodio.gitlens",
18+
"GitHub.vscode-pull-request-github",
19+
"VisualStudioExptTeam.vscodeintellicode",
20+
"christian-kohler.path-intellisense",
21+
"oderwat.indent-rainbow",
22+
"DavidAnson.vscode-markdownlint",
23+
"yzhang.markdown-all-in-one",
24+
"rangav.vscode-thunder-client"
25+
]
26+
}

client/.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"css.validate": false,
3+
"editor.formatOnSave": true,
4+
"editor.tabSize": 2,
5+
"editor.codeActionsOnSave": {
6+
"source.fixAll": true
7+
},
8+
"headwind.runOnSave": false
9+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/// <reference types="cypress" />
2+
3+
// Welcome to Cypress!
4+
//
5+
// This spec file contains a variety of sample tests
6+
// for a todo list app that are designed to demonstrate
7+
// the power of writing tests in Cypress.
8+
//
9+
// To learn more about how Cypress works and
10+
// what makes it such an awesome testing tool,
11+
// please read our getting started guide:
12+
// https://on.cypress.io/introduction-to-cypress
13+
14+
describe('example to-do app', () => {
15+
beforeEach(() => {
16+
// Cypress starts out with a blank slate for each test
17+
// so we must tell it to visit our website with the `cy.visit()` command.
18+
// Since we want to visit the same URL at the start of all our tests,
19+
// we include it in our beforeEach function so that it runs before each test
20+
cy.visit('https://example.cypress.io/todo');
21+
});
22+
23+
it('displays two todo items by default', () => {
24+
// We use the `cy.get()` command to get all elements that match the selector.
25+
// Then, we use `should` to assert that there are two matched items,
26+
// which are the two default items.
27+
cy.get('.todo-list li').should('have.length', 2);
28+
29+
// We can go even further and check that the default todos each contain
30+
// the correct text. We use the `first` and `last` functions
31+
// to get just the first and last matched elements individually,
32+
// and then perform an assertion with `should`.
33+
cy.get('.todo-list li').first().should('have.text', 'Pay electric bill');
34+
cy.get('.todo-list li').last().should('have.text', 'Walk the dog');
35+
});
36+
37+
it('can add new todo items', () => {
38+
// We'll store our item text in a variable so we can reuse it
39+
const newItem = 'Feed the cat';
40+
41+
// Let's get the input element and use the `type` command to
42+
// input our new list item. After typing the content of our item,
43+
// we need to type the enter key as well in order to submit the input.
44+
// This input has a data-test attribute so we'll use that to select the
45+
// element in accordance with best practices:
46+
// https://on.cypress.io/selecting-elements
47+
cy.get('[data-test=new-todo]').type(`${newItem}{enter}`);
48+
49+
// Now that we've typed our new item, let's check that it actually was added to the list.
50+
// Since it's the newest item, it should exist as the last element in the list.
51+
// In addition, with the two default items, we should have a total of 3 elements in the list.
52+
// Since assertions yield the element that was asserted on,
53+
// we can chain both of these assertions together into a single statement.
54+
cy.get('.todo-list li')
55+
.should('have.length', 3)
56+
.last()
57+
.should('have.text', newItem);
58+
});
59+
60+
it('can check off an item as completed', () => {
61+
// In addition to using the `get` command to get an element by selector,
62+
// we can also use the `contains` command to get an element by its contents.
63+
// However, this will yield the <label>, which is lowest-level element that contains the text.
64+
// In order to check the item, we'll find the <input> element for this <label>
65+
// by traversing up the dom to the parent element. From there, we can `find`
66+
// the child checkbox <input> element and use the `check` command to check it.
67+
cy.contains('Pay electric bill')
68+
.parent()
69+
.find('input[type=checkbox]')
70+
.check();
71+
72+
// Now that we've checked the button, we can go ahead and make sure
73+
// that the list element is now marked as completed.
74+
// Again we'll use `contains` to find the <label> element and then use the `parents` command
75+
// to traverse multiple levels up the dom until we find the corresponding <li> element.
76+
// Once we get that element, we can assert that it has the completed class.
77+
cy.contains('Pay electric bill')
78+
.parents('li')
79+
.should('have.class', 'completed');
80+
});
81+
82+
context('with a checked task', () => {
83+
beforeEach(() => {
84+
// We'll take the command we used above to check off an element
85+
// Since we want to perform multiple tests that start with checking
86+
// one element, we put it in the beforeEach hook
87+
// so that it runs at the start of every test.
88+
cy.contains('Pay electric bill')
89+
.parent()
90+
.find('input[type=checkbox]')
91+
.check();
92+
});
93+
94+
it('can filter for uncompleted tasks', () => {
95+
// We'll click on the "active" button in order to
96+
// display only incomplete items
97+
cy.contains('Active').click();
98+
99+
// After filtering, we can assert that there is only the one
100+
// incomplete item in the list.
101+
cy.get('.todo-list li')
102+
.should('have.length', 1)
103+
.first()
104+
.should('have.text', 'Walk the dog');
105+
106+
// For good measure, let's also assert that the task we checked off
107+
// does not exist on the page.
108+
cy.contains('Pay electric bill').should('not.exist');
109+
});
110+
111+
it('can filter for completed tasks', () => {
112+
// We can perform similar steps as the test above to ensure
113+
// that only completed tasks are shown
114+
cy.contains('Completed').click();
115+
116+
cy.get('.todo-list li')
117+
.should('have.length', 1)
118+
.first()
119+
.should('have.text', 'Pay electric bill');
120+
121+
cy.contains('Walk the dog').should('not.exist');
122+
});
123+
124+
it('can delete all completed tasks', () => {
125+
// First, let's click the "Clear completed" button
126+
// `contains` is actually serving two purposes here.
127+
// First, it's ensuring that the button exists within the dom.
128+
// This button only appears when at least one task is checked
129+
// so this command is implicitly verifying that it does exist.
130+
// Second, it selects the button so we can click it.
131+
cy.contains('Clear completed').click();
132+
133+
// Then we can make sure that there is only one element
134+
// in the list and our element does not exist
135+
cy.get('.todo-list li')
136+
.should('have.length', 1)
137+
.should('not.have.text', 'Pay electric bill');
138+
139+
// Finally, make sure that the clear button no longer exists.
140+
cy.contains('Clear completed').should('not.exist');
141+
});
142+
});
143+
});

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"eslint": "^8.0.1",
3131
"eslint-config-prettier": "8.5.0",
3232
"eslint-config-standard": "^17.0.0",
33+
"eslint-plugin-cypress": "^2.12.1",
3334
"eslint-plugin-import": "^2.25.2",
3435
"eslint-plugin-n": "^15.0.0",
3536
"eslint-plugin-promise": "^6.0.0",

0 commit comments

Comments
 (0)