Przejdź do treści

Zadanie 1. Continuous Integration

1. Prosty lokalny pipeline

Celem zadania jest stworzenie pipeline do obsługi gotowej, działającej aplikacji.

1.1. Utwórz plik powłoki pipeline.sh

1.2. Dodaj do niego następujące polecenia

#!/bin/bash

cd main
composer install
ret=$?
if [ $ret != 0 ]
then
    exit $ret
fi

composer run tests
ret=$?
if [ $ret != 0 ]
then
    exit $ret
fi
cd ..

1.3. Uruchom pipeline.sh

chmod +x pipeline.sh
./pipeline.sh

2. Przebudowanie obrazów i restart aplikacji

2.1. Dopisz wymagane polecenia do pipeline.sh

docker-compose build
ret=$?
if [ $ret != 0 ]
then
    exit $ret
fi

docker-compose stop
docker-compose create
ret=$?
if [ $ret != 0 ]
then
    exit $ret
fi

docker-compose start
ret=$?
if [ $ret != 0 ]
then
    exit $ret
fi

2.2. Uruchom pipeline.sh

./pipeline.sh

3. Github Actions

3.1. Sklonuj repozytorium na swoim profilu github

lub utwórz nowe puste, niezainicjalizowane repozytorium na swoim profilu github i wykonaj następujące polecenia:

git remote add origin git@github.com:<tu_twoje_repozytorium>
git branch -M main
git push -u origin main

3.2. Utwórz plik .github/workflows/ci.yml

name: Trunk Based development - Continuous Integration
run-name: ${{ github.actor }} is testing out GitHub Actions
on: [push]
jobs:
  Run-CI:
    runs-on: ubuntu-latest
    steps:
      - run: echo "The job was automatically triggered by a ${{ github.event_name }} event."
      - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!"
      - run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
      - name: Check out repository code
        uses: actions/checkout@v3
      - run: echo "The ${{ github.repository }} repository has been cloned to the runner."
      - run: echo " The workflow is now ready to test your code on the runner."
      - name: Install dependencies
        uses: php-actions/composer@v6
        with:
          php_version: '8.1'
          args: '-d main'

      - uses: actions/upload-artifact@v2
        with:
          name: debug-output
          path: output.log

      - name: PHPUnit tests
        uses: php-actions/phpunit@v3
        with:
          bootstrap: main/tests/bootstrap.php
          args: '-v --testdox-html=main/tests/_output/report.html main/tests'
      - uses: actions/upload-artifact@v2
        with:
          name: test-report
          path: main/tests/_output/report.html

      - run: echo "This job's status is ${{ job.status }}."

3.3 Commit

3.4 Push