Clean up feature branch #32
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: Clean up feature branch | |
on: | |
delete: | |
branches: | |
- feature/* | |
env: | |
IMAGE_NAME: ds-wagtail | |
jobs: | |
delete: | |
if: github.event.ref_type == 'branch' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clean up | |
run: | | |
IMAGE_ID=$IMAGE_NAME | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Strip "v" prefix from tag name | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "main" ] && VERSION=latest | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "Clean up Docker image $IMAGE_ID:$VERSION" | |
- name: Delete image | |
uses: bots-house/[email protected] | |
with: | |
owner: nationalarchives | |
name: ${{ env.IMAGE_ID }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ env.VERSION }} |