#14: Improved .yml file x2. #5
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
name: TestAndDeploy | |
on: push | |
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 | |
jobs: | |
Tests: | |
runs-on: ubuntu-latest | |
env: | |
COMPOSE_FILE: .github/docker-compose.yml | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Prepare .env | |
run: | | |
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 | |
Deploy: | |
runs-on: ubuntu-latest | |
needs: Tests | |
if: ${{ github.ref == 'refs/heads/main' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set Environment | |
run: | | |
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 }}"}' |