Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

Commit

Permalink
Convert CircleCI workflows into GH Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Blomqvist authored and ruohola committed Mar 18, 2021
1 parent 339a002 commit 731fdfb
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 83 deletions.
21 changes: 0 additions & 21 deletions .circleci/check_commits.sh

This file was deleted.

24 changes: 0 additions & 24 deletions .circleci/config.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ docker-compose*
.idea/
.vscode/

.circleci/
!.circleci/check_makemessages.sh
.github/
!.github/check_makemessages.sh

.graphqlconfig

Expand Down
21 changes: 21 additions & 0 deletions .github/check_commits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

# CI runs this script to check that there are no extra merge commits
# in the feature branch that is being merged, and that the branch was rebased
# on top of the latest default branch.
# More details: https://stackoverflow.com/q/64435110/9835872

head=$(git remote show origin | awk '/HEAD branch/ {print $NF}')
current="$(git rev-parse HEAD)"

if ! git merge-base --is-ancestor "origin/${head}" "$current"; then
printf "Forgotten to rebase on top of %s.\nExiting with error!\n" "$head"
exit 1
fi

if [ "$(git rev-list --count --merges "origin/${head}..${current}")" -ne 0 ]; then
printf "There are merge commits on the branch.\nExiting with error!\n"
exit 1
fi

echo Branch up-to-date and commits ok.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# shellcheck disable=SC2016 # Backticks are fine in single quotes.

# CircleCI runs this script in the container to verify that makemessages
# CI pipeline runs this script in the container to verify that makemessages
# was run and thus the translation files are all up-to-date.

