Skip to content

Merge pull request #907 from sanger/dependabot/pip/responses-0.25.0 #446

Merge pull request #907 from sanger/dependabot/pip/responses-0.25.0

Merge pull request #907 from sanger/dependabot/pip/responses-0.25.0 #446

name: Automated build, test, release and push
on:
push:
branches:
- develop
- master
env:
IMAGE_NAME: ${{ github.repository }}/${{ github.event.repository.name }}
jobs:
build_test_release_push:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
ports:
- 3306:3306
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: unified_warehouse_test
steps:
- uses: actions/checkout@v2
- uses: nelonoel/[email protected]
- name: Build and tag the image for testing and release
run: >-
docker build .
--file Dockerfile
--tag docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME}
- name: Create mysql test warehouse database and table
run: >-
docker run
--network host
--entrypoint ''
--env SETTINGS_MODULE=crawler.config.test
docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME}
python setup_test_db.py
- name: Start a testing SFTP server
run: |
docker run -p "3010:22" -v ${PWD}/test:/home/foo -d atmoz/sftp foo:pass:1001
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 4.2
mongodb-replica-set: heron_rs
- name: Run tests against the image
run: >-
docker run
--network host
--entrypoint ''
--env SFTP_SERVER=localhost
--env SFTP_PORT=3010
--env SETTINGS_MODULE=crawler.config.test
docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME}
python -m pytest --no-cov -vx
- name: Set release name
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
run: echo "RELEASE_NAME=$(printf -- '%s%s\n' $(cat .release-version) $([ ${BRANCH_NAME} = "develop" ] && printf -- '-%s-develop' ${GITHUB_RUN_ID} || echo ""))" >> $GITHUB_ENV
- name: Set release tag
run: echo "RELEASE_TAG=v$RELEASE_NAME" >> $GITHUB_ENV
- name: Create release
uses: ncipollo/[email protected]
with:
name: ${{ env.RELEASE_NAME }}
tag: ${{ env.RELEASE_TAG }}
prerelease: ${{ !(github.ref == 'refs/heads/master') }}
commit: ${{ github.sha }}
- name: Login to registry
run: >-
docker login
-u ${{ github.actor }}
-p ${{ secrets.GITHUB_TOKEN }}
docker.pkg.github.com
- name: Tag image with release version
run: >-
docker tag
docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME}
docker.pkg.github.com/${IMAGE_NAME}:${{ env.RELEASE_TAG }}
- name: Push release tag image to registry
run: >-
docker push docker.pkg.github.com/${IMAGE_NAME}:${{ env.RELEASE_TAG }}
- name: Remove old releases
uses: snok/container-retention-policy@v2
with:
image-names: ${{ github.event.repository.name }}/*
cut-off: Four months ago UTC
timestamp-to-use: updated_at
account-type: org
org-name: sanger
keep-at-least: 5
skip-tags: latest
token: ${{ secrets.REMOVE_OLD_IMAGES }}