Skip to content

Commit

Permalink
feat: Add workflow to create pre-release on version change
Browse files Browse the repository at this point in the history
This commit introduces a new workflow file `beta-release.yml` that runs on the `v3-alpha` branch. The workflow checks for changes in the package version and creates a pre-release if the version has changed. It uses GitHub Actions, Node.js, and the `actions/checkout`, `actions/setup-node`, and `curl` actions to handle the required steps.

The workflow performs the following steps:
- Checks out the code
- Sets up Node.js
- Installs dependencies
- Retrieves the previous and current package versions
- Compares the versions and determines if a pre-release is needed
- Creates a pre-release using the GitHub API if needed
  • Loading branch information
realashleybailey committed Aug 24, 2023
1 parent 186b088 commit 5086ece
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 27 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/beta-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Create Pre-Release on Version Change

on:
push:
branches:
- v3-alpha

jobs:
check-version-and-create-release:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install dependencies
run: npm install

- name: Get previous package version
id: get_prev_version
run: echo "::set-output name=prev_version::$(git show HEAD^:package.json | jq -r '.version')"

- name: Get current package version
id: get_current_version
run: echo "::set-output name=current_version::$(jq -r '.version' package.json)"

- name: Compare versions
id: compare_versions
run: |
if [[ "${{ steps.get_prev_version.outputs.prev_version }}" != "${{ steps.get_current_version.outputs.current_version }}" ]]; then
echo "Version changed. Creating Pre-Release."
echo "::set-output name=version_changed::true"
else
echo "Version unchanged. No Pre-Release needed."
echo "::set-output name=version_changed::false"
fi
- name: Create Pre-Release
if: steps.compare_versions.outputs.version_changed == 'true'
run: |
# Create a new Pre-Release using GitHub API
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/:owner/:repo/releases -d '{"tag_name": "v${{ steps.get_current_version.outputs.current_version }}", "prerelease": true, "draft": false}'
4 changes: 3 additions & 1 deletion .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Build and push Docker image

on:
push:
push:
branches:
- v3-alpha

env:
REGISTRY: ghcr.io
Expand Down
11 changes: 11 additions & 0 deletions app/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def scan_users():
info("Scanning for new users")
global_sync_users()

@schedule.task("interval", id="checkForUpdates", minutes=10, misfire_grace_time=900)
def check_for_updates():
# Import the function here to avoid circular imports
from app.utils.software_lifecycle import need_update
from app import app

info("Checking for updates")

# Update jinja global variable
app.jinja_env.globals.update(APP_UPDATE=need_update())



# Ignore these helper functions they need to be moved to a different file
Expand Down
7 changes: 5 additions & 2 deletions app/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ def user_identity_lookup(user):

def user_lookup_callback(_jwt_header, jwt_data):
identity = jwt_data["sub"]
user = Accounts.get_by_id(identity)
return model_to_dict(user, recurse=True, backrefs=True, exclude=[Accounts.password])
try:
user = Accounts.get_by_id(identity)
return model_to_dict(user, recurse=True, backrefs=True, exclude=[Accounts.password])
except Exception:
return None

def is_setup_required():
return not server_verified()
Expand Down
4 changes: 0 additions & 4 deletions app/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

{% block main %}

{% if APP_UPDATE %}
{% include 'templates/update.html' %}
{% endif %}

{% include 'templates/menu.html' %}

<div id="content" class="max-w-screen-xl mx-auto mt-[64px]">
Expand Down
2 changes: 2 additions & 0 deletions app/templates/base.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<span class="ml-2">Please wait...</span>
</div>

{% include 'templates/update.html' %}

</body>

</html>
2 changes: 2 additions & 0 deletions app/templates/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<span class="ml-2">Please wait...</span>
</div>

{% include 'templates/update.html' %}

</body>

