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

Feat/implement ci cd pipeline #5

Open
wants to merge 29 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9de08c6
WIP: Create master-workflow.yaml
jsong336 Jul 5, 2023
d3178be
Update master-workflow.yaml
jsong336 Jul 6, 2023
f7b30d2
Update master-workflow.yaml
jsong336 Jul 6, 2023
3eb6e95
Update master-workflow.yaml
jsong336 Jul 6, 2023
fbc44eb
Update master-workflow.yaml
jsong336 Jul 6, 2023
b52bfbc
Update master-workflow.yaml
jsong336 Jul 6, 2023
01cb958
Update master-workflow.yaml
jsong336 Jul 6, 2023
4ee3165
Update master-workflow.yaml
jsong336 Jul 6, 2023
00c9a83
Update master-workflow.yaml
jsong336 Jul 6, 2023
f2e5f7c
Update master-workflow.yaml
jsong336 Jul 6, 2023
bb1953c
Update master-workflow.yaml
jsong336 Jul 6, 2023
6a594cc
Update master-workflow.yaml
jsong336 Jul 6, 2023
39d6d86
Update master-workflow.yaml
jsong336 Jul 6, 2023
419caf0
Update master-workflow.yaml
jsong336 Jul 6, 2023
110b7d9
Update master-workflow.yaml
jsong336 Jul 6, 2023
19451b1
Update master-workflow.yaml
jsong336 Jul 6, 2023
a3e9a38
Update master-workflow.yaml
jsong336 Jul 6, 2023
5580a59
Update master-workflow.yaml
jsong336 Jul 6, 2023
77e944e
Update and rename master-workflow.yaml to push-job.yaml
jsong336 Jul 6, 2023
be2692a
Update push-job.yaml
jsong336 Jul 7, 2023
dfb1074
Update push-job.yaml
jsong336 Jul 7, 2023
7e0dbb3
Update push-job.yaml
jsong336 Jul 7, 2023
80d1137
Update push-job.yaml
jsong336 Jul 7, 2023
a45d6b5
Update push-job.yaml
jsong336 Jul 7, 2023
f590dc6
Update push-job.yaml
jsong336 Jul 7, 2023
93b5673
added more sciprt
jsong336 Jul 7, 2023
8f617ac
added more sciprt
jsong336 Jul 7, 2023
40d3ac0
added more sciprt
jsong336 Jul 7, 2023
21d589a
added more sciprt
jsong336 Jul 7, 2023
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
81 changes: 81 additions & 0 deletions .github/workflows/push-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI/CD on push
on:
push:
branches:
- master
- development
- feat/implement-ci-cd-pipeline
env:
POETRY_VERSION: 1.5.1
PYTHON_VERSION: '3.10'
GH_TOKEN: ${{ github.token }}
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Check Version
run: bash scripts/check_pypi_version.sh

- id: setup-python
name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Cache Poetry
uses: actions/cache@v2
with:
path: ~/.local
key: poetry-${{ env.POETRY_VERSION }}-0

- name: Setup Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true

- id: cache-python-dependencies
name: Cache Python Dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install Python Dependencies
if: steps.cache-python-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Build Package
# if: github.ref == 'ref/head/master'
run: poetry build

- id: create-release
name: Create Release
# if: github.ref == 'ref/head/master'
run: |
git config --local user.name "Github Action"

bash scripts/check_tag.sh
if [[ ! $? == 0 ]]; then exit 1; fi

bash scripts/check_semver.sh $tag
semver=$([[ $? == 0 ]] && echo 1)
echo "SEMVER=$semver" >> $GITHUB_OUTPUT

tag=$(bash scripts/get_release_tag.sh)
echo "Creating new release: $tag"

gh release create $tag \
--generate-notes \
--title "Release: $tag"
${semver:+--prerelease}

# - name: Publish Package
# # if: github.ref == 'ref/head/master' && steps.create-release.outputs.semver == 1
# run: |
# poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
# poetry publish
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ajaejokes"
version = "0.1.1"
version = "0.1.1.rc"
description = ""
authors = ["Jeongwon Song <jeongwon412@gmail.com>"]
readme = "README.md"
Expand Down
22 changes: 22 additions & 0 deletions scripts/check_pypi_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# Scripts to check if the release already exists in pypi
latestVersion=$(curl -s https://pypi.org/pypi/ajaejokes/json | jq -r '.info.version')
currentVersion=$(bash scripts/get_release_tag.sh)

echo "Latest Version: $latestVersion"
echo "Current Version: $currentVersion"

# TODO: Check semver format of currentVersion
# Check if current version = latestVersion first. (i.e. more common mistakes)
if [[ $latestVersion == $currentVersion ]]; then
echo "$currentVersion is not upgraded"
exit 1
fi

releases=$(curl -s https://pypi.org/pypi/ajaejokes/json | jq -cr '.releases | keys | .[]')
for release in ${releases[@]}; do
if [[ $release == $currentVersion ]]; then
echo "$currentVersion already exists"
exit 1
fi
done
12 changes: 12 additions & 0 deletions scripts/check_semver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Check if valid semver
# TODO: v prefix or .rc postfix are supported
VERSION="$@"
rx='^([0-9]+\.){0,2}(\*|[0-9]+)$'
if [[ $VERSION =~ $rx ]]; then
echo "valid semver"
exit 0
else
echo "invalid semver"
exit 1
fi
9 changes: 9 additions & 0 deletions scripts/check_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# Script to check if tag already exists
tags=$(git tag)
for tag in ${tags[@]}; do
if [[ "$@" == $tag ]]; then
echo "tag $@ already exists"
exit 1
fi
done
1 change: 1 addition & 0 deletions scripts/get_release_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo -n $(cat pyproject.toml| grep -oP 'version = "\K.*?(?=")')