Skip to content

Merge pull request #395 from sanger/dependabot/npm_and_yarn/multi-36d… #161

Merge pull request #395 from sanger/dependabot/npm_and_yarn/multi-36d…

Merge pull request #395 from sanger/dependabot/npm_and_yarn/multi-36d… #161

name: Build, test and release
on:
push:
branches:
- develop
- main
env:
IMAGE_NAME: ${{ github.repository }}/${{ github.event.repository.name }}
jobs:
build_test_and_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: nelonoel/branch-name@v1.0.1
- 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: Run tests against the image
run: >-
docker run
--network host
docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME}
npm test run
- 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 main 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/main') }}
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 }}