Skip to content

Commit

Permalink
Auto-update "latest" tag to latest released tag for each image base (#…
Browse files Browse the repository at this point in the history
…102)

* Create update_latest.yaml

* Generalize for all images and make easier for forks

* Add missing env

* Pull latest before inspect
  • Loading branch information
almahmoud authored May 6, 2024
1 parent 738b6e3 commit ea2bea1
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/update_latest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Update latest tag to latest release

on:
workflow_dispatch:
schedule:
- cron: '0 18 * * *'

jobs:
update_latest:
name: "Update latest tag"
strategy:
fail-fast: false
matrix:
image: ['r-ver', 'bioconductor', 'bioconductor_docker', 'tidyverse', 'ml-verse', 'shiny']
runs-on: ubuntu-latest
steps:
- name: Set defaults for schedule
id: defs
run: |
OWNER_REPO="bioconductor"
echo repo="$OWNER_REPO" >> $GITHUB_OUTPUT
echo releasetag=$(curl https://hub.docker.com/v2/repositories/$OWNER_REPO/${{matrix.image}}/tags?page_size=1000 | jq '.results[].name' | tr -d '"' | grep -v "-" | sort -n | grep RELEASE | tail -n 1) >> $GITHUB_OUTPUT
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Dockerhub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Update latest tag
run: |
OWNER_REPO="${{steps.defs.outputs.repo}}"
docker pull $OWNER_REPO/${{matrix.image}}:${{steps.defs.outputs.releasetag}}
docker pull $OWNER_REPO/${{matrix.image}}:latest
IMAGEDIFF=$(diff <(docker inspect $OWNER_REPO/${{matrix.image}}:latest) <(docker inspect $OWNER_REPO/${{matrix.image}}:${{steps.defs.outputs.releasetag}}))
if [ -z "$IMAGEDIFF" ]; then
echo '"latest" tag is already "${{steps.defs.outputs.releasetag}}"'
else
docker tag $OWNER_REPO/${{matrix.image}}:${{steps.defs.outputs.releasetag}} $OWNER_REPO/${{matrix.image}}:latest
docker push $OWNER_REPO/${{matrix.image}}:latest
docker tag $OWNER_REPO/${{matrix.image}}:${{steps.defs.outputs.releasetag}} ghcr.io/$OWNER_REPO/${{matrix.image}}:latest
docker push ghcr.io/$OWNER_REPO/${{matrix.image}}:latest
fi

0 comments on commit ea2bea1

Please sign in to comment.