From 6cf8de253a69570ccaf890a22bf20abd5d6dd6b4 Mon Sep 17 00:00:00 2001 From: Lucy Linder Date: Sat, 6 Jun 2020 20:22:05 +0200 Subject: [PATCH] add option 'rm' (#156) --- .github/workflows/test.yml | 9 +++++---- README.md | 2 ++ action.yml | 4 ++++ tip.py | 30 ++++++++++++++++++------------ 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7cbfb8f..a414425 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,21 +18,22 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - - run: echo "Build some tool and generate some artifacts" > artifact.txt + + - run: echo "Build some tool and generate some (versioned) artifacts" > artifact-$(date -u +"%Y-%m-%dT%H-%M-%SZ").txt - name: Single uses: ./ with: + rm: true token: ${{ secrets.GITHUB_TOKEN }} - files: artifact.txt + files: artifact-*.txt - name: List uses: ./ with: token: ${{ secrets.GITHUB_TOKEN }} files: | - artifact.txt + artifact-*.txt README.md - run: | diff --git a/README.md b/README.md index fb12346..1fc2fec 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,5 @@ jobs: Note that the tag and the pre-release need to be created manually the first time. The workflow above will fail if the release does not exist. The default tag name is `tip`, but it can be optionally overriden through option `tag` or setting envvar `INPUT_TAG`. + +If you systematically want to remove previous artifacts (e.g. old versions), set the `rm` option to true. diff --git a/action.yml b/action.yml index ec6b715..014aa7e 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,10 @@ inputs: description: 'Name of the tag that corresponds to the tip/nightly pre-release' required: false default: tip + rm: + description: 'Whether to delete all the previous artifacts, or only replacing the ones with the same name' + required: false + default: false runs: using: 'docker' image: 'Dockerfile' diff --git a/tip.py b/tip.py index 2f4ca79..dc33e60 100755 --- a/tip.py +++ b/tip.py @@ -68,18 +68,24 @@ print("· Upload artifacts") artifacts = files -for asset in gh_release.get_assets(): - print(">", asset) - print(" ", asset.name) - for artifact in artifacts: - aname = str(Path(artifact).name) - if asset.name == aname: - print(" removing '%s'..." % asset.name) - asset.delete_asset() - print(" uploading '%s'..." % artifact) - gh_release.upload_asset(artifact, name=aname) - artifacts.remove(artifact) - break +if getenv('INPUT_RM', 'false') == 'true': + print("· RM set. All previous assets are being cleared...") + for asset in gh_release.get_assets(): + print(" ", asset.name) + asset.delete_asset() +else: + for asset in gh_release.get_assets(): + print(">", asset) + print(" ", asset.name) + for artifact in artifacts: + aname = str(Path(artifact).name) + if asset.name == aname: + print(" removing '%s'..." % asset.name) + asset.delete_asset() + print(" uploading '%s'..." % artifact) + gh_release.upload_asset(artifact, name=aname) + artifacts.remove(artifact) + break for artifact in artifacts: print(" uploading '%s'..." % artifact)