Step-by-Step Tutorial: Build Your First GitHub Action Project

Simplify Your Workflow: Add Multiple Repositories into One with One Click

Step-by-Step Tutorial: Build Your First GitHub Action Project

I want to showcase my multiple GitHub project repos shown in a single repository but I don’t want to create manually.

Then, I used GitHub Action to automate my tasks.

Step:1 Create a GitHub repository with any name Github-action

Step:2 Create a new file .yml file .github/workflows

Step:3 Create a token in a Developer setting

Step:4 Add a token in an environment in a repo setting

Step:5 Write file name .github/workflows/action.yml

name: Fetch and Showcase Repositories by Topic

on:
  push:
    branches:
      - main

jobs:
  fetch_repos:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Fetch repositories by topic
        id: fetch_repos
        run: |
          # Define the username and topic
          USERNAME='bharatveeryadav'     # Replace with your GitHub username or organization
          TOPIC='devops'                  # Replace with the desired topic (e.g., 'devops', 'cloud', etc.)
          OUTPUT_DIR='Projects'               # Directory to clone projects
          README_FILE='README.md'             # README file name

          # Create output directory and README file
          mkdir -p $OUTPUT_DIR
          echo "# Projects with Topic: $TOPIC" > $README_FILE
          echo "" >> $README_FILE
          echo "This repository contains projects related to the topic '$TOPIC'." >> $README_FILE
          echo "" >> $README_FILE
          echo "## List of Projects" >> $README_FILE
          echo "" >> $README_FILE

          # Make the API request to fetch repositories by topic
          response=$(curl -s -H "Authorization: token ${{ secrets.MY_PERSONAL_ACCESS_TOKEN }}" \
            "https://api.github.com/search/repositories?q=user:$USERNAME+topic:$TOPIC&per_page=100")

          # Filter repositories by topic, clone them, and add to README
          echo "$response" | jq -r '.items[] | .name + " " + .clone_url' | while read -r name repo; do
            # Clone each repository into the output directory
            git clone "$repo" "$OUTPUT_DIR/$name"

            # Add project to README file
            echo "- [$name]($repo)" >> $README_FILE
          done

      - name: Commit and Push Changes
        run: |
          git config --global user.email "bharatveeryadavg@gmail.com"
          git config --global user.name "bharatveeryadav"
          git add .
          git add $OUTPUT_DIR $README_FILE
          git commit -m "Add repositories with topic '$TOPIC' and update README"
          git pull origin main
          git push origin main
  • Make sure to change your username with your account and secret.

add topic name with

Step:6 Add topic name in which repo you want to add automatically

Step:7 Change the permission to read and write

Step:8 Go to actions run the job if failed run again