Skip to content

feat: Community repo connect #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions .github/workflows/akash-community-groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
name: Update Community Groups

on:
repository_dispatch:
types: [community-groups-changed]
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN
permissions:
contents: write # Required to push commits and create branches
pull-requests: write # Required to create and label PRs

# Make sure to:
# GH Repo Settings -> Actions -> General -> Workflow permissions -> [x] Allow GitHub Actions to create and approve pull requests
# GH Repo Settings -> Branches -> Add branch ruleset -> call it "default-main" or however you like, leave defaults and click "Save changes"

jobs:
update-groups:
runs-on: ubuntu-latest
outputs:
merge_complete: ${{ steps.create-merge-pr.outputs.merge_complete }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Check for existing PR
id: check-pr
run: |
gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
PR_EXIST=$(gh pr list --search "Update Community Groups" --state open --json number --jq 'length')
echo "pr_exists=$PR_EXIST" >> $GITHUB_OUTPUT
if [ "$PR_EXIST" -gt "0" ]; then
PR_INFO=$(gh pr list --search "Update Community Groups" --state open --json number,headRefName --jq '.[0]')
PR_NUMBER=$(echo $PR_INFO | jq -r '.number')
PR_BRANCH=$(echo $PR_INFO | jq -r '.headRefName')
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "pr_branch=$PR_BRANCH" >> $GITHUB_OUTPUT
fi

- name: Clone and Update Groups
id: update-groups
run: |
# Save current state
if [ -d "src/content/Development_Current_Groups_Page" ]; then
mkdir -p ../old_groups
cp -r src/content/Development_Current_Groups_Page/* ../old_groups/
fi

# Clone the community repository
rm -rf temp_community
git clone --depth 1 https://github.com/akash-network/community.git temp_community

# Create target directory if it doesn't exist
mkdir -p src/content/Development_Current_Groups_Page

# Copy only sig-* and wg-* folders and their README.md files
cd temp_community
for dir in sig-* wg-*; do
if [ -d "$dir" ] && [ -f "$dir/README.md" ]; then
mkdir -p ../src/content/Development_Current_Groups_Page/$dir
cp $dir/README.md ../src/content/Development_Current_Groups_Page/$dir/
fi
done
cd ..

# Remove temporary directory
rm -rf temp_community

# Check for changes
if [ -d "../old_groups" ]; then
if diff -r ../old_groups src/content/Development_Current_Groups_Page > /dev/null 2>&1; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected in groups"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected in groups"
diff -r ../old_groups src/content/Development_Current_Groups_Page || true
fi
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Initial groups setup"
fi

# Cleanup old groups
rm -rf ../old_groups

- name: Update Existing PR
if: steps.update-groups.outputs.has_changes == 'true' && steps.check-pr.outputs.pr_exists != '0'
run: |
git config --global user.name 'GitHub Action'
git config --global user.email 'action@github.com'

git stash --include-untracked
git fetch origin ${{ steps.check-pr.outputs.pr_branch }}
git checkout ${{ steps.check-pr.outputs.pr_branch }}
git stash pop || echo "No stashed changes to apply"

git add src/content/Development_Current_Groups_Page
if git diff --staged --quiet; then
echo "No changes to commit after staging"
exit 0
fi

git commit -m "chore: update community groups [skip ci]"
git push origin ${{ steps.check-pr.outputs.pr_branch }}

- name: Create & Merge PR if Needed
id: create-merge-pr
if: steps.update-groups.outputs.has_changes == 'true'
run: |
# Configure git
gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
git config --global user.name 'GitHub Action'
git config --global user.email 'action@github.com'

if [[ "${{ steps.check-pr.outputs.pr_exists }}" -gt "0" ]]; then
echo "Merging existing PR #${{ steps.check-pr.outputs.pr_number }}..."
gh pr merge --auto --squash --delete-branch ${{ steps.check-pr.outputs.pr_number }}
else
echo "No existing PR found. Creating a new one..."

branch_name="update-community-groups-$(date +%Y%m%d-%H%M%S)"
git checkout -b $branch_name
git add src/content/Development_Current_Groups_Page
if git diff --staged --quiet; then
echo "No changes to commit after staging"
exit 0
fi
git commit -m "chore: update community groups"
git push origin $branch_name

# Create PR and capture the PR URL
PR_URL=$(gh pr create \
--title "Update Community Groups $(date +%Y-%m-%d)" \
--body "Automated PR to update community groups documentation" \
--base main \
--head $branch_name)

# Extract PR number from PR URL using a more reliable method
PR_NUMBER=$(echo $PR_URL | grep -oP 'pull/\K[0-9]+')
if [ -z "$PR_NUMBER" ]; then
echo "Error: Could not extract PR number from URL: $PR_URL"
exit 1
fi

echo "Merging newly created PR #$PR_NUMBER..."
echo "Waiting until PR is mergeable ..."
for i in {1..10}; do
MERGEABLE=$(gh pr view $PR_NUMBER --json mergeable --jq '.mergeable')
echo "Mergeable status: $MERGEABLE"
if [ "$MERGEABLE" = "MERGEABLE" ]; then
break
fi
echo "Waiting for PR to become mergeable..."
sleep 3
done
gh pr merge --auto --squash --delete-branch $PR_NUMBER
fi
echo "merge_complete=true" >> $GITHUB_OUTPUT

# to trigger the Astro Build workflow
trigger-astro:
name: Trigger Astro Build
needs: update-groups
if: needs.update-groups.outputs.merge_complete == 'true'
runs-on: ubuntu-latest
steps:
- name: Dispatch event to trigger Astro build
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
event-type: groups-update
26 changes: 15 additions & 11 deletions src/components/development-pages/community-groups-grid.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
---
import { getCollection } from "astro:content";
import { getCollection, type CollectionEntry } from "astro:content";
import CgCard from "../mdx-cards/cg-card.astro";

const pages = await getCollection("Development_Current_Groups_Page");

function filterGroupsByCategory(groups: any, categoryName: string) {
return groups.filter((group: any) => group.id.startsWith(categoryName));
function filterGroupsByCategory(
groups: CollectionEntry<"Development_Current_Groups_Page">[],
categoryName: string,
) {
return groups.filter((group) => group.data.category === categoryName);
}

const { group } = Astro.props;
Expand All @@ -20,14 +23,15 @@ const filteredGroups = filterGroupsByCategory(pages, group);
filteredGroups.map((item: any) => (
<CgCard
parentGroup={group}
tag={item.slug.split("/")[1]}
title={item.data.title}
description={item.data.description}
meetingslinkLabel={item.data.meetings.link.label}
meetingsLink={item.data.meetings.link.link}
githubLink={item.data.githubLink}
discordLink={item.data.discordLink}
dateLabel={item.data.meetings.dateLabel}
tag={item?.slug?.split("/")[0]}
title={item?.data?.title}
description={item?.data?.description}
meetingslinkLabel={item?.data?.meetings?.link?.label}
meetingsLink={item?.data?.meetings?.link?.link}
githubLink={item?.data?.githubLink}
discordLink={item?.data?.discordLink}
dateLabel={item?.data?.meetings?.dateLabel}
slug={item?.slug}
/>
))
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/mdx-cards/cg-card.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ const {
discordLink,
parentGroup,
dateLabel,
slug,
} = Astro.props;
---

<div
class="not-prose group flex flex-col justify-between rounded-lg border bg-background2 p-5 shadow-sm duration-300 ease-in-out hover:drop-shadow-md"
>
<a href={`/current-groups/${parentGroup}/${tag}/`} class="flex-1">
<a href={`/current-groups/${slug?.split("/")[0]}/`} class="flex-1">
<span class="flex flex-1 flex-col justify-between">
<div>
<p class="text-sm font-medium leading-[20px] text-cardGray">
Expand Down
Loading