From 020f6f87b42140acc8e0ca5728cab62af348369f Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Sat, 17 Jun 2023 20:37:08 -0400 Subject: [PATCH] Add GitHub workflow for Choco release --- .github/workflows/release-choco.yml | 17 +++++++++++++++++ scripts/publish_choco.py | 7 ++++--- src/WinDynamicDesktop.csproj | 2 +- uwp/Package.appxmanifest | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release-choco.yml diff --git a/.github/workflows/release-choco.yml b/.github/workflows/release-choco.yml new file mode 100644 index 0000000..3db128c --- /dev/null +++ b/.github/workflows/release-choco.yml @@ -0,0 +1,17 @@ +name: Publish to Chocolatey +on: + release: + types: [released] + workflow_dispatch: + inputs: + release_tag: + required: true + description: Tag of release you want to publish + type: string +jobs: + publish: + runs-on: windows-latest # choco can only be run on windows + steps: + - run: python scripts/publish_choco.py ${{ inputs.release_tag || github.event.release.tag_name }} + env: + CHOCO_APIKEY: ${{ secrets.CHOCO_APIKEY }} diff --git a/scripts/publish_choco.py b/scripts/publish_choco.py index 979eac6..fb7ae9e 100644 --- a/scripts/publish_choco.py +++ b/scripts/publish_choco.py @@ -36,11 +36,12 @@ def write_file(filename, contents): with open(filename, 'w', encoding="utf-8") as fileobj: fileobj.write(contents) -r = requests.get("https://api.github.com/repos/t1m0thyj/WinDynamicDesktop/releases/latest") +release_tag = sys.argv[1] if len(sys.argv) > 1 else "latest" +r = requests.get(f"https://api.github.com/repos/t1m0thyj/WinDynamicDesktop/releases/{release_tag}") response = r.json() installer_url = next(a for a in response["assets"] if a["name"].endswith("x86_Setup.exe"))["browser_download_url"] installer_url64 = next(a for a in response["assets"] if a["name"].endswith("x64_Setup.exe"))["browser_download_url"] -package_version = sys.argv[1] if len(sys.argv) > 1 else response["tag_name"][1:] +package_version = response["tag_name"].removeprefix("v") replacers = { "installerChecksum": installer_checksum(response["tag_name"], os.path.basename(installer_url)), "installerUrl": installer_url, @@ -60,6 +61,6 @@ def write_file(filename, contents): write_file(script_filename, old_script) nupkg_filename = f"windynamicdesktop.{package_version}.nupkg" -if input(f"Push {nupkg_filename}? (y/N) ").lower() == "y": +if os.getenv("CI") or input(f"Push {nupkg_filename}? (y/N) ").lower() == "y": subprocess.run(["choco", "push", os.path.join(tempfile.gettempdir(), nupkg_filename), "-s", chocolatey_repo, "-k", os.getenv("CHOCO_APIKEY")]) diff --git a/src/WinDynamicDesktop.csproj b/src/WinDynamicDesktop.csproj index e375f03..27aae79 100644 --- a/src/WinDynamicDesktop.csproj +++ b/src/WinDynamicDesktop.csproj @@ -9,7 +9,7 @@ WinDynamicDesktop WinDynamicDesktop Copyright © 2023 Timothy Johnson - 5.2.1 + 5.3.0 resources\WinDynamicDesktop.ico true true diff --git a/uwp/Package.appxmanifest b/uwp/Package.appxmanifest index f69148f..dc8aef8 100644 --- a/uwp/Package.appxmanifest +++ b/uwp/Package.appxmanifest @@ -1,6 +1,6 @@  - + WinDynamicDesktop Timothy Johnson