This repository has been archived by the owner on Jan 17, 2025. It is now read-only.
.github/workflows/cicd.yml #288
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
on: | |
workflow_dispatch: | |
inputs: | |
RUNTESTS: {description: 'Run tests', required: false} | |
push: | |
schedule: [{cron: '1 0 1,15 * *'}] | |
repository_dispatch: | |
env: | |
DOCKER_BUILDKIT: "1" | |
COMPOSE_DOCKER_CLI_BUILD: "1" | |
BUILDKIT_PROGRESS: "plain" | |
NO_SQUASH: "" | |
NONINTERACTIVE: "1" | |
FORCE_ONLINE: "1" | |
RELEASABLE_REPOS: "^corpusops/" | |
RELEASABLE_BRANCHES: "^refs/tags" | |
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME || '__token__' }} | |
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD || '' }} | |
RUNTESTS: ${{ github.event.inputs.RUNTESTS || '1' }} | |
jobs: | |
ci: | |
runs-on: ubuntu-latest | |
if: ( (github.event_name != 'repository_dispatch') | |
||(github.event_name == 'repository_dispatch' && | |
github.event.client_payload.slash_command.sha != '' && | |
contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha))) | |
steps: | |
- uses: actions/checkout@v2 | |
if: github.event_name != 'repository_dispatch' | |
- uses: actions/checkout@v2 | |
if: github.event_name == 'repository_dispatch' | |
name: Fork based /ok-to-test checkout | |
with: {ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'} | |
- name: Set vars | |
run: |- | |
if ( echo "$GITHUB_REF" | egrep -q "${RELEASABLE_BRANCHES}" ) \ | |
&& ( echo "$GITHUB_REPOSITORY" | egrep -q "${RELEASABLE_REPOS}" ) | |
then releasable=true;else releasable=false;fi | |
echo "::set-output name=releasable::$releasable" | |
id: v | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Activate docker experimental | |
run: |- | |
sudo bash -exc "service docker stop;python -c \ | |
\"d='/etc/docker/daemon.json';\ | |
import json;c=json.load(open(d));c['experimental']=True;\ | |
open(d, 'w').write(json.dumps(c))\" | |
systemctl restart docker" | |
- name: Setup env | |
if: ${{ env.RUNTESTS == '1' }} | |
run: |- | |
for i in .env .env.local;do if [ -e $i.test ];then cp -v $i.test $i;fi;done | |
printf "USER_UID=$(id -u)\nUSER_GID=$(id -g)\n">>.env | |
- name: Build dependant docker images if any | |
run: if ( docker compose config|egrep -q build:; );then docker compose build;fi | |
- name: Start stack | |
if: ${{ env.RUNTESTS == '1' }} | |
run: docker compose up -d && docker compose ps -a | |
- name: Test with tox | |
if: ${{ env.RUNTESTS == '1' }} | |
run: |- | |
set -ex | |
http_services="bitwarden" | |
services="db setup $http_services" | |
bash="docker compose exec -T -u app app bash" | |
http_wait() { $bash -exc "/cops_helpers/dockerize -wait http://$1 -timeout 60s"; } | |
# docker compose exec -T db bash -c \ | |
# 'printf "drop schema public cascade;create schema public;"|psql -U $POSTGRES_USER $POSTGRES_DB' | |
# docker compose up -d --force-recreate --no-deps $services | |
for i in $http_services;do http_wait $i;done | |
( while true; do docker ps -a;docker compose logs db bitwarden app;sleep 15;done )& | |
$bash -exc '\ | |
( while !(touch .tox/ready);do echo "app not ready ($(pwd))">&2;sleep 0.5;done \ | |
&& touch .tox/appready )&\ | |
/cops_helpers/dockerize -wait file://$(pwd)/.tox/appready -timeout 180s;' | |
$bash -exc 'tox -e linting,coverage' | |
- name: Setup python | |
if: ${{ steps.v.outputs.releasable == 'true' && env.TWINE_PASSWORD != '' }} | |
uses: actions/setup-python@v2 | |
- name: Install python release tools & make pkgs | |
if: ${{ steps.v.outputs.releasable == 'true' && env.TWINE_PASSWORD != '' }} | |
run: python -m pip install -U --user wheel build twine | |
&& python -m build --sdist --wheel | |
&& twine upload dist/* |