add option 'rm' (#156)

This commit is contained in:
Lucy Linder
2020-06-06 20:22:05 +02:00
committed by GitHub
parent 65fae902fc
commit 6cf8de253a
4 changed files with 29 additions and 16 deletions

View File

@@ -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: |

View File

@@ -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.

View File

@@ -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'

30
tip.py
View File

@@ -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)