Merge pull request #439 from sanger/develop #205
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 build of project and release creation | |
on: | |
push: | |
branches: | |
- master | |
- develop | |
paths-ignore: | |
- "README.md" | |
env: | |
IMAGE_NAME: ${{ github.repository }}/${{ github.event.repository.name }} | |
jobs: | |
build_and_test_job: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: nelonoel/[email protected] | |
- name: Build the Docker image | |
run: >- | |
docker build . | |
--file Dockerfile | |
--tag docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME} | |
- name: Run rubocop against the image | |
run: >- | |
docker run | |
--network host | |
docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME} | |
bundle exec rubocop | |
- name: Run tests against the image | |
run: >- | |
docker run | |
--network host | |
docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME} | |
bundle exec rspec | |
- name: Set release tag | |
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable | |
# On the develop branch this might create RELEASE_VERSION=2.4.6-987654321-develop | |
# On the master branch this would then only create RELEASE_VERSION=2.4.6 | |
run: echo "RELEASE_VERSION=$(printf -- '%s%s\n' $(cat .release-version) $([ ${BRANCH_NAME} = "develop" ] && printf -- '-%s-develop' ${GITHUB_RUN_ID} || echo ""))" >> $GITHUB_ENV | |
- name: Create release | |
uses: ncipollo/[email protected] | |
with: | |
name: ${{ env.RELEASE_VERSION }} | |
tag: v${{ env.RELEASE_VERSION }} | |
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_VERSION }} | |
- name: Push release tag image to registry | |
run: >- | |
docker push | |
docker.pkg.github.com/${IMAGE_NAME}:${{ env.RELEASE_VERSION }} | |
- 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" | |
token: ${{ secrets.REMOVE_OLD_IMAGES }} |