Get Repositories #97
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Get Repositories | |
on: | |
workflow_dispatch: | |
jobs: | |
Install_gh_CLI: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install gh CLI | |
run: | | |
# Install gh CLI | |
sudo mkdir -p -m 755 /etc/apt/keyrings && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \ | |
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ | |
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ | |
&& sudo apt update \ | |
&& sudo apt install gh -y | |
login: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Log in to GitHub | |
env: | |
GH_TOKEN: ${{ secrets.GH_PAT }} | |
run: | | |
gh auth login --with-token <<<"${GH_TOKEN}" | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
## - name: Get Repository Names | |
## id: get-repos | |
##run: | | |
##gh api --paginate '/users/Rafi98/repos' --jq '.[].full_name' > repositories.txt | |
#gh api --paginate '/Rafi98/GH_TASK3' --jq '.[].full_name' > repositories.txt | |
# Replace '/Rafi98/GH_TASK3' with the appropriate endpoint for organization repositories if needed | |
##- name: Display Repository Names | |
##run: | | |
##cat repositories.txt | |
- name: Get Repository Topics from README.md | |
id: get-topics | |
run: | | |
topics=$(gh api repos/Rafi98/GH_TASK3/topics --jq '.names[]') | |
echo "Repository Topics: $topics" | |
- name: Print Topics from topics.txt | |
run: | | |
cat topics.txt | |
- name: Install gh CLI | |
run: | | |
# Install gh CLI | |
sudo mkdir -p -m 755 /etc/apt/keyrings && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \ | |
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ | |
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ | |
&& sudo apt update \ | |
&& sudo apt install gh -y | |
##- name: Fetch Repository List | |
##id: fetch-repos | |
##run: | | |
##gh api --paginate '/users/Rafi98/repos' --jq '.[].full_name' > repositories.txt | |
##- name: Read Repository List | |
##id: read-repos | |
##run: | | |
##while IFS= read -r repo; do | |
##echo "$repo" | |
##done < repositories.txt | |
- name: Extract Topics content from README.md | |
run: | | |
topics=$(grep -oE '^#+\s+\S+' README.md | sed 's/^#* //') | |
echo "Topics found in README.md:" | |
echo "$topics" | |
run_script: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set Execute Permission | |
run: chmod +x update_topics.sh | |
- name: List Files | |
run: ls | |
- name: Print Topics from topics.txt | |
run: | | |
cat topics.txt | |
- name: Pull Changes | |
run: git pull origin main | |
- name: Execute Shell Script | |
run: | | |
./update_topics.sh "Data Eng" "topics.txt" #Add the text to the topics.txt file | |
git config --global user.name "Rafi98" | |
git config --global user.email "s.mdrafi98@gmail.com" | |
#git add .github/workflows/topics.txt | |
git add . | |
git commit -m "Update topics.txt" | |
git push | |
- name: Print Topics from topics.txt | |
run: | | |
cat topics.txt | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Pull Changes | |
run: git pull origin main | |
- name: Read topics.txt | |
id: read-topics | |
run: | | |
topics_content=$(cat topics.txt) | |
echo "::set-output name=topics::$(cat topics.txt)" | |
#echo "$(cat topics.txt)" > topics_output.txt | |
#echo "TOPICS_FILE=topics.txt" >> $GITHUB_ENV | |
#echo "TOPICS_CONTENT=$topics_content" >> $GITHUB_ENV | |
topics_content=$(<topics.txt) | |
echo "## Topics" > README.md | |
while IFS= read -r line; do | |
echo "$line" >> README.md | |
done <<< "$topics_content" | |
- name: Update README.md | |
run: | | |
echo "## Topics" >> README.md | |
echo "${{ steps.read-topics.outputs.topics_content }}" >> README.md | |
echo "${topics_content}" >> README.md | |
- name: Commit and Push Changes | |
run: | | |
git config --global user.name "Rafi98" | |
git config --global user.email "s.mdrafi98@gmail.com" | |
git add . | |
git commit -m "Update README.md with topics.txt content" | |
git push | |