Negative pattern match for lftp remove

278 Views Asked by At

In a GitHub action, I'd like to remove the old bundle files from the FTP server after deploying the new bundle. To achieve this, I thought to

  1. Deploy new bundle
  2. Parse the hashes of (main-\*.js, polyfills-\*.js etc)
  3. Remove all matching files except the ones with the new hash

For (3), I intended using lftp with mrm main-*.!(328276e83108ad3616fd).js. Yet, this does not seem to match the expected pattern by lftp. Shopts exglob is activated in the parent shell, yet I fear this has no impact on lftp.

Any hints on how to achieve above goal are highly appreciated. Thanks!

1

There are 1 best solutions below

2
On

You need to enable extended globbing for it work https://www.linuxjournal.com/content/bash-extended-globbing

The problem is that this github action doesn't enable it in the alpine docker file so you will need to write your own to do as such

The easiest way to figure this out for you is to fork the repo and create a PR to support it into the StephanThierry/ftp-delete-action repo, and in the mean time use the forked repo in your pipeline

Once you fork repo then edit this file https://github.com/StephanThierry/ftp-delete-action/blob/master/Dockerfile

  RUN apk --no-cache add lftp bash # adds bash to support shopt extglob

  RUN: shopt -s extglob # enables extended globbing

Then create a new version of the branch after you merge that into your fork and use that new branch as the action in your workflow