</html>
36 changes: 18 additions & 18 deletions app/templates/templates/update.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<div class="z-50 fixed left-0 bottom-0 p-4 ">
<a href="https://github.com/wizarrrr/wizarr">
<div class="w-full max-w-xl p-6 mt-auto ml-auto bg-slate-700 rounded ">
<div class="flex items-start justify-between -mx-2">
<div class="flex items-start px-2">
<span class="flex-shrink-0">
<svg width="24" height="21" viewBox="0 0 24 21" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12.0005 15C11.8027 15 11.6093 15.0587 11.4449 15.1686C11.2804 15.2784 11.1523 15.4346 11.0766 15.6173C11.0009 15.8001 10.9811 16.0011 11.0197 16.1951C11.0583 16.3891 11.1535 16.5673 11.2933 16.7071C11.4332 16.847 11.6114 16.9422 11.8054 16.9808C11.9993 17.0194 12.2004 16.9996 12.3831 16.9239C12.5659 16.8482 12.722 16.72 12.8319 16.5556C12.9418 16.3911 13.0005 16.1978 13.0005 16C13.0005 15.7348 12.8951 15.4805 12.7076 15.2929C12.52 15.1054 12.2657 15 12.0005 15ZM22.6705 16.47L14.6205 2.47003C14.3603 2.00354 13.9802 1.61498 13.5196 1.3445C13.0591 1.07401 12.5346 0.931396 12.0005 0.931396C11.4663 0.931396 10.9419 1.07401 10.4813 1.3445C10.0207 1.61498 9.64065 2.00354 9.38046 2.47003L1.38046 16.47C1.11125 16.924 0.966598 17.441 0.9611 17.9688C0.955602 18.4966 1.08945 19.0166 1.34914 19.4761C1.60883 19.9356 1.98516 20.3185 2.44014 20.5861C2.89512 20.8536 3.41264 20.9964 3.94046 21H20.0605C20.5925 21.0053 21.1164 20.8689 21.5784 20.6049C22.0403 20.341 22.4238 19.9589 22.6894 19.4978C22.9551 19.0368 23.0933 18.5134 23.09 17.9814C23.0866 17.4493 22.9418 16.9277 22.6705 16.47ZM20.9405 18.47C20.8528 18.626 20.7249 18.7556 20.5701 18.8453C20.4154 18.935 20.2393 18.9815 20.0605 18.98H3.94046C3.76157 18.9815 3.58556 18.935 3.43077 18.8453C3.27599 18.7556 3.14811 18.626 3.06046 18.47C2.97269 18.318 2.92648 18.1456 2.92648 17.97C2.92648 17.7945 2.97269 17.622 3.06046 17.47L11.0605 3.47003C11.1444 3.30623 11.2719 3.16876 11.4289 3.07277C11.5859 2.97678 11.7664 2.92599 11.9505 2.92599C12.1345 2.92599 12.315 2.97678 12.472 3.07277C12.629 3.16876 12.7565 3.30623 12.8405 3.47003L20.8905 17.47C20.9897 17.6199 21.0467 17.7937 21.0555 17.9732C21.0643 18.1527 21.0245 18.3312 20.9405 18.49V18.47ZM12.0005 7.00003C11.7352 7.00003 11.4809 7.10538 11.2933 7.29292C11.1058 7.48046 11.0005 7.73481 11.0005 8.00003V12C11.0005 12.2652 11.1058 12.5196 11.2933 12.7071C11.4809 12.8947 11.7352 13 12.0005 13C12.2657 13 12.52 12.8947 12.7076 12.7071C12.8951 12.5196 13.0005 12.2652 13.0005 12V8.00003C13.0005 7.73481 12.8951 7.48046 12.7076 7.29292C12.52 7.10538 12.2657 7.00003 12.0005 7.00003Z" fill="#FFC107"></path>
</svg>
</span>
<div class="ml-2">
<h5 class="text-gray-100 font-semibold">{{
_("Attention!") }}</h5>
<span class="text-xs font-medium text-gray-300">{{ _("Update available. Click here.") }}</span>
</div>
<div id="update-needed" class="z-50 absolute inset-0 flex items-center justify-center bg-gray-700 transition-opacity text-white flex flex-col space-y-2 {% if not APP_UPDATE %}hidden{% endif %}">
<div class="flex flex-col items-center justify-center w-full md:w-2/3 lg:w-4/12 py-8 md:mx-auto md:container px-2 sm:px-4 md:px-0">
<div class="relative w-full bg-white rounded shadow dark:border dark:bg-gray-800 dark:border-gray-700">
<div class="p-6 space-y-4 sm:p-8 text-gray-900 dark:text-white">
<span class="flex justify-center">
<i class="fas fa-exclamation-triangle text-5xl text-yellow-400"></i>
</span>
<div class="flex flex-col items-center justify-center space-y-1">
<h1 class="text-3xl font-semibold text-center text-gray-900 dark:text-white">{{ _("Update Required") }}</h1>
<p class="text-center">{{ _("Wizarr requires an update before you can continue.") }}</p>
</div>
<div class="px-2">

<div class="flex justify-center mt-6 space-x-2">
<button onclick="window.location.reload()" class="bg-primary hover:bg-primary_hover focus:outline-none text-white font-medium rounded px-5 py-2.5 text-sm dark:bg-primary dark:hover:bg-primary_hover">{{ _("Reload") }}</button>
</div>
<span class="flex justify-center" style="margin-top: 10px">
<button id="ignoreUpdate" onclick="document.getElementById('update-needed').classList.add('hidden')" class="text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300">
{{ _("Ignore") }}
</button>
</span>
</div>
</div>
</a>
</div>
</div>
9 changes: 8 additions & 1 deletion app/utils/software_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ def get_latest_version():
response = get(url, timeout=10)
return parse(response.content.decode("utf-8"))

def get_latest_beta_version():
url = "https://api.github.com/repos/wizarrrr/wizarr/releases"
response = get(url, timeout=10)
releases = response.json()
latest_beta = [release["tag_name"] for release in releases if release["prerelease"]][0]
return parse(latest_beta)

def get_current_version():
package = path.abspath(path.join(path.dirname(__file__), "../", "../", "package.json"))
with open(package, "r", encoding="utf-8") as f:
Expand Down Expand Up @@ -40,7 +47,7 @@ def is_stable():

def need_update():
current_version = get_current_version()
latest_version = get_latest_version()
latest_version = is_beta() and get_latest_beta_version() or get_latest_version()
update = False

try:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Wizarr",
"version": "3.0.0",
"version": "3.0.2",
"description": "Wizarr is a web application that allows you to share your media library with your friends and family with ease.",
"scripts": {
"server:start": "APP_URL=127.0.0.1:5000 flask run",
Expand Down

0 comments on commit 5086ece

Please sign in to comment.