automatic update of open bus stride db dependencies #157
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
name: CI | |
on: | |
push: | |
pull_request: | |
types: [synchronize, opened, reopened, ready_for_review] | |
jobs: | |
ci: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v2 | |
- env: | |
DOCKER_APP_IMAGE_NAME: "ghcr.io/hasadna/open-bus-stride-api/open-bus-stride-api" | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
HASADNA_K8S_DEPLOY_KEY: ${{ secrets.HASADNA_K8S_DEPLOY_KEY }} | |
SQLALCHEMY_URL: ${{ secrets.SQLALCHEMY_URL }} | |
STRIDE_ETL_DEPLOY_KEY: ${{ secrets.STRIDE_ETL_DEPLOY_KEY }} | |
run: | | |
git clone https://github.com/hasadna/open-bus-stride-db.git ../open-bus-stride-db &&\ | |
pip install -r requirements-dev.txt &&\ | |
pip install -r tests/requirements.txt &&\ | |
pytest &&\ | |
echo "${GITHUB_TOKEN}" | docker login ghcr.io -u hasadna --password-stdin &&\ | |
if docker pull "${DOCKER_APP_IMAGE_NAME}:latest"; then | |
CACHE_FROM_ARG="--cache-from ${DOCKER_APP_IMAGE_NAME}:latest" | |
else | |
CACHE_FROM_ARG="" | |
fi &&\ | |
docker build $CACHE_FROM_ARG --build-arg VERSION=${GITHUB_SHA} -t app . &&\ | |
docker tag app "${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}" &&\ | |
docker push "${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}" &&\ | |
if [ "${GITHUB_REF}" == "refs/heads/main" ]; then | |
docker tag app "${DOCKER_APP_IMAGE_NAME}:latest" &&\ | |
docker push "${DOCKER_APP_IMAGE_NAME}:latest" &&\ | |
if ! git log -1 --pretty=format:"%s" | grep -- --no-deploy; then | |
cd `mktemp -d` &&\ | |
echo "${HASADNA_K8S_DEPLOY_KEY}" > hasadna_k8s_deploy_key &&\ | |
chmod 400 hasadna_k8s_deploy_key &&\ | |
export GIT_SSH_COMMAND="ssh -i `pwd`/hasadna_k8s_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" &&\ | |
git clone git@github.com:hasadna/hasadna-k8s.git &&\ | |
cd hasadna-k8s &&\ | |
python update_yaml.py '{"strideApiImage":"'"${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}"'"}' apps/openbus/values-hasadna-auto-updated.yaml &&\ | |
git config --global user.name "Open Bus Stride API CI" &&\ | |
git config --global user.email "open-bus-stride-api-ci@localhost" &&\ | |
git add apps/openbus/values-hasadna-auto-updated.yaml && git commit -m "automatic update of open bus stride api" &&\ | |
git push origin master &&\ | |
echo "${STRIDE_ETL_DEPLOY_KEY}" > stride_etl_deploy_key &&\ | |
chmod 400 stride_etl_deploy_key &&\ | |
export GIT_SSH_COMMAND="ssh -i `pwd`/stride_etl_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" &&\ | |
git clone git@github.com:hasadna/open-bus-stride-etl.git &&\ | |
cd open-bus-stride-etl &&\ | |
echo "${GITHUB_SHA}" > stride-api-latest-commit.txt &&\ | |
git add stride-api-latest-commit.txt &&\ | |
git commit -m "automatic update of open bus stride api dependencies" &&\ | |
git push origin main | |
fi | |
fi |