chore: add missing echo commands #3
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
# This workflow will install Python dependencies, run tests and lint with a single version of Python | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: Django Book API | |
on: | |
push: | |
branches: [ master ] | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
# install python dependencies | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
# format code with autopep8 | |
- name: autopep8 | |
uses: peter-evans/autopep8@v1 | |
with: | |
args: --recursive --in-place --aggressive --aggressive . | |
# create a pull request if autopep8 made changes | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
commit-message: autopep8 action fixes | |
title: Fixes by autopep8 action | |
body: This is an auto-generated PR with fixes by autopep8. | |
labels: autopep8, automated pr | |
reviewers: abu271 | |
branch: autopep8-patches | |
# lint code with flake8 | |
- name: Lint with flake8 | |
run: cd app && flake8 | |
# upload artifacts | |
- name: Upload math result for job 1 | |
uses: actions/upload-artifact@v3 | |
with: | |
name: bookapi-artifact | |
path: | | |
app/ | |
Dockerfile | |
docker-compose.yml | |
requirements.txt | |
version.txt | |
retention-days: 1 | |
test: | |
name: Unit Tests | |
runs-on: ubuntu-latest | |
needs: build | |
# create docker postgres container for testing | |
services: | |
postgres: | |
image: postgres:12.3-alpine | |
env: | |
POSTGRES_DB: github-workflow | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: superpassword | |
ports: | |
- 5432:5432 | |
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
steps: | |
# download artifacts | |
- name: Download artifact from Build | |
uses: actions/download-artifact@v3 | |
with: | |
name: bookapi-artifact | |
# install python dependencies | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
# run python tests | |
- name: Run test | |
run: cd app && python manage.py test | |
env: | |
SYSTEM_ENV: GITHUB_WORKFLOW | |
push_docker: | |
name: Push to Docker Hub | |
runs-on: ubuntu-latest | |
needs: [test, build] | |
steps: | |
# download artifacts | |
- name: Download artifact from Build | |
uses: actions/download-artifact@v3 | |
with: | |
name: bookapi-artifact | |
# build & upload docker image | |
- name: Docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Extract version and set it to TAG env var | |
run: | | |
echo "TAG=$(cat version.txt)" >> $GITHUB_ENV | |
- name: Build Docker image | |
run: | | |
docker build -t bookapi_v${{ env.TAG }} . | |
docker tag bookapi_v${{ env.TAG }} ${{ secrets.DOCKER_USER }}/octo:bookapi_v${{ env.TAG }} | |
- name: Upload Docker image to Docker Hub | |
run: docker push ${{ secrets.DOCKER_USER }}/octo:bookapi_v${{ env.TAG }} | |