ghcr-delete-image-action icon indicating copy to clipboard operation
ghcr-delete-image-action copied to clipboard

Not able to delete multiple tags using the action

Open TaniyaVincent opened this issue 2 years ago • 3 comments

I want to pass the list of tags to be deleted as a text file. Currently, I am able to pass only one tag. Is there a way I can give multiple tags as input in this action?

      tag: '${{ steps.package.outputs.content }}'           

TaniyaVincent avatar May 30 '22 21:05 TaniyaVincent

A workaround is to use a matrix job, you can take a list of the tags and pass it to jq to convert to a json array:

  generate-delete-docker-images-matrix:
    outputs:
      matrix: ${{ steps.matrix.outputs.tags }}
    steps:
.... <earlier step uses docker/metadata-action to generate tags>
      -
        name: Generate matrix
        id: matrix
        run: |
          TAGS="$(echo "${{ steps.generate-docker-metadata.outputs.tags }}" | jq -c --raw-input 'split(",")')"
          echo "tags=${TAGS}" >> ${GITHUB_OUTPUT}

  delete-docker-images:
    needs: generate-delete-docker-images-matrix
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        tag: ${{ fromJSON(needs.generate-delete-docker-images-matrix.outputs.matrix) }}
    steps:
      - name: Delete image
        uses: bots-house/[email protected]
        with:
          owner: ${{ github.repository_owner }}
          name: ${{ github.event.repository.name }}
          token: ${{ secrets.GITHUB_TOKEN }}
          tag: ${{ matrix.tag }}

electrofelix avatar Nov 03 '22 12:11 electrofelix

@TaniyaVincent Is the workaround sufficient for your use case? Can we close this ticket?

vlussenburg avatar Feb 23 '23 20:02 vlussenburg

I fixed this in a new project. https://github.com/dataaxiom/ghcr-cleanup-action which also supports untagging, so it doesn't delete the image if there are still tags on it.

rohanmars avatar May 13 '24 00:05 rohanmars