-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from kiwix/feature/tag-based-cd
Add tag based CD trigger
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |