Add support for syncing single containers

Signed-off-by: Miguel A. Cabrera Minagorri <mcabrera@vmware.com>
This commit is contained in:
Miguel A. Cabrera Minagorri
2022-04-13 11:17:10 +02:00
committed by Bitnami Containers
parent 9d5925f598
commit 2ceddcb655
3 changed files with 49 additions and 29 deletions

View File

@@ -9,6 +9,9 @@ on:
shift:
description: 'Commits to shift if you edited the containers folder'
default: '0'
container:
description: 'Sync only the container specified'
default: ''
jobs:
build:
name: Trigger Site Rebuild
@@ -20,4 +23,4 @@ jobs:
token: ${{ secrets.BITNAMI_BOT_SECRET }}
fetch-depth: 0
- name: Fetch
run: ./scripts/fetch-commits.sh ${{ github.event.inputs.shift }}
run: ./scripts/fetch-commits.sh ${{ github.event.inputs.shift }} ${{ github.event.inputs.container }}

View File

@@ -1,4 +1,6 @@
# Bitnami Containers
> NOTE: We use the latest commit to know the missing ones to sync. Do not edit this repository manually or the sync will be broken.
> If you edit this repo please take care of scifying how many commits you added into the `COMMIT_SHIFT` env var when calling the `fetch-commits.sh` script
> If you edit this repo please run the sync workflow manually providing:
> - how many commits you added into the `shift` parameter.
> - the container you affected into the `container` parameter.

View File

@@ -8,6 +8,7 @@ set -o xtrace # Uncomment this line for debugging purpose
TARGET_DIR="."
COMMIT_SHIFT="${1:-0}" # Used when you push commits manually
CONTAINER="${2:-}" # USed when we want to sync a single container
function queryRepos() {
local page=0
@@ -45,7 +46,7 @@ function gitConfigure() {
function pushChanges() {
git config user.name "Bitnami Containers"
git config user.email "containers@bitnami.com"
git push
git push origin main
}
function findCommitsToSync() {
@@ -70,7 +71,7 @@ function findCommitsToSync() {
max=$((max - 1))
done
[[ "$max" -eq "0" ]] && echo "Last commit not found into the original repo history" && exit 1
[[ "$max" -eq "0" ]] && echo "Last commit not found into the original repo history" && return 1
printf "$commits_to_sync"
}
@@ -83,13 +84,33 @@ syncCommit() {
rm -f "$patch_file"
}
syncContainerCommits() {
local -r name="${1:?Missing container name}"
local -r repo_url="https://github.com/bitnami/bitnami-docker-${name}"
(
cd "$TARGET_DIR"
# Fetch the old repo master
git remote add --fetch "$name" "$repo_url"
read -r -a commits_to_sync <<< "$(findCommitsToSync "$name")"
if [[ "${#commits_to_sync[@]}" -eq "0" ]]; then
echo "Nothing to sync for ${name}"
else
for commit in "${commits_to_sync[@]}"; do
syncCommit "$commit" "$name"
done
fi
git remote remove "$name"
)
}
function syncRepos() {
local -r repos="$(getContainerRepos)"
gitConfigure # Configure Git client
mkdir -p "$TARGET_DIR"
if [[ -z "$CONTAINER" ]]; then
local -r repos="$(getContainerRepos)"
# Build array of app names since we need to exclude them when moving files
local apps=("mock")
local -r urls=($(echo "$repos" | jq -r '.[].html_url' | sort | uniq))
@@ -99,17 +120,11 @@ function syncRepos() {
done
echo "$repos" | jq -r '.[].html_url' | sort | uniq | while read -r repo_url; do
name="${repo_url:42}" # 42 is the length of https://github.com/bitnami/bitnami-docker-
(
cd "$TARGET_DIR"
# Fetch the old repo master
git remote add --fetch "$name" "$repo_url"
read -r -a commits_to_sync <<< "$(findCommitsToSync "$name")"
for commit in "${commits_to_sync[@]}"; do
syncCommit "$commit" "$name"
done
git remote remove "$name"
)
syncContainerCommits "$name"
done
else
syncContainerCommits "$CONTAINER"
fi
pushChanges
}