Automatically release latest snap when building a tag

This commit is contained in:
Safihre
2022-01-08 10:03:09 +01:00
parent 4d237c4328
commit 94de00b14c
2 changed files with 87 additions and 1 deletions

View File

@@ -141,4 +141,22 @@ jobs:
name: macOS binary (not notarized)
- name: Prepare official release
if: env.AUTOMATION_GITHUB_TOKEN && startsWith(github.ref, 'refs/tags/')
run: python3 builder/package.py release
run: python3 builder/package.py release
release_snap:
name: Release Snap
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
env:
SNAP_TOKEN: ${{ secrets.SNAP_TOKEN }}
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Release latest available Snap
run: |
sudo snap install snapcraft --classic
echo "${SNAP_TOKEN}" | snapcraft login --with -
python3 snap/local/release_snap.py

View File

@@ -0,0 +1,68 @@
#!/usr/bin/python3 -OO
# Copyright 2007-2022 The SABnzbd-Team <team@sabnzbd.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
Automatically release the latest "edge" snap.
This might not be the latest commit, but it will have to do.
"""
import subprocess
from typing import List
def run_external_command(command: List[str]) -> str:
"""Wrapper to ease the use of calling external programs"""
process = subprocess.Popen(command, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, _ = process.communicate()
ret = process.wait()
if output:
print(output)
if ret != 0:
raise RuntimeError("Command returned non-zero exit code %s!" % ret)
return output
# Read the current status
snap_status = run_external_command(["snapcraft", "status", "sabnzbd"])
if not snap_status:
raise ValueError("No information to parse")
# To store the version
arch = None
# Parse line-by-line
for line in snap_status.splitlines():
split_line = line.split()
# First line has 1 extra word
if "latest" in split_line:
split_line.remove("latest")
# Only care for the lines that have the revision and the arch
if len(split_line) == 4:
arch = split_line[0]
if arch not in ("amd64", "arm64", "armhf"):
# Don't care about this arch
arch = None
# Line that has the channel and the revision, but not the arch
if len(split_line) == 3:
# Do we have an arch that we care about?
if arch and split_line[0] == "edge":
# Release this version
run_external_command(["snapcraft", "release", "sabnzbd", split_line[2], "stable"])