-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ba8ec7
commit 4d5569f
Showing
2 changed files
with
98 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: "3" | ||
|
||
services: | ||
nginx: | ||
build: . | ||
working_dir: /app | ||
ports: | ||
- 80:80 | ||
- 443:443 | ||
volumes: | ||
- .:/app | ||
links: | ||
- pgsql | ||
|
||
pgsql: | ||
image: ronasit/postgres:12.5 | ||
ports: | ||
- 5432:5432 | ||
environment: | ||
POSTGRES_PASSWORD: secret | ||
POSTGRES_USER: forge | ||
POSTGRES_DB: forge | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
volumes: | ||
- .:/app | ||
command: ["-c", "fsync=off"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,81 @@ | ||
name: Run tests with coverage | ||
name: TestAndDeploy | ||
|
||
on: | ||
push: | ||
branches: ["master"] | ||
pull_request: | ||
branches: ["master"] | ||
on: push | ||
|
||
jobs: | ||
tests-with-coverage: | ||
runs-on: ubuntu-latest | ||
env: | ||
CI_PROJECT_NAME: sd-simpro-ng-int | ||
CI_DOCKER_REGISTRY_URL: registry.digitalocean.com | ||
CI_CD_REPOSITORY_NAME: RonasIT/sd-simpro-ng-int-dkc | ||
CI_CD_REPOSITORY_EVENT_TYPE: trigger-deployment | ||
|
||
services: | ||
pgsql: | ||
image: postgres:12.5 | ||
env: | ||
POSTGRES_DB: mydb | ||
POSTGRES_USER: myuser | ||
POSTGRES_PASSWORD: mypassword | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 5432:5432 | ||
jobs: | ||
|
||
Tests: | ||
runs-on: ubuntu-latest | ||
env: | ||
COMPOSE_FILE: .github/docker-compose.yml | ||
steps: | ||
- name: Checkout code | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.1' | ||
extensions: pgsql | ||
|
||
- name: Install Dependencies | ||
- name: Prepare .env | ||
run: | | ||
composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist | ||
composer update --with-dependencies | ||
- name: Execute unit tests via PHPUnit with coverage | ||
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml | ||
cp .env.testing .env | ||
- name: Docker-Compose Up | ||
run: | | ||
docker-compose up -d | ||
- name: Prepare Containers | ||
run: | | ||
docker-compose exec -T nginx composer install | ||
docker-compose exec -T nginx php artisan jwt:secret --env=testing | ||
docker-compose exec -T nginx php artisan key:generate --env=testing | ||
- name: Run Tests | ||
run: | | ||
docker-compose exec -T nginx php vendor/bin/phpunit --stop-on-failure ./tests/ | ||
- name: Logs | ||
run: | | ||
docker-compose exec -T nginx cat storage/logs/*.log || true | ||
- name: Upload coverage results to Coveralls | ||
env: | ||
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
Deploy: | ||
runs-on: ubuntu-latest | ||
needs: Tests | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Set Environment | ||
run: | | ||
composer global require php-coveralls/php-coveralls | ||
php-coveralls --coverage_clover=build/logs/clover.xml -v | ||
if ${{ github.ref == 'refs/heads/main' }}; then | ||
echo "CI_PROJECT_ENV_NAME=prod" >> $GITHUB_ENV | ||
CI_PROJECT_ENV_NAME=prod | ||
else | ||
echo "CI_PROJECT_ENV_NAME=dev" >> $GITHUB_ENV | ||
CI_PROJECT_ENV_NAME=dev | ||
fi | ||
echo "CI_DOCKER_IMAGE=$CI_DOCKER_REGISTRY_URL/$CI_PROJECT_NAME/$CI_PROJECT_NAME-$CI_PROJECT_ENV_NAME:${{ github.run_id }}" >> $GITHUB_ENV | ||
- name: Create .env file | ||
run: | | ||
cp .env.$CI_PROJECT_ENV_NAME .env | ||
- name: Set Up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
- name: Set Up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Login To DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: registry.digitalocean.com | ||
username: ${{ secrets.DIGITAL_OCEAN_ACCESS_TOKEN }} | ||
password: ${{ secrets.DIGITAL_OCEAN_ACCESS_TOKEN }} | ||
- name: Build And Push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ env.CI_DOCKER_IMAGE }} | ||
- name: Trigger Deployment | ||
uses: peter-evans/repository-dispatch@v2 | ||
with: | ||
token: ${{ secrets.CI_CD_REPOSITORY_ACCESS_TOKEN }} | ||
repository: ${{ env.CI_CD_REPOSITORY_NAME }} | ||
event-type: ${{ env.CI_CD_REPOSITORY_EVENT_TYPE }} | ||
client-payload: '{"image": "${{ env.CI_DOCKER_IMAGE }}", "env_name": "${{ env.CI_PROJECT_ENV_NAME }}", "project_name": "${{ env.CI_PROJECT_NAME }}"}' |