Skip to content

Commit

Permalink
[1] Update to using Build Numbers (Kometa-Team#2081)
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 authored and actions-user committed May 29, 2024
1 parent cfc232c commit 866ce01
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 168 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
97 changes: 97 additions & 0 deletions .github/workflows/docker-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Docker Version Release

on:
create:
tags:
- v*

jobs:

docker-build:
if: ${{ startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/tags/v2') }}
runs-on: ubuntu-latest
steps:

- name: Check Out Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT

- name: Build and Push
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: kometateam/kometa:${{ steps.get_version.outputs.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Discord Success Notification
uses: Kometa-Team/discord-notifications@master
if: success()
with:
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
title: "${{ vars.REPO_NAME }} ${{ steps.get_version.outputs.VERSION }}: ${{ vars.TEXT_SUCCESS }}"
url: https://github.com/Kometa-Team/${{ vars.REPO_NAME }}/actions/runs/${{ github.run_id }}
color: ${{ vars.COLOR_SUCCESS }}
username: ${{ vars.BOT_NAME }}
avatar_url: ${{ vars.BOT_IMAGE }}
author: ${{ vars.DOCKER_NAME }}
author_icon_url: ${{ vars.DOCKER_IMAGE }}

- name: Discord Failure Notification
uses: Kometa-Team/discord-notifications@master
if: failure()
with:
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
message: ${{ vars.BUILD_FAILURE_ROLE }}
title: "${{ vars.REPO_NAME }} ${{ steps.get_version.outputs.VERSION }}: ${{ vars.TEXT_FAILURE }}"
url: https://github.com/Kometa-Team/${{ vars.REPO_NAME }}/actions/runs/${{ github.run_id }}
color: ${{ vars.COLOR_FAILURE }}
username: ${{ vars.BOT_NAME }}
avatar_url: ${{ vars.BOT_IMAGE }}
author: ${{ vars.DOCKER_NAME }}
author_icon_url: ${{ vars.DOCKER_IMAGE }}

- name: Checkout Configs Repo
uses: actions/checkout@v4
with:
repository: Kometa-Team/Community-Configs
token: ${{ secrets.PAT }}
path: kometaconfigs

- name: Create & Push Tag
working-directory: ./kometaconfigs
run: |
git tag ${{ steps.get_version.outputs.VERSION }}
git push origin ${{ steps.get_version.outputs.VERSION }}
- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG
token: ${{ secrets.PAT }}
tag_name: ${{ steps.get_version.outputs.VERSION }}
121 changes: 37 additions & 84 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,50 @@
name: Docker Version Release
name: Update Build Version

on:
create:
tags:
- v*
pull_request:
branches: [nightly]
types: [closed]

jobs:

docker-build:
if: ${{ startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/tags/v2') }}
increment-version:
runs-on: ubuntu-latest
if: github.base_ref == 'nightly' && github.event.pull_request.merged
steps:

- name: Check Out Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT

- name: Build and Push
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: kometateam/kometa:${{ steps.get_version.outputs.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Discord Success Notification
uses: Kometa-Team/discord-notifications@master
if: success()
with:
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
title: "${{ vars.REPO_NAME }} ${{ steps.get_version.outputs.VERSION }}: ${{ vars.TEXT_SUCCESS }}"
url: https://github.com/Kometa-Team/${{ vars.REPO_NAME }}/actions/runs/${{ github.run_id }}
color: ${{ vars.COLOR_SUCCESS }}
username: ${{ vars.BOT_NAME }}
avatar_url: ${{ vars.BOT_IMAGE }}
author: ${{ vars.DOCKER_NAME }}
author_icon_url: ${{ vars.DOCKER_IMAGE }}

- name: Discord Failure Notification
uses: Kometa-Team/discord-notifications@master
if: failure()
- name: Create App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
message: ${{ vars.BUILD_FAILURE_ROLE }}
title: "${{ vars.REPO_NAME }} ${{ steps.get_version.outputs.VERSION }}: ${{ vars.TEXT_FAILURE }}"
url: https://github.com/Kometa-Team/${{ vars.REPO_NAME }}/actions/runs/${{ github.run_id }}
color: ${{ vars.COLOR_FAILURE }}
username: ${{ vars.BOT_NAME }}
avatar_url: ${{ vars.BOT_IMAGE }}
author: ${{ vars.DOCKER_NAME }}
author_icon_url: ${{ vars.DOCKER_IMAGE }}
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_TOKEN }}

- name: Checkout Configs Repo
- name: Check Out Repo
uses: actions/checkout@v4
with:
repository: Kometa-Team/Community-Configs
token: ${{ secrets.PAT }}
path: kometaconfigs
token: ${{ steps.app-token.outputs.token }}
ref: nightly
fetch-depth: 0

- name: Create & Push Tag
working-directory: ./kometaconfigs
- name: Update VERSION File
run: |
git tag ${{ steps.get_version.outputs.VERSION }}
git push origin ${{ steps.get_version.outputs.VERSION }}
- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG
token: ${{ secrets.PAT }}
tag_name: ${{ steps.get_version.outputs.VERSION }}
value=$(cat VERSION)
old_msg=$(git log -1 HEAD --pretty=format:%s)
if [[ "$value" == *"-"* ]]; then
build_value="$((${value#*-build} + 1))"
new_value="${value%-build*}-build${build_value}"
new_msg="[${build_value}] ${old_msg}"
elif [[ "$value" == *"!"* ]]; then
new_value="${value%!*}"
new_msg="[${new_value}] ${old_msg}"
else
new_value="${value%-build*}-build1"
new_msg="[1] ${old_msg}"
fi
echo "$new_value" > "VERSION"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add VERSION
git commit -m "${new_msg}" --amend
git push origin nightly --force-with-lease
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1-develop30
-build1
24 changes: 12 additions & 12 deletions kometa.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_env(env_str, default, arg_bool=False, arg_int=False):
final_vars = [f"KOMETA_{arg_key.replace('-', '_').upper()}"] + [f"KOMETA_{a.replace('-', '_').upper()}" for a in temp_args if len(a) > 2]
run_args[arg_key] = get_env(final_vars, getattr(args, arg_key.replace("-", "_")), arg_bool=arg_data["type"] == "bool", arg_int=arg_data["type"] == "int")

env_version = get_env("BRANCH_NAME", "master")
env_branch = get_env("BRANCH_NAME", "master")
is_docker = get_env("KOMETA_DOCKER", False, arg_bool=True)
is_linuxserver = get_env("KOMETA_LINUXSERVER", False, arg_bool=True)
is_lxml = get_env("KOMETA_LXML", False, arg_bool=True)
Expand Down Expand Up @@ -205,7 +205,7 @@ def get_env(env_str, default, arg_bool=False, arg_int=False):
util.logger = logger
from modules.builder import CollectionBuilder
from modules.config import ConfigFile
from modules.request import Requests, parse_version
from modules.request import Requests
from modules.util import Failed, FilterFailed, NonExisting, NotScheduled, Deleted

def my_except_hook(exctype, value, tb):
Expand All @@ -225,12 +225,12 @@ def new_send(*send_args, **kwargs):

requests.Session.send = new_send

file_version = ("Unknown", "Unknown", 0)
local_version = "Unknown"
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "VERSION")) as handle:
for line in handle.readlines():
line = line.strip()
if len(line) > 0:
file_version = parse_version(line)
local_version = line
break

uuid_file = os.path.join(default_dir, "UUID")
Expand Down Expand Up @@ -271,13 +271,13 @@ def start(attrs):
elif is_linuxserver:
system_ver = "Linuxserver"
elif is_docker:
system_ver = "Docker"
system_ver = f"Docker: {env_branch}"
else:
system_ver = f"Python {platform.python_version()}"
my_requests = Requests(file_version, env_version, git_branch, verify_ssl=False if run_args["no-verify-ssl"] else True)
logger.info(f" Version: {my_requests.version[0]} ({system_ver}){f' (Git: {git_branch})' if git_branch else ''}")
if my_requests.new_version:
logger.info(f" Newest Version: {my_requests.new_version}")
my_requests = Requests(local_version, env_branch, git_branch, verify_ssl=False if run_args["no-verify-ssl"] else True)
logger.info(f" Version: {my_requests.local} ({system_ver}){f' (Git: {git_branch})' if git_branch else ''}")
if my_requests.newest:
logger.info(f" Newest Version: {my_requests.newest}")
logger.info(f" Platform: {platform.platform()}")
logger.info(f" Total Memory: {round(psutil.virtual_memory().total / (1024.0 ** 3))} GB")
logger.info(f" Available Memory: {round(psutil.virtual_memory().available / (1024.0 ** 3))} GB")
Expand Down Expand Up @@ -347,9 +347,9 @@ def start(attrs):
except Failed as e:
logger.stacktrace()
logger.error(f"Webhooks Error: {e}")
version_line = f"Version: {my_requests.version[0]}"
if my_requests.new_version:
version_line = f"{version_line} Newest Version: {my_requests.new_version}"
version_line = f"Version: {my_requests.local}"
if my_requests.newest:
version_line = f"{version_line} Newest Version: {my_requests.newest}"
try:
log_data = {}
no_overlays = []
Expand Down
2 changes: 1 addition & 1 deletion modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, translatio
try:
self.Webhooks.start_time_hooks(self.start_time)
if self.Requests.has_new_version():
self.Webhooks.version_hooks(self.Requests.version, self.Requests.latest_version)
self.Webhooks.version_hooks()
except Failed as e:
logger.stacktrace()
logger.error(f"Webhooks Error: {e}")
Expand Down
4 changes: 2 additions & 2 deletions modules/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def config_tags(self):
def configs_url(self):
if self._configs_url is None:
self._configs_url = f"{configs_raw_url}/master/"
if self.requests.version[1] in self.config_tags and (self.requests.latest_version[1] != self.requests.version[1] or self.requests.branch == "master"):
self._configs_url = f"{configs_raw_url}/v{self.requests.version[1]}/"
if self.requests.local.main in self.config_tags and (self.requests.latest.main != self.requests.local.main or self.requests.branch == "master"):
self._configs_url = f"{configs_raw_url}/v{self.requests.local.main}/"
return self._configs_url

@property
Expand Down
Loading

0 comments on commit 866ce01

Please sign in to comment.