mirror of
https://github.com/kiwix/kiwix-apple-custom.git
synced 2025-09-22 03:40:45 -04:00
Add tag based CD trigger
This commit is contained in:
parent
80f30d08dc
commit
35b9fefee4
29
.github/workflows/cd.yml
vendored
Normal file
29
.github/workflows/cd.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
name: Publish Custom App
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: macos-13
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: custom
|
||||
|
||||
- name: Set tag variable as an output
|
||||
id: vars
|
||||
run:
|
||||
|
|
||||
echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Validate tag
|
||||
run:
|
||||
|
|
||||
cd custom
|
||||
python .github/workflows/tag_validator.py ${{ steps.vars.outputs.tag }}
|
49
.github/workflows/tag_validator.py
vendored
Normal file
49
.github/workflows/tag_validator.py
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import re
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
def is_valid(tag):
|
||||
# Regex verify the tag format
|
||||
pattern = re.compile(
|
||||
r'^(?P<brand_folder>\w+)_(?P<build_nr>\d+)(?:_(?P<extra_tag>\w+))?$')
|
||||
match = pattern.match(tag)
|
||||
|
||||
if match:
|
||||
groups = match.groupdict()
|
||||
brand = groups.get('brand_folder')
|
||||
build_nr = int(groups.get('build_nr'))
|
||||
if Path(brand).is_dir():
|
||||
print(f"valid tag found: {tag} (brand: {
|
||||
brand}, build number: {build_nr})")
|
||||
return True
|
||||
else:
|
||||
exist_with_error(f"The directory of the tag: '{
|
||||
brand}' doesn't exist")
|
||||
else:
|
||||
exist_with_error(f"Invalid tag: {tag}")
|
||||
return False
|
||||
|
||||
|
||||
def exist_with_error(msg):
|
||||
print(f"Error: {msg}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="A github tag validator for custom apps")
|
||||
parser.add_argument(
|
||||
"tag",
|
||||
help="The github tag to be verified",
|
||||
type=str
|
||||
)
|
||||
args = parser.parse_args()
|
||||
return is_valid(args.tag)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user