Skip to content

Commit

Permalink
Merge pull request #18 from jordojordo/sync-updates
Browse files Browse the repository at this point in the history
Update sync script with target branch in manifest - add sync workflow
  • Loading branch information
jordojordo authored Jul 13, 2023
2 parents f3afdbe + 0d09508 commit d8a8c11
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 14 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/sync-extensions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Sync and Release Extensions

on:
push:
branches:
- main
paths:
- manifest.json

env:
ACTIONS_RUNNER_DEBUG: false
CI_COMMIT_MESSAGE: CI Build Artifacts

jobs:
sync:
if: github.repository_owner == 'rancher'
name: Sync and Release Extensions
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure Git
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Setup Helm
uses: azure/setup-helm@v3
with:
version: v3.12.1

- name: Setup yq
uses: chrisdickinson/[email protected]
with:
yq-version: v4.34.2

- name: Run sync script
shell: bash
id: sync_script
run: |
chmod +x ./scripts/sync
./scripts/sync
- name: Commit build
run: |
git add ./{assets,charts,extensions,icons,index.yaml}
git commit -a -m "${{ env.CI_COMMIT_MESSAGE }}"
git push
- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: ./charts/*
env:
CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
CR_SKIP_EXISTING: true
2 changes: 2 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extensions": {
"elemental": {
"repo": "rancher/elemental-ui",
"branch": "main",
"versions": [
"1.2.0",
"1.1.0",
Expand All @@ -10,6 +11,7 @@
},
"kubewarden": {
"repo": "kubewarden/ui",
"branch": "gh-pages",
"versions": [
"1.0.0",
"1.0.1",
Expand Down
64 changes: 50 additions & 14 deletions scripts/sync
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,58 @@ CHECK="\xE2\x9C\x94"

ORG=rancher
BRANCH=main

while getopts "co:b:" opt; do
case $opt in
c)
rm -rf ./charts
rm -rf ./assets
rm -rf ./extensions
rm -rf ./icons
CLEAN=false

usage() {
echo "Usage: $0 [<options>]"
echo " options:"
echo " [-c | --clean] Clean the current extension assets including: ./{charts, assets, extensions, icons}"
echo " [-o | --org] <name> Specify the organization of the current repository (defaults to 'rancher')"
echo " [-b | --branch] <name> Specify the destination branch of the extension assets within the current repository (defaults to 'main')"
exit 1
}

while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
;;
-o|--org)
if [[ -z $2 || $2 == -* ]]; then
echo "Error: Missing argument for $1 option"
usage
fi
ORG="${2}"
shift 2
;;
o)
ORG="${OPTARG}"
-c|--clean)
CLEAN=true
shift
;;
b)
BRANCH="${OPTARG}"
-b|--branch)
if [[ -z $2 || $2 == -* ]]; then
echo "Error: Missing argument for $1 option"
usage
fi
BRANCH="${2}"
shift 2
;;
*)
echo "Error: Unknown option $1"
usage
;;
esac
done

shift $((OPTIND-1))

if [[ $CLEAN == true ]]; then
rm -rf ./charts
rm -rf ./assets
rm -rf ./extensions
rm -rf ./icons
fi

echo -e "${CYAN}${BOLD}Syncing Extensions${RESET}"

EXTS=$(jq -r ".extensions | keys[]" manifest.json)
Expand All @@ -52,24 +84,28 @@ for NAME in ${EXTS}
do
echo -e "${CYAN} + Syncing: ${BOLD}${NAME}${RESET}"

# Make diretories for assets anc charts
# Make diretories for assets, charts, and extensions
mkdir -p ./assets/${NAME}
mkdir -p ./charts/${NAME}
mkdir -p ./extensions/${NAME}

# Get repository name
# Get repository name, branch, and versions
REPO=$(jq -r ".extensions.${NAME}.repo" manifest.json)
EXT_BRANCH=$(jq -r ".extensions.${NAME}.branch" manifest.json)
VERSIONS=$(jq -r ".extensions.${NAME}.versions[]" manifest.json)
VFORMAT=$(echo $VERSIONS | tr '\n' ' ')

echo -e " Repository: ${REPO}"
echo -e " Branch: ${EXT_BRANCH}"
echo -e " Versions : ${VFORMAT}"
echo ""

echo -e " .. Cloning repository"
rm -rf ./tmp/${NAME}
pushd tmp > /dev/null
git clone https://github.com/${REPO}.git ${NAME}
cd ${NAME}
git checkout ${EXT_BRANCH}
pwd
popd > /dev/null

Expand Down

0 comments on commit d8a8c11

Please sign in to comment.