Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/CD implemented for SRP #1

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build

on:
push:
paths-ignore:
- "**/*.md"
- ".gitignore"
branches:
- master
pull_request:
paths-ignore:
- "**/*.md"
- ".gitignore"
branches:
- master
- develop

jobs:
build:
runs-on: macos-latest

steps:
- name: Build
uses: actions/checkout@v3

- run: xcodebuild -scheme SRP -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=16.2'
50 changes: 50 additions & 0 deletions .github/workflows/create_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create tag and release
on:
push:
branches:
- master
paths-ignore:
- "**/*.md"
- ".gitignore"
jobs:
create-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Get version number and release notes
id: version_and_notes
run: |
current_version=$(python CI/echo_current_version.py)
release_notes=$(python CI/echo_release_notes.py)
echo "::set-output name=tag::$current_version"
echo "::set-output name=notes::$release_notes"

- name: Create tag and release
uses: avakar/tag-and-release@v1
id: tag_and_release
with:
tag_name: ${{ steps.version_and_notes.outputs.tag }}
body: ${{ steps.version_and_notes.outputs.notes }}
release_name: "v${{ steps.version_and_notes.outputs.tag }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create branch from tag
uses: peterjgrainger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: "release/v${{ steps.version_and_notes.outputs.tag }}"

- run: |
echo "Tag already present: ${{ env.TAG_EXISTS }}"

- run: |
echo "Tag already present: ${{ steps.tag_create.outputs.tag_exists }}"
34 changes: 34 additions & 0 deletions .github/workflows/version_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Version Check

on:
pull_request:
paths-ignore:
- "**/*.md"
- ".gitignore"
branches:
- master

jobs:
version-check:
runs-on: ubuntu-latest

steps:
- name: Get Latest Version
id: latest_release_version
uses: pozetroninc/[email protected]
with:
owner: PB-Digital
repo: srp-ios

- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Compare Versions
run: |
release_version=${{ steps.latest_release_version.outputs.release }}
python CI/check_version.py $release_version
42 changes: 42 additions & 0 deletions CI/check_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from models import Config
from config_parser import get_raw_config
from typing import Any
from sys import argv
import json

def parse_version(version_string: str) -> list[int]:
return [ int(i) for i in version_string.split('.') ]

def get_current_version(config: Config) -> list[int]:
return parse_version(config.version)

def compare_versions(release: list[int], current: list[int]) -> bool:
if len(release) != len(current):
print('\n\033[1;31m' + '❌ Version formats does not match!\n')
exit(1)

for r, c in zip(release, current):
if c > r:
return True
elif c < r:
return False

return False

def main():
release_version_string: str = argv.pop()

release_version: list[int] = parse_version(release_version_string)
current_version: list[int] = get_current_version(get_raw_config())

is_valid: bool = compare_versions(release_version, current_version)

if is_valid:
print('\n\033[1;32m' + '✅ Valid\n')
else:
print('\n\033[1;31m' + '❌ Not valid\n')
exit(2)


if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions CI/config_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import json
from typing import Any
from models import Config

def get_raw_config() -> Config:
with open('Config.json', 'r') as file:
config = json.load(file)
return Config(
version = config['version'],
release_notes = config['release_notes']
)
4 changes: 4 additions & 0 deletions CI/echo_current_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from config_parser import get_raw_config

if __name__ == '__main__':
print(get_raw_config().version)
4 changes: 4 additions & 0 deletions CI/echo_release_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from config_parser import get_raw_config

if __name__ == '__main__':
print(get_raw_config().release_notes)
6 changes: 6 additions & 0 deletions CI/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from dataclasses import dataclass

@dataclass
class Config:
version: str
release_notes: str
4 changes: 4 additions & 0 deletions Config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "3.8.2",
"release_notes": "CI/CD integrated"
}