mirror of
https://github.com/pyTooling/Actions.git
synced 2026-02-12 02:56:56 +08:00
releaser: add option 'use-gh-cli'
This commit is contained in:
1
.github/workflows/TestReleaser.yml
vendored
1
.github/workflows/TestReleaser.yml
vendored
@@ -115,6 +115,7 @@ jobs:
|
||||
uses: ./releaser/composite
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
use-gh-cli: true
|
||||
files: |
|
||||
artifact-*.txt
|
||||
README.md
|
||||
|
||||
@@ -149,9 +149,16 @@ Set option `rm` to `true` for systematically removing previous artifacts (e.g. o
|
||||
|
||||
Whether to create releases from any tag or to treat some as snapshots. By default, all the tags with non-empty `prerelease` field (see [semver.org: Is there a suggested regular expression (RegEx) to check a SemVer string?](https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string)) are considered snapshots; neither a release is created nor assets are uploaded.
|
||||
|
||||
### use-gh-cli
|
||||
|
||||
In order to work around the reliability issues explained in section *Troubleshooting* above, option *use-gh-cli* allows
|
||||
using GitHub's official command line tool ([cli/cli](https://github.com/cli/cli)) for uploading/updating assets.
|
||||
|
||||
IMPORTANT: Using this option requires the repository to be cloned (preferredly through [actions/checkout](https://github.com/actions/checkout)).
|
||||
|
||||
## Advanced/complex use cases
|
||||
|
||||
**Releaser** is essentially a very fine wrapper to use the GitHub Actions context data along with the classes
|
||||
**Releaser** is essentially a very thin wrapper to use the GitHub Actions context data along with the classes
|
||||
and methods of PyGithub.
|
||||
|
||||
Similarly to [actions/github-script](https://github.com/actions/github-script), users with advanced/complex requirements might find it desirable to write their own Python script, instead of using **Releaser**.
|
||||
|
||||
@@ -40,6 +40,10 @@ inputs:
|
||||
description: 'Whether to create releases from any tag or to treat some as snapshots'
|
||||
required: false
|
||||
default: true
|
||||
use-gh-cli:
|
||||
description: 'Whether to use the GitHub CLI for uploading artifacts (requires actions/checkout)'
|
||||
required: false
|
||||
default: false
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
|
||||
@@ -40,6 +40,10 @@ inputs:
|
||||
description: 'Whether to create releases from any tag or to treat some as snapshots'
|
||||
required: false
|
||||
default: true
|
||||
use-gh-cli:
|
||||
description: 'Whether to use the GitHub CLI for uploading artifacts (requires actions/checkout)'
|
||||
required: false
|
||||
default: false
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
@@ -55,3 +59,4 @@ runs:
|
||||
INPUT_TAG: ${{ inputs.tag }}
|
||||
INPUT_RM: ${{ inputs.rm }}
|
||||
INPUT_SNAPSHOTS: ${{ inputs.snapshots }}
|
||||
INPUT_USE-GH-CLI: ${{ inputs.use-gh-cli }}
|
||||
|
||||
@@ -27,6 +27,7 @@ from os import environ, getenv
|
||||
from glob import glob
|
||||
from pathlib import Path
|
||||
from github import Github, GithubException
|
||||
from subprocess import check_call
|
||||
|
||||
|
||||
def GetListOfArtifacts(argv):
|
||||
@@ -104,6 +105,7 @@ def GetReleaseHandler(gh):
|
||||
# is semver compilant prerelease tag, thus a snapshot (we skip it)
|
||||
print("! Skipping snapshot prerelease")
|
||||
sys_exit()
|
||||
|
||||
return (tag, env_tag, True)
|
||||
|
||||
def GetRepositoryHandler(repo):
|
||||
@@ -152,6 +154,12 @@ def UploadArtifacts(gh_release, artifacts):
|
||||
|
||||
assets = gh_release.get_assets()
|
||||
|
||||
def delete_all_assets(assets):
|
||||
print("· RM set. All previous assets are being cleared...")
|
||||
for asset in assets:
|
||||
print(f" - {asset.name}")
|
||||
asset.delete_asset()
|
||||
|
||||
def delete_asset_by_name(name):
|
||||
for asset in assets:
|
||||
if asset.name == name:
|
||||
@@ -188,15 +196,22 @@ def UploadArtifacts(gh_release, artifacts):
|
||||
return
|
||||
print(" - keep")
|
||||
|
||||
UseGitHubCLI = getenv("INPUT_USE-GH-CLI", "false").lower() == 'true'
|
||||
|
||||
if getenv("INPUT_RM", "false") == "true":
|
||||
print("· RM set. All previous assets are being cleared...")
|
||||
for asset in assets:
|
||||
print(f" - {asset.name}")
|
||||
asset.delete_asset()
|
||||
delete_all_assets(assets)
|
||||
else:
|
||||
if not UseGitHubCLI:
|
||||
for asset in assets:
|
||||
replace_asset(artifacts, asset)
|
||||
|
||||
if UseGitHubCLI:
|
||||
env = environ.copy()
|
||||
env["GITHUB_TOKEN"] = environ["INPUT_TOKEN"]
|
||||
cmd = ["gh", "release", "upload", "--clobber", tag] + artifacts
|
||||
print(f" > {' '.join(cmd)}")
|
||||
check_call(cmd, env=env)
|
||||
else:
|
||||
for artifact in artifacts:
|
||||
print(f" > {artifact!s}:\n - uploading...")
|
||||
gh_release.upload_asset(artifact)
|
||||
|
||||
Reference in New Issue
Block a user