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

Add workflow without testing model #24

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
23 changes: 14 additions & 9 deletions .github/workflows/test-without-model.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Run Pytest without Model
on:
push:
branches: [develop]
pull_request:
types: [opened, reopened, synchronize, ready_for_review]

env:
WORKING_DIRECTORY: application
Expand Down Expand Up @@ -36,17 +36,22 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
- name: Chekcout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif
- name: Check for model changes
# https://www.ibm.com/docs/ja/aix/7.1?topic=g-grep-command#grep__row-d3e144113
id: check_changes
run: |
BASE_BRANCH=${{ github.base_ref }}
git fetch origin $BASE_BRANCH
MODEL_CHANGED=false
if git diff --name-only origin/$BASE_BRANCH ${{ github.sha }} | grep -q "^${{ env.WORKING_DIRECTORY }}/models/"; then
if git diff --name-only origin/${{ github.base_ref }} | grep -c ${{ env.WORKING_DIRECTORY }}/application/models/ > 0; then
echo $MODEL_CHANGED
MODEL_CHANGED=true
fi
echo $MODEL_CHANGED
echo "MODEL_CHANGED=$MODEL_CHANGED" >> $GITHUB_ENV
- name: Grant privileges to user
run: mysql --protocol=tcp -h 127.0.0.1 -P 3306 -u root -p$MYSQL_ROOT_PASSWORD -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%'; FLUSH PRIVILEGES;"
Expand All @@ -55,15 +60,15 @@ jobs:
with:
working-directory: ${{ env.WORKING_DIRECTORY }}
- name: Run migration
run: |
poetry run python manage.py makemigrations
poetry run python manage.py migrate
run: poetry run python manage.py migrate
- name: Run Pytest Without Model
if: env.MODEL_CHANGED == 'true'
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif
if: env.MODEL_CHANGED == 'false'
run: |
set -o pipefail
poetry run pytest ${{ env.WORKING_DIRECTORY }}/tests/serializers ${{ env.WORKING_DIRECTORY }}/tests/views --junitxml=pytest.xml -x -n auto --cov --no-cov-on-fail --suppress-no-test-exit-code | tee pytest-coverage.txt
- name: Run Pytest
if: env.MODEL_CHANGED == 'true'
run: |
set -o pipefail
poetry run pytest --junitxml=pytest.xml -x -n auto --cov --no-cov-on-fail --suppress-no-test-exit-code | tee pytest-coverage.txt
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# ignore migration files
migrations/
# ignore static files
static/
settings.json
Expand Down
1 change: 1 addition & 0 deletions 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
228 changes: 228 additions & 0 deletions application/application/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# Generated by Django 4.2.1 on 2023-05-14 10:29

import uuid

import django.contrib.auth.models
import django.contrib.auth.validators
import django.core.validators
import django.db.models.deletion
from django.db import migrations, models

import application.utils.customer_storage


class Migration(migrations.Migration):

initial = True

dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
]

operations = [
migrations.CreateModel(
name="Address",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("prefecture", models.CharField(max_length=255)),
("municipalities", models.CharField(max_length=255)),
("house_no", models.CharField(max_length=255)),
("other", models.CharField(blank=True, max_length=255)),
(
"post_no",
models.CharField(
max_length=7,
null=True,
validators=[
django.core.validators.RegexValidator(
"^[0-9]{7}$", "7桁の数字を入力してください。"
)
],
),
),
],
options={
"db_table": "Address",
},
),
migrations.CreateModel(
name="Customer",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("kana", models.CharField(max_length=255)),
("name", models.CharField(max_length=255)),
("birthday", models.DateField()),
(
"phone_no",
models.CharField(
blank=True,
max_length=11,
validators=[
django.core.validators.RegexValidator(
"^[0-9]{11}$", "11桁の数字を入力してください。"
)
],
),
),
(
"address",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="address",
to="application.address",
),
),
],
options={
"db_table": "Customer",
},
),
migrations.CreateModel(
name="CustomerPhoto",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
(
"photo",
models.ImageField(
storage=application.utils.customer_storage.CustomerStorage(),
upload_to="customer_photo",
),
),
(
"customer",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="application.customer",
),
),
],
options={
"db_table": "CustomerPhoto",
},
),
migrations.CreateModel(
name="User",
fields=[
(
"password",
models.CharField(max_length=128, verbose_name="password"),
),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
(
"is_superuser",
models.BooleanField(
default=False,
help_text="Designates that this user has all permissions without explicitly assigning them.",
verbose_name="superuser status",
),
),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
(
"employee_number",
models.CharField(
max_length=8,
unique=True,
validators=[
django.core.validators.RegexValidator("^[0-9]{8}$")
],
verbose_name="社員番号",
),
),
(
"username",
models.CharField(
max_length=150,
unique=True,
validators=[
django.contrib.auth.validators.UnicodeUsernameValidator()
],
),
),
("email", models.EmailField(max_length=254, unique=True)),
(
"role",
models.PositiveIntegerField(
choices=[
(0, "Management"),
(1, "General"),
(2, "Part Time"),
],
default=2,
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"user_permissions",
models.ManyToManyField(
blank=True,
help_text="Specific permissions for this user.",
related_name="user_set",
related_query_name="user",
to="auth.permission",
verbose_name="user permissions",
),
),
],
options={
"db_table": "User",
"ordering": ["employee_number"],
},
managers=[
("objects", django.contrib.auth.models.UserManager()),
],
),
]
Loading
Loading