Skip to content

Commit 9c63056

Browse files
committed
Merge dev into main
2 parents 708a39c + fb8ab41 commit 9c63056

File tree

127 files changed

+2164
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+2164
-331
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name : 'Increment Tag - Dev'
2+
description: 'Increment Tag - Dev'
3+
4+
inputs:
5+
package_name:
6+
description: 'Package name for coverage'
7+
required: true
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: List all branches
18+
shell: bash
19+
run: git branch -a
20+
21+
- name: Checkout dev branch
22+
shell: bash
23+
run: |
24+
git checkout dev || (git checkout -b dev && git push -u origin dev)
25+
26+
27+
- name: Set up Git user
28+
shell: bash
29+
run: |
30+
git config --global user.name 'GitHub Actions'
31+
git config --global user.email '[email protected]'
32+
33+
- name: Fetch all tags
34+
shell: bash
35+
run: git fetch --tags
36+
37+
- name: Find and increment latest tag
38+
shell: bash
39+
id: latest_tag
40+
run: |
41+
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
42+
echo "Latest tag: $LATEST_TAG"
43+
44+
# Extract just the version part and increment it
45+
VERSION_PART=$(echo $LATEST_TAG | sed 's/^v//')
46+
MAJOR=$(echo $VERSION_PART | cut -d. -f1)
47+
MINOR=$(echo $VERSION_PART | cut -d. -f2)
48+
PATCH=$(echo $VERSION_PART | cut -d. -f3)
49+
50+
NEW_PATCH=$((PATCH + 1))
51+
52+
NEW_TAG="v$MAJOR.$MINOR.$NEW_PATCH"
53+
echo "New tag: $NEW_TAG"
54+
55+
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
56+
57+
- name: Update README badge
58+
shell: bash
59+
run: |
60+
sed -i "s/release-v[0-9]*\.[0-9]*\.[0-9]*/release-$NEW_TAG/" README.md
61+
62+
- name: Update Version File (root)
63+
shell: bash
64+
run: |
65+
echo $NEW_TAG | sed 's/refs\/tags\///' > ./${{ inputs.package_name }}/version
66+
67+
- name: Commit and push changes
68+
shell: bash
69+
run: |
70+
git add README.md ./${{ inputs.package_name }}/version
71+
git commit -m "Update release badge and version file"
72+
git push origin dev # Push to the 'dev' branch
73+
74+
- name: Tag new version
75+
shell: bash
76+
run: |
77+
NEW_TAG=${{ env.NEW_TAG }}
78+
git config --global user.name "GitHub Actions"
79+
git config --global user.email "[email protected]"
80+
81+
git tag $NEW_TAG
82+
git push origin $NEW_TAG
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name : 'Increment Tag - Main'
2+
description: 'Increment Tag - Main'
3+
4+
inputs:
5+
package_name:
6+
description: 'Package name for coverage'
7+
required: true
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2 # updated to v2
14+
with:
15+
ref: 'main' # Check out the 'main' branch
16+
fetch-depth: 0 # Fetch all history for .Git info
17+
18+
- name: Update Main Branch
19+
shell: bash
20+
run: |
21+
git pull origin main
22+
23+
- name: Set up Git user
24+
shell: bash
25+
run: |
26+
git config --global user.name 'GitHub Actions'
27+
git config --global user.email '[email protected]'
28+
29+
- name: Fetch all tags
30+
shell: bash
31+
run: git fetch --tags
32+
33+
- name: Find and increment latest tag
34+
shell: bash
35+
id: latest_tag
36+
run: |
37+
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
38+
echo "Latest tag: $LATEST_TAG"
39+
40+
# Extract just the version part and increment it
41+
VERSION_PART=$(echo $LATEST_TAG | sed 's/^v//')
42+
MAJOR=$(echo $VERSION_PART | cut -d. -f1)
43+
Z_PART=$(echo $VERSION_PART | cut -d. -f2)
44+
45+
NEW_Z=$((Z_PART + 1))
46+
47+
NEW_TAG="v$MAJOR.$NEW_Z.0"
48+
echo "New tag: $NEW_TAG"
49+
50+
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
51+
52+
- name: Update README badge
53+
shell: bash
54+
run: |
55+
sed -i "s/release-v[0-9]*\.[0-9]*\.[0-9]*/release-$NEW_TAG/" README.md
56+
57+
- name: Update Version File (root)
58+
shell: bash
59+
run: |
60+
echo $NEW_TAG > ./${{ inputs.package_name }}/version
61+
62+
- name: Commit and push changes
63+
shell: bash
64+
run: |
65+
git add README.md ./${{ inputs.package_name }}/version
66+
git commit -m "Update release badge and version file"
67+
git push origin main # Push to the 'main' branch
68+
69+
- name: Tag new version
70+
shell: bash
71+
run: |
72+
NEW_TAG=${{ env.NEW_TAG }}
73+
git tag $NEW_TAG
74+
git push origin $NEW_TAG
75+
76+
- name: Update Dev branch
77+
shell: bash
78+
run: |
79+
git checkout dev
80+
git merge main
81+
git push origin dev
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name : Install Dependencies (for tests - Unit)
2+
description: 'Install Dependencies (for tests - Unit)'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Install Python 3.x
8+
uses: actions/setup-python@v4
9+
with:
10+
python-version: 3.x
11+
- name: Cache pip dependencies (for tests - Unit)
12+
uses: actions/cache@v3
13+
with:
14+
path: ~/.cache/pip
15+
key: ${{ runner.os }}-pip-${{ hashFiles('**/tests/unit/requirements-unit.txt') }}
16+
restore-keys: |
17+
${{ runner.os }}-pip-
18+
- name: Install dependencies (for tests - Unit)
19+
shell: bash
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -r tests/unit/requirements-unit.txt
23+
pip install -e .
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run Python Tests
2+
description: 'Run Python Tests'
3+
4+
inputs:
5+
package_name:
6+
description: 'Package name for coverage'
7+
required: true
8+
AWS_ACCESS_KEY_ID:
9+
description: 'AWS Account KEY ID'
10+
required: true
11+
AWS_SECRET_ACCESS_KEY:
12+
description: 'AWS Secret Access Key'
13+
required: true
14+
AWS_DEFAULT_REGION:
15+
description: 'AWS Default region'
16+
required: true
17+
AWS_ACCOUNT_ID:
18+
description: 'AWS Account ID'
19+
required: true
20+
21+
22+
runs:
23+
using: 'composite'
24+
steps:
25+
- name: Run pytest (with coverage) - Unit Tests
26+
shell: bash
27+
run: |
28+
coverage run --source=${{ inputs.package_name }} -m pytest -v -s --durations=0 --ignore=tests_* tests/unit
29+
env:
30+
COVERAGE_FILE : .coverage.unit
31+
AWS_SECRET_ACCESS_KEY: ${{ inputs.AWS_SECRET_ACCESS_KEY }}
32+
AWS_DEFAULT_REGION : ${{ inputs.AWS_DEFAULT_REGION }}
33+
AWS_ACCOUNT_ID : ${{ inputs.AWS_ACCOUNT_ID }}
34+
AWS_ACCESS_KEY_ID : ${{ inputs.AWS_ACCESS_KEY_ID }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Increment Tag - Dev branch
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_run:
6+
workflows: ["Run Unit Tests"]
7+
branches: [dev]
8+
types:
9+
- completed
10+
11+
jobs:
12+
increment-tag-dev:
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3 #
17+
- name: Increment Tag (for DEV)
18+
uses: ./.github/actions/increment-tag-dev
19+
with:
20+
package_name: ${{ secrets.PACKAGE_NAME }}
21+
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Increment Tag - Main branch
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_run:
6+
workflows: ["Run Unit Tests"]
7+
branches: [main]
8+
types:
9+
- completed
10+
11+
jobs:
12+
increment-tag-main:
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Increment Tag (for MAIN)
18+
uses: ./.github/actions/increment-tag-main
19+
with:
20+
package_name: ${{ secrets.PACKAGE_NAME }}
21+
22+

.github/workflows/run-tests.yml

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
name: Run Python Tests
1+
name : Run Unit Tests
22
on:
3-
push:
4-
branches:
5-
- master
6-
pull_request:
7-
branches:
8-
- master
3+
push
94

105
jobs:
11-
build:
6+
run-tests:
127
runs-on: ubuntu-latest
138
steps:
14-
- uses: actions/checkout@v2
15-
- name: Install Python 3
16-
uses: actions/setup-python@v1
9+
# Setup
10+
- name: Checkout Code from GitHub
11+
uses: actions/checkout@v3
12+
13+
# Tests - Unit
14+
- name: Install Dependencies (for tests - Unit)
15+
uses: ./.github/actions/install-dependencies__unit
16+
17+
- name: Run Tests - Unit
18+
#if : false
19+
uses: ./.github/actions/run-tests__unit
1720
with:
18-
python-version: 3.8
19-
- name: Install dependencies
20-
run: |
21-
python -m pip install --upgrade pip
22-
pip install -r requirements.txt
23-
pip install -e .
21+
package_name : ${{ secrets.PACKAGE_NAME }}
22+
AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23+
AWS_DEFAULT_REGION : ${{ secrets.AWS_DEFAULT_REGION }}
24+
AWS_ACCOUNT_ID : ${{ secrets.AWS_ACCOUNT_ID }}
25+
AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
26+
27+
# Tear Down
28+
# - name: Publish Code Coverage
29+
# uses: ./.github/actions/publish-coverage
30+
# with:
31+
# codecov_token : ${{ secrets.CODECOV_TOKEN }}
32+
33+
2434

25-
- name: Run tests with pytest
26-
run: |
27-
pytest -v --durations=0 --cov=osbot_utils tests
28-
coveralls
29-
env:
30-
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

git-publish-main.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
git pull
2+
git checkout main
3+
git pull origin main
4+
git merge --no-ff dev -m "Merge dev into main"
5+
git push origin main
6+
git checkout dev
7+
git merge main -m "Merge main into dev"

osbot_aws/AWS_Config.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from dotenv import load_dotenv
44

5-
65
class AWS_Config:
76

87
def __init__(self):
@@ -14,15 +13,17 @@ def __enter__(self):
1413
def __exit__(self, type, value, traceback):
1514
pass
1615

17-
def aws_session_profile_name (self): return os.getenv('AWS_PROFILE_NAME' )
18-
def aws_session_region_name (self): return os.getenv('AWS_DEFAULT_REGION' )
19-
def aws_session_account_id (self): return os.getenv('AWS_ACCOUNT_ID' )
20-
def dev_skip_aws_key_check (self): return os.getenv('DEV_SKIP_AWS_KEY_CHECK' , False ) # use to not have the 500ms check that happens during this check
21-
def bot_name (self): return os.getenv('OSBOT_NAME' ) # todo: refactor variable to osbot_name (need to check for side effects)
22-
def lambda_s3_bucket (self): return os.getenv('OSBOT_LAMBDA_S3_BUCKET' , f'{self.aws_session_account_id()}-osbot-lambdas' )
23-
def lambda_s3_folder_layers (self): return os.getenv('OSBOT_LAMBDA_S3_FOLDER_LAYERS' , 'layers' )
24-
def lambda_s3_folder_lambdas (self): return os.getenv('OSBOT_LAMBDA_S3_FOLDER_LAMBDAS', 'lambdas' )
25-
def lambda_role_name (self): return os.getenv('OSBOT_LAMBDA_ROLE_NAME' 'role-osbot-lambda' )
16+
def aws_access_key_id (self): return os.getenv('AWS_ACCESS_KEY_ID' )
17+
def aws_secret_access_key (self): return os.getenv('AWS_SECRET_ACCESS_KEY' )
18+
def aws_session_profile_name (self): return os.getenv('AWS_PROFILE_NAME' )
19+
def aws_session_region_name (self): return os.getenv('AWS_DEFAULT_REGION' )
20+
def aws_session_account_id (self): return os.getenv('AWS_ACCOUNT_ID' ) or self.sts_session_account_id()
21+
def dev_skip_aws_key_check (self): return os.getenv('DEV_SKIP_AWS_KEY_CHECK' , False ) # use to not have the 500ms check that happens during this check
22+
def bot_name (self): return os.getenv('OSBOT_NAME' ) # todo: refactor variable to osbot_name (need to check for side effects)
23+
def lambda_s3_bucket (self): return os.getenv('OSBOT_LAMBDA_S3_BUCKET' ) or f'{self.aws_session_account_id()}-osbot-lambdas'
24+
def lambda_s3_folder_layers (self): return os.getenv('OSBOT_LAMBDA_S3_FOLDER_LAYERS' , 'layers' )
25+
def lambda_s3_folder_lambdas (self): return os.getenv('OSBOT_LAMBDA_S3_FOLDER_LAMBDAS', 'lambdas' )
26+
def lambda_role_name (self): return os.getenv('OSBOT_LAMBDA_ROLE_NAME' 'role-osbot-lambda' )
2627

2728

2829
def set_aws_session_profile_name(self, value): os.environ['AWS_PROFILE_NAME' ] = value ; return value
@@ -34,6 +35,14 @@ def set_lambda_s3_folder_lambdas(self, value): os.environ['OSBOT_LAMBDA_S3_FOLDE
3435
def set_lambda_role_name (self, value): os.environ['OSBOT_LAMBDA_ROLE_NAME' ] = value ; return value
3536
def set_bot_name (self, value): os.environ['OSBOT_NAME' ] = value ; return value
3637

38+
def sts_session_account_id(self): # to handle when the AWS_ACCOUNT_ID is not set
39+
from osbot_aws.apis.STS import STS # the use of this method is not advised
40+
return STS().current_account_id() # since this is quite an expensive method
41+
42+
# helper methods
43+
def account_id (self): return self.aws_session_account_id()
44+
def region_name(self): return self.aws_session_region_name()
45+
3746

3847
def set_aws_region(region_name):
3948
AWS_Config().set_aws_session_region_name(region_name)

0 commit comments

Comments
 (0)