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 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - 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 - name: Single
uses: ./ uses: ./
with: with:
rm: true
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
files: artifact.txt files: artifact-*.txt
- name: List - name: List
uses: ./ uses: ./
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
files: | files: |
artifact.txt artifact-*.txt
README.md README.md
- run: | - 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. 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`. 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' description: 'Name of the tag that corresponds to the tip/nightly pre-release'
required: false required: false
default: tip 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: runs:
using: 'docker' using: 'docker'
image: 'Dockerfile' image: 'Dockerfile'

30
tip.py
View File

@@ -68,18 +68,24 @@ print("· Upload artifacts")
artifacts = files artifacts = files
for asset in gh_release.get_assets(): if getenv('INPUT_RM', 'false') == 'true':
print(">", asset) print("· RM set. All previous assets are being cleared...")
print(" ", asset.name) for asset in gh_release.get_assets():
for artifact in artifacts: print(" ", asset.name)
aname = str(Path(artifact).name) asset.delete_asset()
if asset.name == aname: else:
print(" removing '%s'..." % asset.name) for asset in gh_release.get_assets():
asset.delete_asset() print(">", asset)
print(" uploading '%s'..." % artifact) print(" ", asset.name)
gh_release.upload_asset(artifact, name=aname) for artifact in artifacts:
artifacts.remove(artifact) aname = str(Path(artifact).name)
break 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: for artifact in artifacts:
print(" uploading '%s'..." % artifact) print(" uploading '%s'..." % artifact)