Merge pull request #398 from ror-community/dump-index-error-if-extra-dir #210
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: Deploy Dev | |
on: | |
push: | |
branches: | |
- "dev" | |
paths-ignore: | |
- '**docker-compose.yml' | |
- ./github/* | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
env: | |
ELASTIC7_HOST: "localhost" | |
ELASTIC7_PORT: "9200" | |
ELASTIC_PASSWORD: "changeme" | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
LAUNCH_DARKLY_KEY: ${{ secrets.LAUNCH_DARKLY_KEY_DEV }} | |
services: | |
elasticsearch7: | |
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0 | |
env: | |
discovery.type: single-node | |
ES_JAVA_OPTS: -Xms512m -Xmx512m | |
ELASTIC_PASSWORD: changeme | |
xpack.security.enabled: "false" | |
http.cors.enabled: "true" | |
http.cors.allow-origin: "*" | |
ports: | |
- 9200:9200 | |
steps: | |
- name: Checkout ror-api code | |
uses: actions/checkout@v2 | |
with: | |
path: ror-api | |
- name: Checkout ror-data-test | |
uses: actions/checkout@v2 | |
with: | |
repository: ror-community/ror-data-test | |
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
path: ror-data-test | |
- name: Get last data dump name | |
working-directory: ./ror-data-test | |
run: | | |
FILE="$(ls -Art *.zip | tail -n 1)" | |
echo ${FILE%.*} | |
echo "LATEST_DUMP_FILE=${FILE%.*}" >> $GITHUB_ENV | |
- name: Cache dependency | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Set up Python environment | |
uses: actions/setup-python@v2 | |
with: | |
python-version: "3.8" | |
- name: Install requirements | |
working-directory: ./ror-api | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install yapf | |
python manage.py collectstatic --noinput | |
- name: Setup | |
working-directory: ./ror-api | |
run: | | |
python manage.py setup v1.42-2024-02-21-ror-data -t | |
# Dump file temp hard coded for v2 beta | |
# Pulled from ror-data-test per settings.py config | |
- name: Test | |
working-directory: ./ror-api | |
run: | | |
python manage.py test rorapi.tests.tests_unit | |
# TODO fix these tests running in GitHub Action | |
# python manage.py test rorapi.tests_integration | |
# python manage.py test rorapi.tests_functional | |
build: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_RORAPI_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_RORAPI_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: rorcommunity/ror-api:dev | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache | |
deploy: | |
needs: [test, build] | |
runs-on: ubuntu-latest | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Extract variables | |
shell: bash | |
run: | | |
echo "::set-output name=BRANCH::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" | |
echo "::set-output name=TAG::$(git tag --points-at HEAD)" | |
echo "::set-output name=GIT_SHA::$(git rev-parse HEAD)" | |
echo "::set-output name=GIT_SHA_SHORT::$(git rev-parse --short HEAD)" | |
echo "::set-output name=MESSAGE::$(git log --format=%B -n 1 ${{ github.event.after }})" | |
id: extract_variables | |
- name: Checkout terraform config repo | |
uses: actions/checkout@v2 | |
with: | |
# public repo with terraform configuration | |
repository: "ror-community/new-deployment" | |
persist-credentials: false | |
- name: Commit changes to terraform config repository | |
# use go template in terraform config repository to update git sha and tag | |
# commit and push changes to trigger terraform workflow | |
run: | | |
export GIT_SHA=${{ steps.extract_variables.outputs.GIT_SHA_SHORT }} | |
export GIT_TAG=${{ steps.extract_variables.outputs.GIT_TAG }} | |
wget https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz | |
tar -xzvf dockerize-linux-amd64-v0.6.0.tar.gz | |
rm dockerize-linux-amd64-v0.6.0.tar.gz | |
./dockerize -template ror/services/api/_ror-api-dev.auto.tfvars.tmpl:ror/services/api/_ror-api-dev.auto.tfvars | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add ror/services/api/_ror-api-dev.auto.tfvars | |
git commit -m "Adding ror-api git variables for commit ${{ steps.extract_variables.outputs.GIT_SHA }}" | |
- name: Push changes | |
uses: ad-m/github-push-action@v0.6.0 | |
with: | |
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
repository: "ror-community/new-deployment" | |
branch: "refs/heads/master" | |
tags: false | |
- name: Notify Slack | |
uses: edge/simple-slack-notify@master | |
with: | |
channel: "#deployment-updates" | |
color: "good" | |
text: "A new version of the <https://api.dev.ror.org|REST API> is deployed to dev." | |
failure_text: "${env.GITHUB_WORKFLOW} (${env.GITHUB_RUN_NUMBER}) build failed" | |
fields: | | |
[{ "title": "Commit message", "value": "${{ steps.extract_variables.outputs.MESSAGE }}" }, | |
{ "title": "Committed by", "value": "<https://github.com/${{ github.repository }}/commits?author=${{ github.actor }}|${{ github.actor }}>", "short": true }, | |
{ "title": "Commit SHA", "value": "<https://github.com/${{ github.repository }}/commit/${{ steps.extract_variables.outputs.GIT_SHA }}|${{ steps.extract_variables.outputs.GIT_SHA_SHORT }}>", "short": true }, | |
{ "title": "Repository", "value": "<https://github.com/${{ github.repository }}|${{ github.repository }}>", "short": true }, | |
{ "title": "Branch", "value": "<https://github.com/${{ github.repository }}/tree/${{ steps.extract_variables.outputs.BRANCH }}|${{ steps.extract_variables.outputs.BRANCH }}>", "short": true }] |