Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GH_APP_ID=""
GH_APP_KEY="-----BEGIN RSA PRIVATE KEY-----
Private Key data...
-----END PRIVATE KEY-----"
GH_PAT=""
GDRIVE_MAIN_DIRECTORY_NAME=""
USER_SHARE=""
ENV="" # "LOCAL" or "GCP"
GH_TESTS_REPO_NAME=""
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Icon
# Thumbnails
._*

# Environment variables
.env

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ repos:
types: [python]
language: system
stages: [push]
pass_filenames: false
- id: darglint
name: darglint
entry: poetry run darglint -v 2
Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at hello@artefactory.com. All
reported by contacting the project team at fr-softeng@artefact.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
16 changes: 3 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,6 @@ clean_build:
.PHONY: clean
clean: clean_build clean_docker

.PHONY: github-install
github-install:
if [ -f ./github_install.sh ]; then \
./github_install.sh; \
read -p "The GitHub repository is now initialized. Do you want to delete the file 'github_install.sh' ? (y/n) : " rm_github_install; \
if [ "$${rm_github_install}" == "y" ]; then \
rm github_install.sh; \
else \
echo "Keeping 'github_install.sh' file in repository !"; \
fi; \
else \
echo "Github repository already initialized !"; \
fi;
.PHONY: deploy_gcp
deploy_gcp:
sh examples/cloud_run/deploy.sh
257 changes: 43 additions & 214 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,211 +7,70 @@
[![Python Version](https://img.shields.io/badge/Python-3.9-informational.svg)](#supported-python-versions)
[![Dependencies Status](https://img.shields.io/badge/dependabots-active-informational.svg)](https://github.com/artefactory/github_tests_validator_app}/pulls?utf8=%E2%9C%93&q=is%3Apr%20author%3Aapp%2Fdependabot)

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Security: bandit](https://img.shields.io/badge/security-bandit-informational.svg)](https://github.com/PyCQA/bandit)
[![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-informational?logo=pre-commit&logoColor=white)](https://github.com/artefactory/github_tests_validator_app}/blob/main/.pre-commit-config.yaml)
[![Semantic Versions](https://img.shields.io/badge/%F0%9F%9A%80-semantic%20versions-informational.svg)](https://github.com/artefactory/github_tests_validator_app/releases)
[![Documentation](https://img.shields.io/badge/doc-sphinx-informational.svg)](https://github.com/artefactory/github_tests_validator_app}/tree/main/docs)
[![License](https://img.shields.io/badge/License-MIT-informational.svg)](https://github.com/artefactory/github_tests_validator_app}/blob/main/LICENSE)
[![Releases](https://img.shields.io/badge/%F0%9F%9A%80-semantic%20versions-informational.svg)](https://github.com/artefactory/github_tests_validator_app/releases)

`github_tests_validator_app` is a Python cli/package

</div>

## TL;DR

```bash
pip install git+ssh://git@github.com/artefactory/github_tests_validator_app.git@main
```

## Supported Python Versions

Main version supported : `3.9`

Other supported versions :


## Installation

### Public Package

Install the package from PyPi if it is publicly available :

```bash
pip install -U github_tests_validator_app
```

or with `Poetry`

```bash
poetry add github_tests_validator_app
```

### Private Package

Install the package from a private Github repository from the main branch:

```bash
pip install git+ssh://git@github.com/artefactory/github_tests_validator_app.git@main
```

Or with `Poetry`
`github_tests_validator_app` is a GitHub Application you can deploy on your own to retrieve test results from forked projects.

```bash
poetry add git+ssh://git@github.com/artefactory/github_tests_validator_app.git@main
```
Here is how it works :

Or from a known tag:
![Architecture](docs/architecture.png)

```bash
pip install git+ssh://git@github.com/artefactory/github_tests_validator_app.git@0.1.0
```
The main purpose of this project is for education.

Or from the latest Github Release using [personal access tokens](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)

```bash
# Set the GITHUB_TOKEN environment variable to your personal access token
latest_release_tag=$(curl -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/artefactory/github_tests_validator_app/releases/latest | jq -r ".tag_name")
pip install git+ssh://git@github.com/artefactory/github_tests_validator_app.git@${latest_release_tag}
```
Often, Computer Science teachers can have a main repository and ask their students to fork their repository to complete the courses from their repository.

## Usage
Students never merge their repository into the main one, so it can be tedious for teachers to retrieve informations about the results from their exercices.

Once installed, you can run commands like :

```bash
github_tests_validator_app --help
```

```bash
github_tests_validator_app dialogs hello --name Roman
```
By deploying a GitHub App and asking their students to install this app on their GitHub forked projects, teachers can retrieve automatically the results from their tests (using [pytest](https://docs.pytest.org/en/7.1.x/)) into Google Sheets.

```bash
github_tests_validator_app dialogs clock --color blue
```

or if installed with `Poetry`:

```bash
poetry run github_tests_validator_app --help
```

```bash
poetry run github_tests_validator_app dialogs hello --name Roman
```

or using Docker :

```bash
docker run ghcr.io/artefactory/github_tests_validator_app:0.1.0 --help
```

```bash
docker run ghcr.io/artefactory/github_tests_validator_app:0.1.0 dialogs hello --name Roman
```

## Local setup

If you want to contribute to the development of this package,

1. Clone the repository :

```bash
git clone git@github.com:artefactory/github_tests_validator_app.git
```

2. If you don't have `Poetry` installed, run:

```bash
make download-poetry; export PATH="$HOME/.local/bin:$PATH"
```
</div>

3. Initialize poetry and install `pre-commit` hooks:
## Prerequisites

```bash
make install
```
1) You need to [create a GitHub App](https://docs.github.com/en/developers/apps/building-github-apps/creating-a-github-app) in your organization or personal account on GitHub
2) For GCP cloud run deployment, you may need to install terraform and the gcloud CLI.

And you are ready to develop !
## Deploy locally

### Initial Github setting up
You first need to create a `.env` file by filling up the values from the `.env.template` file.
More details about each of these values [below](#environment-variables-details).

Can be automatically done directly after using the [`cookiecutter` template](https://github.com/artefactory/ppt) :
You can start the GitHub App backend locally with the following command :

```bash
make github-install
docker run -d --rm -p 127.0.0.1:8080:8080 --env-file .env ghcr.io/artefactory/github_tests_validator_app:latest
```

Otherwise, see :
- [Stale bot](https://github.com/apps/stale) for automatic issue closing.
- [GitHub Pages](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site) to deploy your documentation from the `gh-pages` branch.
- [GitHub Branch Protection](https://docs.github.com/en/github/administering-a-repository/about-protected-branches) to secure your `main` branch.
Then you can use [smee.io](https://smee.io/) or [ngrok](https://ngrok.com/) to serve your applications running locally.

### Poetry
## Deploy in the cloud

All manipulations with dependencies are executed through Poetry. If you're new to it, look through [the documentation](https://python-poetry.org/docs/).
With Cloud Run, you have an example terraform configuration [here](https://github.com/artefactory/github_tests_validator_app/blob/main/examples/cloud_run/).

<details>
<summary>Notes about Poetry commands</summary>
<p>

Here are some examples of Poetry [commands](https://python-poetry.org/docs/cli/#commands) :
But you can deploy the application on many Serverless Container services on any cloud by making sure that :
- The secrets defined in the `.env` file are available for the container at runtime as environment variables
- The container can receive HTTP requests
- The container can use a GCP service account to login with the [Python Google Auth client](https://google-auth.readthedocs.io/en/master/)
- The service account is linked to a GCP Project which has the Google Drive API enabled

- `poetry add numpy`
- `poetry run pytest`
- `poetry build`
- etc

</p>
</details>
## Environment variables details

### Building your package
- GH_APP_ID : Auto-generated ID of the GitHub App you created during the [`Prerequisites`](#prerequisites) step.
- GH_APP_KEY : Private Key of the GitHub App you created during the [`Prerequisites`](#prerequisites) step.
- GH_PAT : GitHub personal access token [you must create](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) that has access to the GitHub repository containing the tests and the original repository which was forked (both could be the same repository).
- GDRIVE_MAIN_DIRECTORY_NAME : Name of the Google Drive Folder where you want the stats to be sent.
- USER_SHARE : Comma-separated list of emails that have access to this Google Drive Folder.
- LOGGING : "LOCAL" if you are deploying locally, "GCP" if you are deploying on Google Cloud Run.
- GH_TESTS_REPO_NAME : (Optional, only if you are using a git submodule for the tests folder) Name of the repository containing the tests (could be convenient if you have a repository with the exercices, and another one with the solutions and you want to have the same tests in both repositories by providing a submodule defined in a third repository).

Building a new version of the application contains steps:
## Contributing

- Bump the version of your package `poetry version <version>`. You can pass the new version explicitly, or a rule such as `major`, `minor`, or `patch`. For more details, refer to the [Semantic Versions](https://semver.org/) standard.
- Make a commit to `GitHub`.
- Create a `GitHub release`.
- And... publish only if you want to make your package publicly available on PyPi 🙂 `poetry publish --build`

Packages:

- [`Typer`](https://github.com/tiangolo/typer) is great for creating CLI applications.
- [`Rich`](https://github.com/willmcgugan/rich) makes it easy to add beautiful formatting in the terminal.

## 🚀 Features

- Support for `Python 3.9`
- [`Poetry`](https://python-poetry.org/) as the dependencies manager. See configuration in [`pyproject.toml`](https://github.com/artefactory/github_tests_validator_app}/blob/main/pyproject.toml) and [`setup.cfg`](https://github.com/artefactory/github_tests_validator_app}/blob/main/setup.cfg).
- Power of [`black`](https://github.com/psf/black), [`isort`](https://github.com/timothycrosley/isort) and [`pyupgrade`](https://github.com/asottile/pyupgrade) formatters.
- Ready-to-use [`pre-commit`](https://pre-commit.com/) hooks with formatters above.
- Type checks with [`mypy`](https://mypy.readthedocs.io).
- Testing with [`pytest`](https://docs.pytest.org/en/latest/).
- Docstring checks with [`darglint`](https://github.com/terrencepreilly/darglint).
- Security checks with [`safety`](https://github.com/pyupio/safety), [`bandit`](https://github.com/PyCQA/bandit) and [`anchore`](https://github.com/anchore/scan-action).
- Secrets scanning with [`gitleaks`](https://github.com/zricethezav/gitleaks)
- Well-made [`.editorconfig`](https://github.com/artefactory/github_tests_validator_app}/blob/main/.editorconfig), [`.dockerignore`](https://github.com/artefactory/github_tests_validator_app}/blob/main/.dockerignore), and [`.gitignore`](https://github.com/artefactory/github_tests_validator_app}/blob/main/.gitignore). You don't have to worry about those things.

For building and deployment:

- `GitHub` integration.
- [`Makefile`](https://github.com/artefactory/github_tests_validator_app}/blob/main/Makefile#L89) for building routines. Everything is already set up for security checks, codestyle checks, code formatting, testing, linting, docker builds, etc. More details at [Makefile summary](#makefile-usage)).
- [Dockerfile](https://github.com/artefactory/github_tests_validator_app}/blob/main/docker/Dockerfile) for your package.
- `Github Actions` with predefined [build workflow](https://github.com/artefactory/github_tests_validator_app}/blob/main/.github/workflows/build.yml) as the default CI/CD.
- `Github Packages` with Github Container Registry updated automatically when [releasing the package](https://github.com/artefactory/ppt/blob/main/%7B%7B%20cookiecutter.project_name.lower().replace('%20'%2C%20'_')%20%7D%7D/.github/workflows/cd.yml).
- Automatic drafts of new releases with [`Release Drafter`](https://github.com/marketplace/actions/release-drafter). It creates a list of changes based on labels in merged `Pull Requests`. You can see labels (aka `categories`) in [`release-drafter.yml`](https://github.com/artefactory/github_tests_validator_app}/blob/main/.github/release-drafter.yml). Works perfectly with [Semantic Versions](https://semver.org/) specification.

For creating your open source community:

- Ready-to-use [Pull Requests templates](https://github.com/artefactory/github_tests_validator_app}/blob/main/.github/PULL_REQUEST_TEMPLATE.md) and several [Issue templates](https://github.com/artefactory/github_tests_validator_app}/tree/main/.github/ISSUE_TEMPLATE).
- Files such as: `LICENSE`, `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`, and `SECURITY.md` are generated automatically.
- [`Stale bot`](https://github.com/apps/stale) that closes abandoned issues after a period of inactivity. (You will only [need to setup free plan](https://github.com/marketplace/stale)). Configuration is [here](https://github.com/artefactory/github_tests_validator_app}/blob/main/.github/.stale.yml).
- [Semantic Versions](https://semver.org/) specification with [`Release Drafter`](https://github.com/marketplace/actions/release-drafter).
Check the guide here : [CONTRIBUTING](https://github.com/artefactory/github_tests_validator_app/blob/main/CONTRIBUTING.md)

### Makefile usage

[`Makefile`](https://github.com/artefactory/github_tests_validator_app}/blob/main/Makefile) contains many functions for fast assembling and convenient work.
[`Makefile`](https://github.com/artefactory/github_tests_validator_app/blob/main/Makefile) contains many functions for fast assembling and convenient work.

<details>
<summary>1. Download Poetry</summary>
Expand Down Expand Up @@ -392,43 +251,13 @@ deactivate
</p>
</details>

## 📈 Releases

You can see the list of available releases on the [GitHub Releases](https://github.com/artefactory/github_tests_validator_app}/releases) page.

We follow [Semantic Versions](https://semver.org/) specification.

We use [`Release Drafter`](https://github.com/marketplace/actions/release-drafter). As pull requests are merged, a draft release is kept up-to-date listing the changes, ready to publish when you’re ready. With the categories option, you can categorize pull requests in release notes using labels.

For Pull Requests, these labels are configured, by default:

| **Label** | **Title in Releases** |
| :-----------------------------------: | :---------------------: |
| `enhancement`, `feature` | 🚀 Features |
| `bug`, `refactoring`, `bugfix`, `fix` | 🔧 Fixes & Refactoring |
| `build`, `ci`, `testing` | 📦 Build System & CI/CD |
| `breaking` | 💥 Breaking Changes |
| `documentation` | 📝 Documentation |
| `dependencies` | ⬆️ Dependencies updates |


GitHub creates the `bug`, `enhancement`, and `documentation` labels automatically. Dependabot creates the `dependencies` label. Create the remaining labels on the Issues tab of the GitHub repository, when needed.## 🛡 License

[![License](https://img.shields.io/github/license/artefactory/github_tests_validator_app)](https://github.com/artefactory/github_tests_validator_app}/blob/main/LICENSE)

This project is licensed under the terms of the `MIT` license. See [LICENSE](https://github.com/artefactory/github_tests_validator_app}/blob/main/LICENSE) for more details.## 📃 Citation
<details>
<summary>11. Deploy on GCP</summary>
<p>

```
@misc{github_tests_validator_app,
author = {artefactory},
title = {`github_tests_validator_app` is a Python cli/package},
year = {2022},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/artefactory/github_tests_validator_app}}}
}
```bash
make deploy_gcp
```

## Credits

This project was generated with [`ppt`](https://github.com/artefactory/ppt).
</p>
</details>
3 changes: 1 addition & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
> It is critical that security related issues are reported privately so we have time to address them before they become public knowledge.

Vulnerabilities can be reported by emailing core members:

- artefactory [hello@artefactory.com](mailto:hello@artefactory.com)
- artefactory [fr-softeng@artefact.com](mailto:fr-softeng@artefact.com)

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ RUN poetry install --no-root --only main

COPY . /home/docker_user/workspace/

CMD ["poetry", "run", "python3", "server.py"]
CMD ["poetry", "run", "launch_github_app"]
Loading