Skip to content

Commit

Permalink
Merge pull request #13 from kiwix/feature/tag-based-cd
Browse files Browse the repository at this point in the history
Add tag based CD trigger
  • Loading branch information
BPerlakiH authored Jan 12, 2024
2 parents 80f30d0 + 35b9fef commit 07bf453
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 49 additions & 0 deletions .github/workflows/tag_validator.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 07bf453

Please sign in to comment.