diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index b4a66db..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: ci -on: - push: - branches: - - master -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: 3.x - - run: pip install mkdocs-material mkdocs-jupyter - - run: mkdocs gh-deploy --force diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..aaa0a71 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,83 @@ +name: cicd + +on: + push + +env: + POSTGRES_DBNAME: postgres + POSTGRES_USER: postgres + POSTGRES_PWD: postgres + POSTGRES_HOST: 127.0.0.1 + POSTGRES_PORT: 15434 + +jobs: + tests: + name: Django Tests + runs-on: ubuntu-latest + + services: + postgres: + image: "postgres:15" + env: + POSTGRES_PASSWORD: ${{env.POSTGRES_PWD}} + POSTGRES_USER: ${{env.POSTGRES_USER}} + POSTGRES_DB: ${{env.POSTGRES_DBNAME}} + ports: + - 15434:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python 3.x + uses: actions/setup-python@v4 + with: + python-version: 3.x + + - name: Install and configure Poetry + run: | + INSTALL_PATH="$HOME/.local" + INSTALLATION_SCRIPT="$(mktemp)" + VIRTUALENVS_PATH="{cache-dir}/virtualenvs/#\~/$HOME" + + curl -sSL https://install.python-poetry.org/ --output "$INSTALLATION_SCRIPT" + + POETRY_HOME=$INSTALL_PATH python3 "$INSTALLATION_SCRIPT" --yes --version="1.3.2" + + export PATH="/root/.local/bin:$PATH" + + poetry config virtualenvs.create true + poetry config virtualenvs.in-project true + poetry config virtualenvs.path "$VIRTUALENVS_PATH" + + echo "VENV=.venv/bin/activate" >> "$GITHUB_ENV" + + - name: Install Dependencies + run: | + export PATH="/root/.local/bin:$PATH" + poetry install --no-interaction + + - name: Run Tests + run: | + source $VENV + cd sample_django_project && python manage.py test + + deploy: + name: Deploy to prod + runs-on: ubuntu-latest + + needs: tests + + if: github.ref == 'refs/heads/master' + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.x + - run: pip install mkdocs-material + - run: mkdocs gh-deploy --force diff --git a/docs/testing/7_github_actions.md b/docs/testing/7_github_actions.md index acf8406..d3461ff 100644 --- a/docs/testing/7_github_actions.md +++ b/docs/testing/7_github_actions.md @@ -122,7 +122,7 @@ jobs: ### Results -Once you've commit-pushed your workflow, you can access the actions page of your repository. For example, this knowledge base, also has a continuous integration workflow defined, you can the actions page [here](https://github.com/runtimerevolution/python-knowledge-base/actions). +Once you've commit-pushed your workflow, you can access the actions page of your repository. For example, this knowledge base, also has a continuous integration workflow defined, you can see the actions page [here](https://github.com/runtimerevolution/python-knowledge-base/actions). You can inspect each run individually and see if it's running correctly or not, or if the tests are accusing something wrong.