for path in skole/locale/*; do
Expand All @@ -11,7 +11,7 @@ for path in skole/locale/*; do
cp "skole/locale/$lang/LC_MESSAGES/django.po" "/tmp/$lang.po"
done

python manage.py makemessages --all
python manage.py makemessages --all

for path in skole/locale/*; do
lang=$(basename "$path")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: "3.7"

services:
db-circleci:
container_name: db-circleci
db-ci:
container_name: db-ci
image: postgres:12.4-alpine@sha256:4c493832e4865189e3cab86281a1706a074ea6796b525a7f191b3f48546c25a8
ports:
- "5432:5432"
Expand All @@ -13,17 +13,17 @@ services:
logging:
driver: none

backend-circleci:
container_name: backend-circleci
backend-ci:
container_name: backend-ci
build:
context: ..
dockerfile: Dockerfile
target: circleci
target: ci
args:
dev_requirements: "requirements-dev.txt"
environment:
- DEBUG=1
- SECRET_KEY=skole
- DATABASE_URL=postgres://username:password@db-circleci:5432/skole
- DATABASE_URL=postgres://username:password@db-ci:5432/skole
depends_on:
- db-circleci
- db-ci
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "CI"
on: pull_request
jobs:
build:
name: "Build"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v2
with:
# Checkout the current commit instead of the commit that would get
# made when the PR would be merged, since we want to validate that
# the branch doesn't contain any merge commits and is rebased correctly.
# We also fetch all the objects here so that we can do the comparisons.
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: "Check commits of the PR branch"
run: ./.github/check_commits.sh

- name: "Login to Dockerhub"
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: "Pull the image"
# Avoid caching pull-only images,since pullign is faster than caching in most cases.
run: docker-compose --file .github/docker-compose-ci.yml pull

- name: "Setup Docker layer cache"
uses: satackey/action-docker-layer-caching@v0.0.11
# Don't terminate if fetching from the cache fails.
continue-on-error: true

- name: "Build the image"
run: docker-compose --file .github/docker-compose-ci.yml build

- name: "Run linters, type-check, and tests"
run: >
docker-compose --file .github/docker-compose-ci.yml up --abort-on-container-exit
&& docker cp backend-ci:/home/user/app/coverage.xml .
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
fail_ci_if_error: true
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ USER user
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]


FROM dev AS circleci
FROM dev AS ci

COPY --chown=user:user . .

CMD python manage.py graphql_schema --out=/tmp/compare.graphql && diff schema.graphql /tmp/compare.graphql \
&& ./.circleci/check_makemessages.sh \
&& ./.github/check_makemessages.sh \
&& python manage.py makemigrations --check \
&& isort --check-only --diff . \
&& docformatter --check --recursive --wrap-summaries=88 --wrap-descriptions=88 --pre-summary-newline . \
Expand All @@ -65,7 +65,7 @@ CMD python manage.py graphql_schema --out=/tmp/compare.graphql && diff schema.gr
&& gunicorn --check-config --config=config/gunicorn_conf.py config.wsgi


FROM circleci as prod
FROM ci as prod

# Has to be set to an empty string for it to have no effect.
ENV PYTHONASYNCIODEBUG=
Expand Down
47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Skole Backend 🎓

[![circleci status](https://circleci.com/gh/skoleapp/skole-backend.svg?style=shield&circle-token=7a11678cc5b06b270fa5460f456fd0da8368dae2)](https://circleci.com/gh/skoleapp/skole-backend)
[![ci](https://github.com/skoleapp/skole-backend/actions/workflows/ci.yml/badge.svg)](https://github.com/skoleapp/skole-backend/actions)
[![codecov](https://codecov.io/gh/skoleapp/skole-backend/branch/develop/graph/badge.svg?token=EHHHpM9EJO)](https://codecov.io/gh/skoleapp/skole-backend)
[![mypy checked](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
Expand All @@ -15,32 +15,31 @@ See detailed description for all top-level dependencies in [`dependencies.md`](d

A quick look at the top-level files and directories excluding Git ignored locations.

1. [**`.circleci/`**](.circleci/): Configuration for [CircleCI](https://circleci.com/).
2. [**`.github/`**](.github/): Configuration for [Github Actions](https://github.com/features/actions).
3. [**`.idea/`**](.idea/): [Jetbrains](https://www.jetbrains.com/) editor configuration.
4. [**`config/`**](config/): Configuration for [Django](https://www.djangoproject.com/) project.
5. [**`media/`**](media/): Few media files for testing.
6. [**`skole/`**](skole/): Source code.
7. [**`.dockerignore`**](.dockerignore): List of files ignored by [Docker](https://www.docker.com/).
8. [**`.flake8`**](.flake8): Configuration for [Flake8](https://flake8.pycqa.org/en/latest/).
9. [**`.gitignore`**](.gitignore): List of files ignored by [Git](https://git-scm.com/).
10. [**`.graphqlconfig`**](.graphqlconfig): GraphQL configuration file, used by [JS GraphQL](https://plugins.jetbrains.com/plugin/8097-js-graphql) JetBrains IDE plugin.
11. [**`Dockerfile`**](Dockerfile): Formal instructions for Docker how to build the image for the app.
12. [**`README.md`**](README.md): The file you're reading.
13. [**`dependencies.md`**](dependencies.md): Documentation about the project's top-level dependencies.
14. [**`manage.py`**](manage.py): Auto-generated for a Django project, see [docs](https://docs.djangoproject.com/en/stable/ref/django-admin/).
15. [**`mypy.ini`**](mypy.ini): Configuration for [Mypy](http://mypy-lang.org/).
16. [**`pyproject.toml`**](pyproject.toml): Configuration for various Python tools.
17. [**`requirements-dev.txt`**](requirements-dev.txt): List of top-level development requirements.
18. [**`requirements.lock`**](requirements.lock): Exact pinned versions of production requirements and all peer dependencies.
19. [**`requirements.txt`**](requirements.txt): List of top-level production requirements.
20. [**`schema.graphql`**](schema.graphql): GraphQL schema for noticing schema changes quickly from PRs.
1. [**`.github/`**](.github/): Configuration for [Github Actions](https://github.com/features/actions).
2. [**`.idea/`**](.idea/): [Jetbrains](https://www.jetbrains.com/) editor configuration.
3. [**`config/`**](config/): Configuration for [Django](https://www.djangoproject.com/) project.
4. [**`media/`**](media/): Few media files for testing.
5. [**`skole/`**](skole/): Source code.
6. [**`.dockerignore`**](.dockerignore): List of files ignored by [Docker](https://www.docker.com/).
7. [**`.flake8`**](.flake8): Configuration for [Flake8](https://flake8.pycqa.org/en/latest/).
8. [**`.gitignore`**](.gitignore): List of files ignored by [Git](https://git-scm.com/).
9. [**`.graphqlconfig`**](.graphqlconfig): GraphQL configuration file, used by [JS GraphQL](https://plugins.jetbrains.com/plugin/8097-js-graphql) JetBrains IDE plugin.
10. [**`Dockerfile`**](Dockerfile): Formal instructions for Docker how to build the image for the app.
11. [**`README.md`**](README.md): The file you're reading.
12. [**`dependencies.md`**](dependencies.md): Documentation about the project's top-level dependencies.
13. [**`manage.py`**](manage.py): Auto-generated for a Django project, see [docs](https://docs.djangoproject.com/en/stable/ref/django-admin/).
14. [**`mypy.ini`**](mypy.ini): Configuration for [Mypy](http://mypy-lang.org/).
15. [**`pyproject.toml`**](pyproject.toml): Configuration for various Python tools.
16. [**`requirements-dev.txt`**](requirements-dev.txt): List of top-level development requirements.
17. [**`requirements.lock`**](requirements.lock): Exact pinned versions of production requirements and all peer dependencies.
18. [**`requirements.txt`**](requirements.txt): List of top-level production requirements.
19. [**`schema.graphql`**](schema.graphql): GraphQL schema for noticing schema changes quickly from PRs.

## Development Tips 🚀

- No pull requests can be merged without CircleCI first building and running [`Dockerfile`](Dockerfile) against it.
See the `CMD` of the `circleci` stage for the full list of stuff it runs and validates.
CircleCI also verifies the code style, so there is no need to argue about formatting.
- No pull requests can be merged without CI pipeline first building and running [`Dockerfile`](Dockerfile) against it.
See the `CMD` of the `ci` stage for the full list of stuff it runs and validates.
The CI pipeline also verifies the code style, so there is no need to argue about formatting.

- Use [Google style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html) docstrings.

Expand Down

0 comments on commit 731fdfb

Please sign in to comment.