Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
orfeas-k committed Aug 10, 2023
1 parent 9a6276c commit a8a538b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
48 changes: 30 additions & 18 deletions .github/workflows/release-bundle-to-charmhub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ on:

jobs:
get-releases-affected:
runs-on: ubuntu-22.04
name: Get releases affected
runs-on: ubuntu-22.04
outputs:
releases_affected: ${{ steps.get-releases-affected.outputs.RELEASES_AFFECTED_LIST }}
releases_affected: ${{ steps.get-releases-affected.outputs.releases_affected_json }}
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -29,23 +29,35 @@ jobs:

- name: Get releases affected
id: get-releases-affected
run: |
python .github/workflows/test.py ${{ steps.changed-files.outputs.all_changed_files }}
# run: bash .github/workflows/get-releases
# for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
# echo "$file was changed"
# done

run: python scripts/get_releases_affected.py ${{ steps.changed-files.outputs.all_changed_files }}

run-tests-and-publish-bundle-for-releases-affected:
name: Publish bundle for releases affected to corresponding Charmhub channels
runs-on: ubuntu-22.04
needs: [get-releases-affected]
strategy:
fail-fast: false
matrix:
release: ${{ fromJson(needs.get-releases-affected.outputs.releases_affected) }}
steps:
- uses: actions/checkout@v3

# get-releases-affected:
# [..]
- name: Get bundle path for current release
id: bundle-path
run: python scripts/get_bundle_path.py ${{ matrix.release }}

# run-tests-for-releases-affected:
# needs: get-releases-affected
# [..]
# - name: Run tests for bundle release ${{ matrix.release }}
# uses: action-for-bundle-tests
# with:
# bundle-path: ${{ steps.bundle-path.outputs.bundle_path }}

# publish-charm:
# needs: run-tests-for-releases-affected
# [..]
- name: Publish bundle for release ${{ matrix.release }} to Charmhub
run: |
echo release is ${{ matrix.release }}
echo bundle path is ${{ steps.bundle-path.outputs.bundle_path }}
# uses: canonical/charming-actions/[email protected]
# with:
# credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }}
# github-token: ${{ secrets.GITHUB_TOKEN }}
# bundle-path: ${{ steps.bundle-path.outputs.bundle_path }}
# channel: ${{ matrix.release }}
27 changes: 27 additions & 0 deletions scripts/get_bundle_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Get bundle path for specific release
import re
import sys
import os.path
import json

def get_bundle_path_from_release() -> None:
if len(sys.argv)>1:
release = sys.argv[1]
bundle_is_latest = re.search("^latest/", release)
if(bundle_is_latest):
bundle_path = "releases/" + release + "/bundle.yaml"
else:
bundle_path = "releases/" + release + "/kubeflow/bundle.yaml"

# Check if file in bundle_path output exists
# Expect the script to be executed from `bundle-kubeflow` repo directory
if(os.path.exists(bundle_path)):
bundle_path_json = json.dumps(bundle_path)
print(f"Outputting bundle_path in JSON format: {bundle_path_json}")
print(f'::set-output name=bundle_path::{bundle_path_json}')
else:
raise Exception(f"There is no file in path: {bundle_path}")
else:
raise Exception("No release given as input.")

get_bundle_path_from_release()
15 changes: 6 additions & 9 deletions .github/workflows/test.py → scripts/get_releases_affected.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Extract from the files changed by this PR the channels/releases affected
# Extract from the files changed by this PR the releases/channels affected.
import re
import sys
import json

def main() -> None:
def get_releases_affected() -> None:
releases_affected = set()

for file_path in sys.argv:
pattern = "^releases"

# check if string starts with the "releases"
file_path_starts_with_releases = re.search(pattern, file_path)
file_path_starts_with_releases = re.search("^releases", file_path)

if file_path_starts_with_releases :
directories = file_path.split('/')
Expand All @@ -20,14 +18,13 @@ def main() -> None:
accepted_risks = ["beta","edge","stable"]

if(track in accepted_tracks and risk in accepted_risks):
channel = f"{track}/{risk}"
print(channel)
releases_affected.add(channel)
release = f"{track}/{risk}"
releases_affected.add(release)
else:
raise Exception(f"File {file_path} was changed in 'releases' directory but it's not part of a known release/channel.")

releases_affected_json = json.dumps(list(releases_affected))
print(f"The following releases have been affected by this PR: {releases_affected_json}")
print(f'::set-output name=releases_affected_json::{releases_affected_json}')

main()
get_releases_affected()

0 comments on commit a8a538b

Please sign in to comment.