Skip to content

Tilføj workflow til automatisk synkronisering af submodule-pointer - #1

Open
SSogaard94 wants to merge 1 commit into
mainfrom
feature/auto-sync-submodule
Open

Tilføj workflow til automatisk synkronisering af submodule-pointer#1
SSogaard94 wants to merge 1 commit into
mainfrom
feature/auto-sync-submodule

Conversation

@SSogaard94

Copy link
Copy Markdown

Hvad er ændret og hvorfor

bc-code-intelligence indeholder vores AI-personas og domæneviden til Business Central. Disse filer bruges i alle vores repos via en git submodule — men submoduler opdaterer sig ikke automatisk. Tidligere ville alle andre repos pege på en gammel version, medmindre nogen manuelt gik ind og opdaterede dem i hvert enkelt repo.

Hvad workflowet gør

Hver gang der pushes til main i bc-code-intelligence, kører workflowet automatisk to trin:

Trin 1 – Opdagelse
Workflowet spørger dynamisk GitHub API'et om alle aktive repos i kollabdk-organisationen og finder dem, der har bc-code-intelligence som submodule. Der er ingen hardkodet liste — nye repos inkluderes automatisk, blot ved at de tilføjer submodulen én gang.

Trin 2 – Synkronisering
For hvert fundet repo opdateres submodule-pointeren til den nyeste commit. Opdateringen kører parallelt for op til 10 repos ad gangen. Hvis et repo allerede er opdateret, springes det over.

Valg: direkte commit vs. pull request

Workflowet er sat op til at committe direkte til main i de forbrugende repos. Alternativet — at oprette en pull request pr. repo — er bevaret som kommentarer i YAML-filen, så det nemt kan skiftes til.

Hvad der kræves for at det virker

Der skal oprettes én GitHub-hemmelighed i bc-code-intelligence-repoet:

  • ORG_SYNC_TOKEN — et personal access token (eller GitHub App-token) med skriveadgang til alle repos i organisationen.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a GitHub Actions workflow that, on every push to main in bc-code-intelligence, discovers all non-archived repos in the kollabdk org consuming this repo as a git submodule and bumps the submodule pointer to the latest commit. Discovery is dynamic (no hardcoded list), and updates run in parallel (max 10) with fail-fast: false. An alternative PR-based flow is kept as commented-out YAML.

Changes:

  • New discover job enumerates org repos via gh repo list and inspects each repo's .gitmodules to find consumers.
  • New update matrix job clones each consumer, advances the bc-code-intelligence submodule to github.sha, commits, and pushes directly to main.
  • Documents required ORG_SYNC_TOKEN secret and provides commented-out PR-creation alternative.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +75 to +82
# Peg submodulet på den nye commit
git submodule update --init bc-code-intelligence
cd bc-code-intelligence
git fetch origin
git checkout $NEW_SHA
cd ..

git add bc-code-intelligence
Comment on lines +67 to +97
git clone --depth=1 \
https://x-access-token:$GH_TOKEN@github.com/kollabdk/${{ matrix.repo }}.git \
target

cd target
git config user.name "kollab-ai-sync[bot]"
git config user.email "ai-sync@kollab.dk"

# Peg submodulet på den nye commit
git submodule update --init bc-code-intelligence
cd bc-code-intelligence
git fetch origin
git checkout $NEW_SHA
cd ..

git add bc-code-intelligence

# Spring over hvis der ikke er nogen ændring
if git diff --staged --quiet; then
echo "Ingen ændring nødvendig i ${{ matrix.repo }}, springer over."
exit 0
fi

git commit -m "chore: opdater bc-code-intelligence submodule til seneste version [skip ci]"

# -----------------------------------------------------------
# VALG: Direkte commit eller Pull Request?
#
# AKTIV: Direkte commit til main
# -----------------------------------------------------------
git push origin main
Comment on lines +90 to +110
git commit -m "chore: opdater bc-code-intelligence submodule til seneste version [skip ci]"

# -----------------------------------------------------------
# VALG: Direkte commit eller Pull Request?
#
# AKTIV: Direkte commit til main
# -----------------------------------------------------------
git push origin main

# -----------------------------------------------------------
# ALTERNATIV: Opret en Pull Request i stedet for direkte push.
# Kommenter linjen ovenfor ud og fjern kommenteringen nedenfor.
# -----------------------------------------------------------
# BRANCH="update-bc-intelligence-$(date +%Y%m%d-%H%M)"
# git checkout -b $BRANCH
# git push origin $BRANCH
# gh pr create \
# --title "Opdater bc-code-intelligence submodule" \
# --body "Automatisk opdatering til nyeste AI-personas og workflows fra bc-code-intelligence." \
# --base main \
# --head $BRANCH
Comment on lines +25 to +44
# Hent alle ikke-arkiverede repos i org'en (ingen hardkodet liste!)
ALL_REPOS=$(gh repo list kollabdk --limit 1000 --json name,isArchived \
--jq '[.[] | select(.isArchived == false) | .name]')

CONSUMING=()
for repo in $(echo "$ALL_REPOS" | jq -r '.[]'); do
# Spring dette repo selv over
[ "$repo" = "bc-code-intelligence" ] && continue

# Tjek om repoet har en .gitmodules-fil der refererer til os
MODULES=$(gh api repos/kollabdk/$repo/contents/.gitmodules \
--jq '.content' 2>/dev/null | base64 -d 2>/dev/null || true)

if echo "$MODULES" | grep -q "bc-code-intelligence"; then
CONSUMING+=("\"$repo\"")
fi
done

echo "repos=[$(IFS=,; echo "${CONSUMING[*]}")]" >> $GITHUB_OUTPUT

Comment on lines +35 to +38
MODULES=$(gh api repos/kollabdk/$repo/contents/.gitmodules \
--jq '.content' 2>/dev/null | base64 -d 2>/dev/null || true)

if echo "$MODULES" | grep -q "bc-code-intelligence"; then
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants