Merge pull request #532 from sanger/dependabot/pip/mypy-1.14.1 #178
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: Automated release and build | |
on: | |
push: | |
branches: | |
- develop | |
- master | |
env: | |
IMAGE_NAME: ${{ github.repository }}/${{ github.event.repository.name }} | |
jobs: | |
build_test_release_push: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres | |
ports: | |
- 5432:5432 | |
env: | |
POSTGRES_USER: "postgres" | |
POSTGRES_PASSWORD: "postgres" | |
POSTGRES_DB: "baracoda_test" | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 20s | |
--health-timeout 10s | |
--health-retries 5 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: nelonoel/branch-name@v1.0.1 | |
- name: Build and tag the image for testing | |
run: >- | |
docker build . | |
--file Dockerfile | |
--tag docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME} | |
- name: Run tests against the image | |
run: >- | |
docker run | |
--network host | |
--env SETTINGS_PATH=config/test.py | |
--entrypoint="" | |
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 | |
# On the develop branch this might create RELEASE_NAME=2.4.6-987654321-develop | |
# On the master branch this would then only create RELEASE_NAME=2.4.6 | |
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/release-action@v1.8.8 | |
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, *[!develop] # This will DELETE any images where the tag contains ANY characters in "develop", excluding '!' | |
token: ${{ secrets.REMOVE_OLD_IMAGES }} |