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

Trigger build #176

Merged
merged 12 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 32 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
name: Run Tests
# on:
# workflow_run:
# workflows: ["Format Check"]
# types:
# - completed
on:
workflow_run:
workflows: ["Format Check"]
types:
- completed
pull_request:
types: [opened, reopened, edited, synchronize, ready_for_review]

jobs:
run-tests:
runs-on: ubuntu-latest
services:
app:
image: csharp-minitwit:latest
options: --health-cmd='curl -f http://localhost:5000/public || exit 1' --health-interval=10s --health-retries=3 --health-start-period=30s --health-timeout=10s
ports:
- 5000:5000
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Wait for docker
run:
sleep 5

- name: Build Docker image
run: docker build -t csharp-minitwit:latest ./csharp-minitwit

- name: Wait for the service to be healthy
- name: Run Docker container
run: |
until [ "$(docker inspect --format='{{.State.Health.Status}}' app)" == "healthy" ]; do
echo "Waiting for Docker service to be healthy..."
sleep 5
done
docker run -d --name csharp-minitwit -p 5000:8080 csharp-minitwit:latest

- name: Set up Python
uses: actions/setup-python@v4
Expand All @@ -35,12 +33,28 @@ jobs:

- name: Install Python dependencies
run: |
cd ./csharp-minitwit/Tests
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Check Docker Logs
run: docker logs csharp-minitwit

- name: Check Public Endpoint
run: |
status_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/public)
if [ "$status_code" -ne 200 ]; then
echo "Error: $status_code"
exit 1
fi

- name: Run Python tests
env:
BASE_URL: http://localhost:5000
run: |
cd ./Tests
cd ./csharp-minitwit/Tests
pytest minitwit_sim_api_test.py
pytest refactored_minitwit_tests.py

- name: Clean up
run: |
docker stop csharp-minitwit
docker rm csharp-minitwit
Binary file removed csharp-minitwit/Databases/volume/minitwit.db
Binary file not shown.
1 change: 0 additions & 1 deletion csharp-minitwit/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ ENV ASPNETCORE_ENVIRONMENT=${ENVIRONMENT}

COPY --from=build /app/out .
COPY ./Databases/schema.sql ./schema.sql
COPY ./Databases/volume/minitwit.db ./Databases/volume/minitwit.db
COPY ./Services/latest_processed_sim_action_id.txt ./Services/latest_processed_sim_action_id.txt
EXPOSE 5000

Expand Down
13 changes: 13 additions & 0 deletions csharp-minitwit/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@

if (builder.Environment.IsDevelopment())
{
string filePath = connectionString!.Split('=')[1];
string? directoryPath = Path.GetDirectoryName(filePath);

if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);

Check warning on line 52 in csharp-minitwit/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet-format

Possible null reference argument for parameter 'path' in 'DirectoryInfo Directory.CreateDirectory(string path)'.

Check warning on line 52 in csharp-minitwit/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet-format

Possible null reference argument for parameter 'path' in 'DirectoryInfo Directory.CreateDirectory(string path)'.
}

if (!File.Exists(filePath))
{
File.Create(filePath).Close();
}

builder.Services.AddDbContext<MinitwitContext>(options =>
options.UseSqlite(connectionString));
}
Expand Down
2 changes: 2 additions & 0 deletions csharp-minitwit/Tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
requests
4 changes: 4 additions & 0 deletions csharp-minitwit/csharp-minitwit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Databases\volume\" />
</ItemGroup>

</Project>
Loading